blob: 0124ee108d882c02795249ce14cbff98281a46b8 [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;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080035import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070036import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000037import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080038import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000039import android.compat.annotation.ChangeId;
40import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070041import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070042import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.content.Context;
44import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070045import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070046import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070047import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.net.Uri;
49import android.os.AsyncResult;
50import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080051import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Bundle;
53import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080055import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.Looper;
57import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070058import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080059import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070060import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070061import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080062import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080063import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070064import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070065import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080066import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070068import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070070import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070071import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080072import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070073import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090074import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080075import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080076import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070077import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080078import android.telephony.AccessNetworkConstants;
79import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070080import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070081import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080082import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070083import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080084import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070085import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080086import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070087import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080088import android.telephony.CellIdentityCdma;
89import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070091import android.telephony.CellInfoGsm;
92import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070093import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080094import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070095import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070096import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070097import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080098import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700101import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800102import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800103import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700104import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800105import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800107import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800108import android.telephony.SignalStrengthUpdateRequest;
109import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800110import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800112import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700113import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800115import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800116import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800117import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800118import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000119import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000120import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000121import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700122import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700123import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800124import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800125import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700126import android.telephony.gba.GbaAuthRequest;
127import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700128import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000130import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000131import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700132import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000133import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800135import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700136import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800137import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700138import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000139import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700140import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800141import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800142import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700145import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800147import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Andrew Lee312e8172014-10-23 17:01:36 -0700149import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800150import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800151import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800152import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800153import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700155import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700156import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800157import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800158import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800161import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700162import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800163import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800164import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800165import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700166import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000167import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700168import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800169import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800172import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800173import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700174import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700175import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700176import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700178import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800179import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700180import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700181import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700182import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700183import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800184import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800185import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700186import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000187import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700188import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800190import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800191import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700193import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700195import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800196import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700197import com.android.internal.telephony.imsphone.ImsPhone;
198import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000199import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800200import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800201import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
202import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700203import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204import com.android.internal.telephony.uicc.IccIoResult;
205import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800206import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700207import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800208import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000210import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800211import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000212import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800213import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000214import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700215import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700216import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800217import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800218import com.android.phone.callcomposer.CallComposerPictureManager;
219import com.android.phone.callcomposer.CallComposerPictureTransfer;
220import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700221import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700222import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700223import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800224import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700225import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700226import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800227import com.android.services.telephony.TelecomAccountRegistry;
228import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800229import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800230
Hall Liu82694d52020-12-11 18:22:04 -0800231import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700232import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.io.IOException;
234import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700235import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000238import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800239import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800240import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800241import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800242import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100243import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800244import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700245import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800246import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800247import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700248import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800249import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800250import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800251import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
253/**
254 * Implementation of the ITelephony interface.
255 */
Santos Cordon117fee72014-05-16 17:56:12 -0700256public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 private static final String LOG_TAG = "PhoneInterfaceManager";
258 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
259 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261
262 // Message codes used with mMainThreadHandler
263 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700264 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
265 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700266 private static final int CMD_OPEN_CHANNEL = 9;
267 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
268 private static final int CMD_CLOSE_CHANNEL = 11;
269 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800270 private static final int CMD_NV_READ_ITEM = 13;
271 private static final int EVENT_NV_READ_ITEM_DONE = 14;
272 private static final int CMD_NV_WRITE_ITEM = 15;
273 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
274 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
275 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700276 private static final int CMD_RESET_MODEM_CONFIG = 19;
277 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800278 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
279 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800280 private static final int CMD_SEND_ENVELOPE = 25;
281 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000282 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
283 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700284 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
285 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
286 private static final int CMD_EXCHANGE_SIM_IO = 31;
287 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800288 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
289 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700290 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
291 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700292 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
293 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700294 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
295 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
296 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
297 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700298 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
299 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
300 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
301 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700302 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800303 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
304 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000305 private static final int CMD_SWITCH_SLOTS = 50;
306 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700307 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
308 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
309 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
310 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
311 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
312 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
313 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
314 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700315 private static final int CMD_GET_ALL_CELL_INFO = 60;
316 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
317 private static final int CMD_GET_CELL_LOCATION = 62;
318 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700319 private static final int CMD_MODEM_REBOOT = 64;
320 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700321 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
322 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800323 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
324 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700325 private static final int CMD_GET_MODEM_STATUS = 70;
326 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700327 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
328 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700329 private static final int CMD_ERASE_MODEM_CONFIG = 74;
330 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800331 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
332 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
333 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
334 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800335 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
336 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800337 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800338 private static final int CMD_GET_CALL_FORWARDING = 83;
339 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
340 private static final int CMD_SET_CALL_FORWARDING = 85;
341 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
342 private static final int CMD_GET_CALL_WAITING = 87;
343 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
344 private static final int CMD_SET_CALL_WAITING = 89;
345 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700346 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
347 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
348 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
349 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700350 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
351 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800352 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
353 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800354 private static final int CMD_SET_DATA_THROTTLING = 99;
355 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800356 private static final int CMD_SET_SIM_POWER = 101;
357 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800358 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
359 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
360 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
361 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800362 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
363 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000364 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800365 private static final int CMD_GET_SLICING_CONFIG = 110;
366 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800367 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700368 private static final int CMD_ENABLE_VONR = 113;
369 private static final int EVENT_ENABLE_VONR_DONE = 114;
370 private static final int CMD_IS_VONR_ENABLED = 115;
371 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700372 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
373 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800375 // Parameters of select command.
376 private static final int SELECT_COMMAND = 0xA4;
377 private static final int SELECT_P1 = 0x04;
378 private static final int SELECT_P2 = 0;
379 private static final int SELECT_P3 = 0x10;
380
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000381 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
382 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 /** The singleton instance. */
385 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800386 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387
Wink Saville3ab207e2014-11-20 13:07:20 -0800388 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800389 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800390 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700391 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800392 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700393 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800394 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800395 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800396 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700397 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800398 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000399 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400
Peter Wangdafb9ac2020-01-15 14:13:38 -0800401 /** User Activity */
402 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800403 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
404
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700405 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
406
Derek Tan97ebb422014-09-05 16:55:38 -0700407 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
408 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800409 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800410 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700411
Michelecea4cf22018-12-21 15:00:11 -0800412 // String to store multi SIM allowed
413 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
414
Derek Tan740e1672017-06-27 14:56:27 -0700415 // The AID of ISD-R.
416 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
417
yinxub1bed742017-04-17 11:45:04 -0700418 private NetworkScanRequestTracker mNetworkScanRequestTracker;
419
David Kelly5e06a7f2018-03-12 14:10:59 +0000420 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
421 private static final int MANUFACTURER_CODE_LENGTH = 8;
422
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800423 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800424 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800425
Sarah Chin2ec39f62022-08-31 17:03:26 -0700426 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
427 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
428
Derek Tan89e89d42014-07-08 17:00:10 -0700429 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700430 * Experiment flag to enable erase modem config on reset network, default value is false
431 */
432 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
433 "reset_network_erase_modem_config_enabled";
434
Rambo Wang0f050d82021-02-12 11:43:36 -0800435 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800436
sandeepjsb6c87872021-09-27 15:34:44 +0000437 /**
438 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
439 * one ICCID active at the same time.
440 * Apps should use below API signatures if targeting SDK is T and beyond.
441 *
442 * @hide
443 */
444 @ChangeId
445 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
446 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800447
Naina Nallurid63128d2019-09-17 14:10:30 -0700448 /**
Chen Xu540470b2021-12-14 17:15:47 -0800449 * Apps targeting on Android T and beyond will get exception whenever icc close channel
450 * operation fails.
451 */
452 @ChangeId
453 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
454 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
455
456 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class IccAPDUArgument {
460 public int channel, cla, command, p1, p2, p3;
461 public String data;
462
463 public IccAPDUArgument(int channel, int cla, int command,
464 int p1, int p2, int p3, String data) {
465 this.channel = channel;
466 this.cla = cla;
467 this.command = command;
468 this.p1 = p1;
469 this.p2 = p2;
470 this.p3 = p3;
471 this.data = data;
472 }
473 }
474
475 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700476 * A request object to use for transmitting data to an ICC.
477 */
478 private static final class ManualNetworkSelectionArgument {
479 public OperatorInfo operatorInfo;
480 public boolean persistSelection;
481
482 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
483 this.operatorInfo = operatorInfo;
484 this.persistSelection = persistSelection;
485 }
486 }
487
Sarah Chin71b3a852022-09-28 15:54:19 -0700488 private static final class PurchasePremiumCapabilityArgument {
489 public @TelephonyManager.PremiumCapability int capability;
490 public @NonNull String appName;
491 public @NonNull IIntegerConsumer callback;
492
493 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
494 @NonNull String appName, @NonNull IIntegerConsumer callback) {
495 this.capability = capability;
496 this.appName = appName;
497 this.callback = callback;
498 }
499 }
500
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700501 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
503 * request after sending. The main thread will notify the request when it is complete.
504 */
505 private static final class MainThreadRequest {
506 /** The argument to use for the request */
507 public Object argument;
508 /** The result of the request that is run on the main thread */
509 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800510 // The subscriber id that this request applies to. Defaults to
511 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
512 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513
Nathan Harold92bed182018-10-12 18:16:49 -0700514 // In cases where subId is unavailable, the caller needs to specify the phone.
515 public Phone phone;
516
vagdeviaf9a5b92018-08-15 16:01:53 -0700517 public WorkSource workSource;
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 public MainThreadRequest(Object argument) {
520 this.argument = argument;
521 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800522
Nathan Harold92bed182018-10-12 18:16:49 -0700523 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
524 this.argument = argument;
525 if (phone != null) {
526 this.phone = phone;
527 }
528 this.workSource = workSource;
529 }
530
vagdeviaf9a5b92018-08-15 16:01:53 -0700531 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800532 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800533 if (subId != null) {
534 this.subId = subId;
535 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700536 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 }
539
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800540 private static final class IncomingThirdPartyCallArgs {
541 public final ComponentName component;
542 public final String callId;
543 public final String callerDisplayName;
544
545 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
546 String callerDisplayName) {
547 this.component = component;
548 this.callId = callId;
549 this.callerDisplayName = callerDisplayName;
550 }
551 }
552
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553 /**
554 * A handler that processes messages on the main thread in the phone process. Since many
555 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
556 * inbound binder threads to the main thread in the phone process. The Binder thread
557 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
558 * on, which will be notified when the operation completes and will contain the result of the
559 * request.
560 *
561 * <p>If a MainThreadRequest object is provided in the msg.obj field,
562 * note that request.result must be set to something non-null for the calling thread to
563 * unblock.
564 */
565 private final class MainThreadHandler extends Handler {
566 @Override
567 public void handleMessage(Message msg) {
568 MainThreadRequest request;
569 Message onCompleted;
570 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000571 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800573 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574
575 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 case CMD_HANDLE_USSD_REQUEST: {
577 request = (MainThreadRequest) msg.obj;
578 final Phone phone = getPhoneFromRequest(request);
579 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800580 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700582
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 if (!isUssdApiAllowed(request.subId)) {
584 // Carrier does not support use of this API, return failure.
585 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
586 UssdResponse response = new UssdResponse(ussdRequest, null);
587 Bundle returnData = new Bundle();
588 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
589 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700590
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 request.result = true;
592 notifyRequester(request);
593 return;
594 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700595
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 try {
597 request.result = phone != null
598 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
599 } catch (CallStateException cse) {
600 request.result = false;
601 }
602 // Wake up the requesting thread
603 notifyRequester(request);
604 break;
pkanwar32d516d2016-10-14 19:37:38 -0700605 }
606
Yorke Lee716f67e2015-06-17 15:39:16 -0700607 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700608 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700609 final Phone phone = getPhoneFromRequest(request);
610 request.result = phone != null ?
611 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
612 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 uiccPort = getUiccPortFromRequest(request);
622 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800624 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000629 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800630 iccArgument.channel, iccArgument.cla, iccArgument.command,
631 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
632 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result;
641 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800642 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 if (ar.result == null) {
644 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800645 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800647 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 } else {
649 loge("iccTransmitApduLogicalChannel: Unknown exception");
650 }
651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 break;
654
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
656 request = (MainThreadRequest) msg.obj;
657 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort = getUiccPortFromRequest(request);
659 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800661 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 } else {
664 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000666 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800667 iccArgument.cla, iccArgument.command, iccArgument.p1,
668 iccArgument.p2,
669 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 break;
672
673 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result;
678 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800679 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 if (ar.result == null) {
681 loge("iccTransmitApduBasicChannel: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("iccTransmitApduBasicChannel: CommandException: " +
684 ar.exception);
685 } else {
686 loge("iccTransmitApduBasicChannel: Unknown exception");
687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 break;
691
692 case CMD_EXCHANGE_SIM_IO:
693 request = (MainThreadRequest) msg.obj;
694 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000695 uiccPort = getUiccPortFromRequest(request);
696 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800698 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700699 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 } else {
701 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
702 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000703 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
705 iccArgument.data, onCompleted);
706 }
707 break;
708
709 case EVENT_EXCHANGE_SIM_IO_DONE:
710 ar = (AsyncResult) msg.obj;
711 request = (MainThreadRequest) ar.userObj;
712 if (ar.exception == null && ar.result != null) {
713 request.result = ar.result;
714 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 break;
719
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 case CMD_SEND_ENVELOPE:
721 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort = getUiccPortFromRequest(request);
723 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800725 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800729 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800731 break;
732
733 case EVENT_SEND_ENVELOPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800739 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700740 if (ar.result == null) {
741 loge("sendEnvelopeWithStatus: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("sendEnvelopeWithStatus: CommandException: " +
744 ar.exception);
745 } else {
746 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
747 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800750 break;
751
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 case CMD_OPEN_CHANNEL:
753 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000754 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800755 IccLogicalChannelRequest openChannelRequest =
756 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000757 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700758 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800759 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800760 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 } else {
763 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800764 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
765 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 break;
768
769 case EVENT_OPEN_CHANNEL_DONE:
770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700772 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 int[] result = (int[]) ar.result;
775 int channelId = result[0];
776 byte[] selectResponse = null;
777 if (result.length > 1) {
778 selectResponse = new byte[result.length - 1];
779 for (int i = 1; i < result.length; ++i) {
780 selectResponse[i - 1] = (byte) result[i];
781 }
782 }
783 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800784 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800785
786 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700787 if (uiccPort == null) {
788 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
789 } else {
790 IccLogicalChannelRequest channelRequest =
791 (IccLogicalChannelRequest) request.argument;
792 channelRequest.channel = channelId;
793 uiccPort.onLogicalChannelOpened(channelRequest);
794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 if (ar.result == null) {
797 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700799 if (ar.exception != null) {
800 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
801 }
802
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700803 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700804 if (ar.exception instanceof CommandException) {
805 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800806 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700807 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700808 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700809 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700810 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700811 }
812 }
813 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800814 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700816 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700818 break;
819
820 case CMD_CLOSE_CHANNEL:
821 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000822 uiccPort = getUiccPortFromRequest(request);
823 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700824 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800825 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800826 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800827 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700828 } else {
829 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000830 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 break;
833
834 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null) {
838 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800839 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700840 if (uiccPort == null) {
841 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
842 } else {
843 final int channelId = (Integer) request.argument;
844 uiccPort.onLogicalChannelClosed(channelId);
845 }
Chen Xu540470b2021-12-14 17:15:47 -0800846 } else {
847 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800848 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800849 if (ar.exception instanceof CommandException) {
850 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
851 CommandException.Error error =
852 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800853 if (error == CommandException.Error.INVALID_ARGUMENTS) {
854 // should only throw exceptions from the binder threads.
855 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800856 "iccCloseLogicalChannel: invalid argument ");
857 }
858 } else {
859 loge("iccCloseLogicalChannel: Unknown exception");
860 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800861 request.result = (exception != null) ? exception :
862 new IllegalStateException(
863 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800864 }
865 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800866 break;
867
868 case CMD_NV_READ_ITEM:
869 request = (MainThreadRequest) msg.obj;
870 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800871 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
872 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800873 break;
874
875 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800881 request.result = "";
882 if (ar.result == null) {
883 loge("nvReadItem: Empty response");
884 } else if (ar.exception instanceof CommandException) {
885 loge("nvReadItem: CommandException: " +
886 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700887 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800888 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700889 }
890 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700891 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700892 break;
893
Jake Hambye994d462014-02-03 13:10:13 -0800894 case CMD_NV_WRITE_ITEM:
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
897 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800898 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700899 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800900 break;
901
902 case EVENT_NV_WRITE_ITEM_DONE:
903 handleNullReturnEvent(msg, "nvWriteItem");
904 break;
905
906 case CMD_NV_WRITE_CDMA_PRL:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800910 break;
911
912 case EVENT_NV_WRITE_CDMA_PRL_DONE:
913 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
914 break;
915
chen xu6dac5ab2018-10-26 17:39:23 -0700916 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800917 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700918 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800920 break;
921
chen xu6dac5ab2018-10-26 17:39:23 -0700922 case EVENT_RESET_MODEM_CONFIG_DONE:
923 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800924 break;
925
Sooraj Sasindran37444802020-08-11 10:40:43 -0700926 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
929 request);
930 Phone phone = getPhoneFromRequest(request);
931 if (phone != null) {
932 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
933 } else {
934 loge("isNRDualConnectivityEnabled: No phone object");
935 request.result = false;
936 notifyRequester(request);
937 }
938 break;
939 }
940
941 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 // request.result must be set to something non-null
948 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700949 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700950 request.result = ar.result;
951 } else {
952 request.result = false;
953 }
954 if (ar.result == null) {
955 loge("isNRDualConnectivityEnabled: Empty response");
956 } else if (ar.exception instanceof CommandException) {
957 loge("isNRDualConnectivityEnabled: CommandException: "
958 + ar.exception);
959 } else {
960 loge("isNRDualConnectivityEnabled: Unknown exception");
961 }
962 }
963 notifyRequester(request);
964 break;
965
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 case CMD_IS_VONR_ENABLED: {
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
969 request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.isVoNrEnabled(onCompleted, request.workSource);
973 } else {
974 loge("isVoNrEnabled: No phone object");
975 request.result = false;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_IS_VONR_ENABLED_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null && ar.result != null) {
985 request.result = ar.result;
986 } else {
987 // request.result must be set to something non-null
988 // for the calling thread to unblock
989 if (ar.result != null) {
990 request.result = ar.result;
991 } else {
992 request.result = false;
993 }
994 if (ar.result == null) {
995 loge("isVoNrEnabled: Empty response");
996 } else if (ar.exception instanceof CommandException) {
997 loge("isVoNrEnabled: CommandException: "
998 + ar.exception);
999 } else {
1000 loge("isVoNrEnabled: Unknown exception");
1001 }
1002 }
1003 notifyRequester(request);
1004 break;
1005
Sooraj Sasindran37444802020-08-11 10:40:43 -07001006 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1009 Phone phone = getPhoneFromRequest(request);
1010 if (phone != null) {
1011 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1012 request.workSource);
1013 } else {
1014 loge("enableNrDualConnectivity: No phone object");
1015 request.result =
1016 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1017 notifyRequester(request);
1018 }
1019 break;
1020 }
1021
1022 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
1025 if (ar.exception == null) {
1026 request.result =
1027 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1028 } else {
1029 request.result =
1030 TelephonyManager
1031 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1036 request.result =
1037 TelephonyManager
1038 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001039 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1040 request.result =
1041 TelephonyManager
1042 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001043 }
1044 loge("enableNrDualConnectivity" + ": CommandException: "
1045 + ar.exception);
1046 } else {
1047 loge("enableNrDualConnectivity" + ": Unknown exception");
1048 }
1049 }
1050 notifyRequester(request);
1051 break;
1052 }
1053
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001054 case CMD_ENABLE_VONR: {
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1057 Phone phone = getPhoneFromRequest(request);
1058 if (phone != null) {
1059 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1060 request.workSource);
1061 } else {
1062 loge("setVoNrEnabled: No phone object");
1063 request.result =
1064 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1065 notifyRequester(request);
1066 }
1067 break;
1068 }
1069
1070 case EVENT_ENABLE_VONR_DONE: {
1071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
1073 if (ar.exception == null) {
1074 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1075 } else {
1076 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1077 if (ar.exception instanceof CommandException) {
1078 CommandException.Error error =
1079 ((CommandException) (ar.exception)).getCommandError();
1080 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1081 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1083 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1084 } else {
1085 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1086 }
1087 loge("setVoNrEnabled" + ": CommandException: "
1088 + ar.exception);
1089 } else {
1090 loge("setVoNrEnabled" + ": Unknown exception");
1091 }
1092 }
1093 notifyRequester(request);
1094 break;
1095 }
1096
SongFerngWang3ef3e072020-12-21 16:41:52 +08001097 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001099 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1100 request);
1101 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 break;
1103
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
1107 if (ar.exception == null && ar.result != null) {
1108 request.result = ar.result; // Integer
1109 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301110 // request.result must be set to something non-null
1111 // for the calling thread to unblock
1112 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001113 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 loge("getAllowedNetworkTypesBitmask: CommandException: "
1117 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 }
1121 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001122 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001127 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1128 request);
1129 Pair<Integer, Long> reasonWithNetworkTypes =
1130 (Pair<Integer, Long>) request.argument;
1131 getPhoneFromRequest(request).setAllowedNetworkTypes(
1132 reasonWithNetworkTypes.first,
1133 reasonWithNetworkTypes.second,
1134 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 break;
1136
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1138 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 break;
1140
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001141 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1142 request = (MainThreadRequest)msg.obj;
1143 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001144 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001145 break;
1146
1147 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1148 ar = (AsyncResult)msg.obj;
1149 request = (MainThreadRequest)ar.userObj;
1150 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001151 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001152 break;
1153
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001154 case CMD_SET_VOICEMAIL_NUMBER:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1157 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001158 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1159 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001160 break;
1161
1162 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1163 handleNullReturnEvent(msg, "setVoicemailNumber");
1164 break;
1165
Stuart Scott54788802015-03-30 13:18:01 -07001166 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1169 request);
1170 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1171 break;
1172
1173 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1174 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1175 break;
1176
Shishir Agrawal302c8692015-06-19 13:49:39 -07001177 case CMD_PERFORM_NETWORK_SCAN:
1178 request = (MainThreadRequest) msg.obj;
1179 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1180 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1181 break;
1182
Hall Liu27d24262020-09-18 19:04:59 -07001183 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001186 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1187 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1188 request.argument;
1189 int callForwardingReason = args.first;
1190 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001191 break;
Hall Liu27d24262020-09-18 19:04:59 -07001192 }
1193 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001194 ar = (AsyncResult) msg.obj;
1195 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001196 TelephonyManager.CallForwardingInfoCallback callback =
1197 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1198 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001200 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1202 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1203 // Service Class is a bit mask per 3gpp 27.007. Search for
1204 // any service for voice call.
1205 if ((callForwardInfo.serviceClass
1206 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001207 callForwardingInfo = new CallForwardingInfo(
1208 callForwardInfo.status
1209 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001210 callForwardInfo.reason,
1211 callForwardInfo.number,
1212 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001213 break;
1214 }
1215 }
1216 // Didn't find a call forward info for voice call.
1217 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001218 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1219 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001220 }
Hall Liu27d24262020-09-18 19:04:59 -07001221 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001222 } else {
1223 if (ar.result == null) {
1224 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1225 }
1226 if (ar.exception != null) {
1227 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1228 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001229 int errorCode = TelephonyManager
1230 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 if (ar.exception instanceof CommandException) {
1232 CommandException.Error error =
1233 ((CommandException) (ar.exception)).getCommandError();
1234 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001235 errorCode = TelephonyManager
1236 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001237 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001238 errorCode = TelephonyManager
1239 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001240 }
1241 }
Hall Liu27d24262020-09-18 19:04:59 -07001242 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 }
Shuo Qian4a594052020-01-23 11:59:30 -08001244 break;
Hall Liu27d24262020-09-18 19:04:59 -07001245 }
Shuo Qian4a594052020-01-23 11:59:30 -08001246
Hall Liu27d24262020-09-18 19:04:59 -07001247 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001248 request = (MainThreadRequest) msg.obj;
1249 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001250 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001251 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001252 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1253 request.argument).first;
1254 request.phone.setCallForwardingOption(
1255 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001256 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001257 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001258 callForwardingInfoToSet.getReason(),
1259 callForwardingInfoToSet.getNumber(),
1260 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263
Hall Liu27d24262020-09-18 19:04:59 -07001264 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 ar = (AsyncResult) msg.obj;
1266 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001267 Consumer<Integer> callback =
1268 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1269 request.argument).second;
1270 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001271 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001272 int errorCode = TelephonyManager.CallForwardingInfoCallback
1273 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001274 if (ar.exception instanceof CommandException) {
1275 CommandException.Error error =
1276 ((CommandException) (ar.exception)).getCommandError();
1277 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001278 errorCode = TelephonyManager.CallForwardingInfoCallback
1279 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001280 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001281 errorCode = TelephonyManager.CallForwardingInfoCallback
1282 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001283 }
1284 }
1285 callback.accept(errorCode);
1286 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001287 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001288 }
Shuo Qian4a594052020-01-23 11:59:30 -08001289 break;
Hall Liu27d24262020-09-18 19:04:59 -07001290 }
Shuo Qian4a594052020-01-23 11:59:30 -08001291
Hall Liu27d24262020-09-18 19:04:59 -07001292 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001293 request = (MainThreadRequest) msg.obj;
1294 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1295 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1296 break;
Hall Liu27d24262020-09-18 19:04:59 -07001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298
Hall Liu27d24262020-09-18 19:04:59 -07001299 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001300 ar = (AsyncResult) msg.obj;
1301 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001302 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001305 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001306 // Service Class is a bit mask per 3gpp 27.007.
1307 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001308 if (callForwardResults.length > 1
1309 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001310 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001311 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001312 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1313 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001314 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001315 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001316 }
1317 } else {
1318 if (ar.result == null) {
1319 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1320 }
1321 if (ar.exception != null) {
1322 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1323 }
1324 if (ar.exception instanceof CommandException) {
1325 CommandException.Error error =
1326 ((CommandException) (ar.exception)).getCommandError();
1327 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001329 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1331 callWaitingStatus =
1332 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001333 }
1334 }
1335 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001337 break;
Hall Liu27d24262020-09-18 19:04:59 -07001338 }
Shuo Qian4a594052020-01-23 11:59:30 -08001339
Hall Liu27d24262020-09-18 19:04:59 -07001340 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001341 request = (MainThreadRequest) msg.obj;
1342 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001343 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1344 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001345 break;
Hall Liu27d24262020-09-18 19:04:59 -07001346 }
Shuo Qian4a594052020-01-23 11:59:30 -08001347
Hall Liu27d24262020-09-18 19:04:59 -07001348 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001351 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1352 Consumer<Integer> callback =
1353 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1354 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001355 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001356 if (ar.exception instanceof CommandException) {
1357 CommandException.Error error =
1358 ((CommandException) (ar.exception)).getCommandError();
1359 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1360 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1362 callback.accept(
1363 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001364 } else {
1365 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1366 }
1367 } else {
1368 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1369 }
1370 } else {
1371 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1372 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001373 }
Shuo Qian4a594052020-01-23 11:59:30 -08001374 break;
Hall Liu27d24262020-09-18 19:04:59 -07001375 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001376 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 CellNetworkScanResult cellScanResult;
1380 if (ar.exception == null && ar.result != null) {
1381 cellScanResult = new CellNetworkScanResult(
1382 CellNetworkScanResult.STATUS_SUCCESS,
1383 (List<OperatorInfo>) ar.result);
1384 } else {
1385 if (ar.result == null) {
1386 loge("getCellNetworkScanResults: Empty response");
1387 }
1388 if (ar.exception != null) {
1389 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1390 }
1391 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1392 if (ar.exception instanceof CommandException) {
1393 CommandException.Error error =
1394 ((CommandException) (ar.exception)).getCommandError();
1395 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1396 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1397 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1398 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1399 }
1400 }
1401 cellScanResult = new CellNetworkScanResult(errorCode, null);
1402 }
1403 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001404 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001405 break;
1406
1407 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1408 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001409 ManualNetworkSelectionArgument selArg =
1410 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001411 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1412 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001413 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1414 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001415 break;
1416
1417 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 if (ar.exception == null) {
1421 request.result = true;
1422 } else {
1423 request.result = false;
1424 loge("setNetworkSelectionModeManual " + ar.exception);
1425 }
1426 notifyRequester(request);
1427 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 break;
1429
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001430 case CMD_GET_MODEM_ACTIVITY_INFO:
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001433 if (defaultPhone != null) {
1434 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 } else {
1436 ResultReceiver result = (ResultReceiver) request.argument;
1437 Bundle bundle = new Bundle();
1438 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001439 new ModemActivityInfo(0, 0, 0,
1440 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001441 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001442 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 break;
1444
Hall Liud0f208c2020-10-14 16:54:44 -07001445 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001448 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001449 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001450 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001451 if (mLastModemActivityInfo == null) {
1452 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1453 mLastModemActivitySpecificInfo[0] =
1454 new ActivityStatsTechSpecificInfo(
1455 0,
1456 0,
1457 new int[ModemActivityInfo.getNumTxPowerLevels()],
1458 0);
1459 mLastModemActivityInfo =
1460 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1461 }
1462
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001464 // Update the last modem activity info and the result of the request.
1465 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1466 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001467 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 }
Kai Shi917fdc62022-11-28 14:01:02 -08001469 // This is needed to decouple ret from mLastModemActivityInfo
1470 // We don't want to return mLastModemActivityInfo which is updated
1471 // inside mergeModemActivityInfo()
1472 ret = new ModemActivityInfo(
1473 mLastModemActivityInfo.getTimestampMillis(),
1474 mLastModemActivityInfo.getSleepTimeMillis(),
1475 mLastModemActivityInfo.getIdleTimeMillis(),
1476 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001477
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 } else {
1479 if (ar.result == null) {
1480 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001481 error = TelephonyManager.ModemActivityInfoException
1482 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001484 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001485 error = TelephonyManager.ModemActivityInfoException
1486 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001487 } else {
1488 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001489 error = TelephonyManager.ModemActivityInfoException
1490 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491 }
1492 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001493 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001494 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001495 bundle.putParcelable(
1496 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001497 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001498 } else {
1499 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1500 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001501 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001503 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001504 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 case CMD_SET_ALLOWED_CARRIERS:
1507 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001508 CarrierRestrictionRules argument =
1509 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001510 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001511 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 break;
1513
1514 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null && ar.result != null) {
1518 request.result = ar.result;
1519 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001520 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1521 if (ar.exception instanceof CommandException) {
1522 loge("setAllowedCarriers: CommandException: " + ar.exception);
1523 CommandException.Error error =
1524 ((CommandException) (ar.exception)).getCommandError();
1525 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1526 request.result =
1527 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1528 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 } else {
1530 loge("setAllowedCarriers: Unknown exception");
1531 }
1532 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001533 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 break;
1535
1536 case CMD_GET_ALLOWED_CARRIERS:
1537 request = (MainThreadRequest) msg.obj;
1538 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001539 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 break;
1541
1542 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 if (ar.exception == null && ar.result != null) {
1546 request.result = ar.result;
1547 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001548 request.result = new IllegalStateException(
1549 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001550 if (ar.result == null) {
1551 loge("getAllowedCarriers: Empty response");
1552 } else if (ar.exception instanceof CommandException) {
1553 loge("getAllowedCarriers: CommandException: " +
1554 ar.exception);
1555 } else {
1556 loge("getAllowedCarriers: Unknown exception");
1557 }
1558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001559 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001560 break;
1561
Nathan Haroldb3014052017-01-25 15:57:32 -08001562 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 if (ar.exception == null && ar.result != null) {
1566 request.result = ar.result;
1567 } else {
1568 request.result = new IllegalArgumentException(
1569 "Failed to retrieve Forbidden Plmns");
1570 if (ar.result == null) {
1571 loge("getForbiddenPlmns: Empty response");
1572 } else {
1573 loge("getForbiddenPlmns: Unknown exception");
1574 }
1575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001576 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001577 break;
1578
1579 case CMD_GET_FORBIDDEN_PLMNS:
1580 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001581 uiccPort = getUiccPortFromRequest(request);
1582 if (uiccPort == null) {
1583 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001584 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001585 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001586 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001587 break;
1588 }
1589 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001590 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001591 if (uiccApp == null) {
1592 loge("getForbiddenPlmns() no app with specified type -- "
1593 + appType);
1594 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001595 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001596 break;
1597 } else {
1598 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1599 + " specified type -- " + appType);
1600 }
1601 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1602 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1603 onCompleted);
1604 break;
1605
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001606 case CMD_SWITCH_SLOTS:
1607 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001608 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001609 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001610 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001611 break;
1612
1613 case EVENT_SWITCH_SLOTS_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001617 notifyRequester(request);
1618 break;
1619 case CMD_GET_NETWORK_SELECTION_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1622 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1623 break;
1624
1625 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 if (ar.exception != null) {
1629 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1630 } else {
1631 int mode = ((int[]) ar.result)[0];
1632 if (mode == 0) {
1633 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1634 } else {
1635 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1636 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001637 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
1639 break;
1640 case CMD_GET_CDMA_ROAMING_MODE:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1643 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1644 break;
1645 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 if (ar.exception != null) {
1649 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1650 } else {
1651 request.result = ((int[]) ar.result)[0];
1652 }
1653 notifyRequester(request);
1654 break;
1655 case CMD_SET_CDMA_ROAMING_MODE:
1656 request = (MainThreadRequest) msg.obj;
1657 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1658 int mode = (int) request.argument;
1659 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1660 break;
1661 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = ar.exception == null;
1665 notifyRequester(request);
1666 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001667 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1670 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1671 break;
1672 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
1675 if (ar.exception != null) {
1676 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1677 } else {
1678 request.result = ((int[]) ar.result)[0];
1679 }
1680 notifyRequester(request);
1681 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001682 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1685 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001686 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1687 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001688 break;
1689 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
1692 request.result = ar.exception == null;
1693 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001694 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001695 case CMD_GET_ALL_CELL_INFO:
1696 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001698 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001699 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001700 case EVENT_GET_ALL_CELL_INFO_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001703 // If a timeout occurs, the response will be null
1704 request.result = (ar.exception == null && ar.result != null)
1705 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001706 synchronized (request) {
1707 request.notifyAll();
1708 }
1709 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001710 case CMD_REQUEST_CELL_INFO_UPDATE:
1711 request = (MainThreadRequest) msg.obj;
1712 request.phone.requestCellInfoUpdate(request.workSource,
1713 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1714 break;
1715 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1719 try {
1720 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001721 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001722 cb.onError(
1723 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1724 ar.exception.getClass().getName(),
1725 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001726 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001727 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001728 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001729 } else {
1730 // use the result as returned
1731 cb.onCellInfo((List<CellInfo>) ar.result);
1732 }
1733 } catch (RemoteException re) {
1734 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1735 }
1736 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001737 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 request = (MainThreadRequest) msg.obj;
1739 WorkSource ws = (WorkSource) request.argument;
1740 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001741 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001743 }
1744 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 ar = (AsyncResult) msg.obj;
1746 request = (MainThreadRequest) ar.userObj;
1747 if (ar.exception == null) {
1748 request.result = ar.result;
1749 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001750 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001752 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 }
1754
1755 synchronized (request) {
1756 request.notifyAll();
1757 }
1758 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001759 }
chen xu6dac5ab2018-10-26 17:39:23 -07001760 case CMD_MODEM_REBOOT:
1761 request = (MainThreadRequest) msg.obj;
1762 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001763 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001764 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001765 case EVENT_CMD_MODEM_REBOOT_DONE:
1766 handleNullReturnEvent(msg, "rebootModem");
1767 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001768 case CMD_REQUEST_ENABLE_MODEM:
1769 request = (MainThreadRequest) msg.obj;
1770 boolean enable = (boolean) request.argument;
1771 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001772 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001773 PhoneConfigurationManager.getInstance()
1774 .enablePhone(request.phone, enable, onCompleted);
1775 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001776 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001777 ar = (AsyncResult) msg.obj;
1778 request = (MainThreadRequest) ar.userObj;
1779 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001780 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001781 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001782 if ((boolean) request.result) {
1783 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1784 updateModemStateMetrics();
1785 } else {
1786 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1787 + ar.exception);
1788 }
1789 notifyRequester(request);
1790 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001791 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001792 case CMD_GET_MODEM_STATUS:
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1795 PhoneConfigurationManager.getInstance()
1796 .getPhoneStatusFromModem(request.phone, onCompleted);
1797 break;
1798 case EVENT_GET_MODEM_STATUS_DONE:
1799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801 int id = request.phone.getPhoneId();
1802 if (ar.exception == null && ar.result != null) {
1803 request.result = ar.result;
1804 //update the cache as modem status has changed
1805 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1806 (boolean) request.result);
1807 } else {
1808 // Return true if modem status cannot be retrieved. For most cases,
1809 // modem status is on. And for older version modems, GET_MODEM_STATUS
1810 // and disable modem are not supported. Modem is always on.
1811 // TODO: this should be fixed in R to support a third
1812 // status UNKNOWN b/131631629
1813 request.result = true;
1814 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1815 + ar.exception);
1816 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001817 notifyRequester(request);
1818 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001819 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1820 request = (MainThreadRequest) msg.obj;
1821 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1822 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1823 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1824 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1825 break;
1826 }
1827 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1828 ar = (AsyncResult) msg.obj;
1829 request = (MainThreadRequest) ar.userObj;
1830 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1831 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1832 args.second.accept(ar.exception == null);
1833 notifyRequester(request);
1834 break;
1835 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001836 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1837 request = (MainThreadRequest) msg.obj;
1838 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1839 Phone phone = getPhoneFromRequest(request);
1840 if (phone != null) {
1841 phone.getSystemSelectionChannels(onCompleted);
1842 } else {
1843 loge("getSystemSelectionChannels: No phone object");
1844 request.result = new ArrayList<RadioAccessSpecifier>();
1845 notifyRequester(request);
1846 }
1847 break;
1848 }
1849 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 if (ar.exception == null && ar.result != null) {
1853 request.result = ar.result;
1854 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001855 request.result = new IllegalStateException(
1856 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001857 if (ar.result == null) {
1858 loge("getSystemSelectionChannels: Empty response");
1859 } else {
1860 loge("getSystemSelectionChannels: Unknown exception");
1861 }
1862 }
1863 notifyRequester(request);
1864 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001865 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1866 ar = (AsyncResult) msg.obj;
1867 request = (MainThreadRequest) ar.userObj;
1868 if (ar.exception == null && ar.result != null) {
1869 request.result = ar.result;
1870 } else {
1871 request.result = -1;
1872 loge("Failed to set Forbidden Plmns");
1873 if (ar.result == null) {
1874 loge("setForbidenPlmns: Empty response");
1875 } else if (ar.exception != null) {
1876 loge("setForbiddenPlmns: Exception: " + ar.exception);
1877 request.result = -1;
1878 } else {
1879 loge("setForbiddenPlmns: Unknown exception");
1880 }
1881 }
1882 notifyRequester(request);
1883 break;
1884 case CMD_SET_FORBIDDEN_PLMNS:
1885 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001886 uiccPort = getUiccPortFromRequest(request);
1887 if (uiccPort == null) {
1888 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001889 request.result = -1;
1890 notifyRequester(request);
1891 break;
1892 }
1893 Pair<Integer, List<String>> setFplmnsArgs =
1894 (Pair<Integer, List<String>>) request.argument;
1895 appType = setFplmnsArgs.first;
1896 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001897 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001898 if (uiccApp == null) {
1899 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1900 request.result = -1;
1901 loge("Failed to get UICC App");
1902 notifyRequester(request);
1903 } else {
1904 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1905 ((SIMRecords) uiccApp.getIccRecords())
1906 .setForbiddenPlmns(onCompleted, fplmns);
1907 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001908 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001909 case CMD_ERASE_MODEM_CONFIG:
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1912 defaultPhone.eraseModemConfig(onCompleted);
1913 break;
1914 case EVENT_ERASE_MODEM_CONFIG_DONE:
1915 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001916 break;
zoey chene02881a2019-12-30 16:11:23 +08001917
Kai Shif70f46f2021-03-03 13:59:46 -08001918 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1919 request = (MainThreadRequest) msg.obj;
1920 request.result = defaultPhone.eraseDataInSharedPreferences();
1921 notifyRequester(request);
1922 break;
1923
zoey chene02881a2019-12-30 16:11:23 +08001924 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1925 request = (MainThreadRequest) msg.obj;
1926 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1927 Pair<String, String> changed = (Pair<String, String>) request.argument;
1928 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1929 changed.first, changed.second, onCompleted);
1930 break;
1931 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1932 ar = (AsyncResult) msg.obj;
1933 request = (MainThreadRequest) ar.userObj;
1934 if (ar.exception == null) {
1935 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001936 // If the operation is successful, update the PIN storage
1937 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1938 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001939 UiccController.getInstance().getPinStorage()
1940 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001941 } else {
1942 request.result = msg.arg1;
1943 }
1944 notifyRequester(request);
1945 break;
1946
Michele Berionne5e411512020-11-13 02:36:59 +00001947 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001948 request = (MainThreadRequest) msg.obj;
1949 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1950 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1951 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1952 enabled.first, enabled.second, onCompleted);
1953 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001954 }
zoey chene02881a2019-12-30 16:11:23 +08001955 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1956 ar = (AsyncResult) msg.obj;
1957 request = (MainThreadRequest) ar.userObj;
1958 if (ar.exception == null) {
1959 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001960 // If the operation is successful, update the PIN storage
1961 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1962 int phoneId = getPhoneFromRequest(request).getPhoneId();
1963 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001964 UiccController.getInstance().getPinStorage()
1965 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001966 } else {
1967 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1968 }
zoey chene02881a2019-12-30 16:11:23 +08001969 } else {
1970 request.result = msg.arg1;
1971 }
Michele Berionne5e411512020-11-13 02:36:59 +00001972
1973
zoey chene02881a2019-12-30 16:11:23 +08001974 notifyRequester(request);
1975 break;
1976
Peter Wangdafb9ac2020-01-15 14:13:38 -08001977 case MSG_NOTIFY_USER_ACTIVITY:
1978 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001979 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001980 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1981 getDefaultPhone().getContext().sendBroadcastAsUser(
1982 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1983 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001984
1985 case CMD_SET_DATA_THROTTLING: {
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1988 DataThrottlingRequest dataThrottlingRequest =
1989 (DataThrottlingRequest) request.argument;
1990 Phone phone = getPhoneFromRequest(request);
1991 if (phone != null) {
1992 phone.setDataThrottling(onCompleted,
1993 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1994 dataThrottlingRequest.getCompletionDurationMillis());
1995 } else {
1996 loge("setDataThrottling: No phone object");
1997 request.result =
1998 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1999 notifyRequester(request);
2000 }
2001
2002 break;
2003 }
2004 case EVENT_SET_DATA_THROTTLING_DONE:
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007
2008 if (ar.exception == null) {
2009 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2010 } else if (ar.exception instanceof CommandException) {
2011 loge("setDataThrottling: CommandException: " + ar.exception);
2012 CommandException.Error error =
2013 ((CommandException) (ar.exception)).getCommandError();
2014
2015 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2016 request.result = TelephonyManager
2017 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2018 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2019 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002020 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2021 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002022 } else {
2023 request.result =
2024 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2025 }
2026 } else {
2027 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2028 }
2029 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2030 notifyRequester(request);
2031 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002032
2033 case CMD_SET_SIM_POWER: {
2034 request = (MainThreadRequest) msg.obj;
2035 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2036 request = (MainThreadRequest) msg.obj;
2037 int stateToSet =
2038 ((Pair<Integer, IIntegerConsumer>)
2039 request.argument).first;
2040 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2041 break;
2042 }
2043 case EVENT_SET_SIM_POWER_DONE: {
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046 IIntegerConsumer callback =
2047 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2048 if (ar.exception != null) {
2049 loge("setSimPower exception: " + ar.exception);
2050 int errorCode = TelephonyManager.CallForwardingInfoCallback
2051 .RESULT_ERROR_UNKNOWN;
2052 if (ar.exception instanceof CommandException) {
2053 CommandException.Error error =
2054 ((CommandException) (ar.exception)).getCommandError();
2055 if (error == CommandException.Error.SIM_ERR) {
2056 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2057 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2058 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2059 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2060 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2061 } else {
2062 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2063 }
2064 }
2065 try {
2066 callback.accept(errorCode);
2067 } catch (RemoteException e) {
2068 // Ignore if the remote process is no longer available to call back.
2069 Log.w(LOG_TAG, "setSimPower: callback not available.");
2070 }
2071 } else {
2072 try {
2073 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2074 } catch (RemoteException e) {
2075 // Ignore if the remote process is no longer available to call back.
2076 Log.w(LOG_TAG, "setSimPower: callback not available.");
2077 }
2078 }
2079 break;
2080 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002081 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2082 request = (MainThreadRequest) msg.obj;
2083
2084 final Phone phone = getPhoneFromRequest(request);
2085 if (phone == null || phone.getServiceStateTracker() == null) {
2086 request.result = new IllegalStateException("Phone or SST is null");
2087 notifyRequester(request);
2088 break;
2089 }
2090
2091 Pair<Integer, SignalStrengthUpdateRequest> pair =
2092 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2093 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2094 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002095 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002096 request.subId, pair.first /*callingUid*/,
2097 pair.second /*request*/, onCompleted);
2098 break;
2099 }
2100 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2101 ar = (AsyncResult) msg.obj;
2102 request = (MainThreadRequest) ar.userObj;
2103 // request.result will be the exception of ar if present, true otherwise.
2104 // Be cautious not to leave result null which will wait() forever
2105 request.result = ar.exception != null ? ar.exception : true;
2106 notifyRequester(request);
2107 break;
2108 }
2109 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2110 request = (MainThreadRequest) msg.obj;
2111
2112 Phone phone = getPhoneFromRequest(request);
2113 if (phone == null || phone.getServiceStateTracker() == null) {
2114 request.result = new IllegalStateException("Phone or SST is null");
2115 notifyRequester(request);
2116 break;
2117 }
2118
2119 Pair<Integer, SignalStrengthUpdateRequest> pair =
2120 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2121 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2122 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002123 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002124 request.subId, pair.first /*callingUid*/,
2125 pair.second /*request*/, onCompleted);
2126 break;
2127 }
2128 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2129 ar = (AsyncResult) msg.obj;
2130 request = (MainThreadRequest) ar.userObj;
2131 request.result = ar.exception != null ? ar.exception : true;
2132 notifyRequester(request);
2133 break;
2134 }
Jordan Liu109698e2020-11-24 14:50:34 -08002135
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002136 case CMD_GET_SLICING_CONFIG: {
2137 request = (MainThreadRequest) msg.obj;
2138 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2139 request.phone.getSlicingConfig(onCompleted);
2140 break;
2141 }
2142 case EVENT_GET_SLICING_CONFIG_DONE: {
2143 ar = (AsyncResult) msg.obj;
2144 request = (MainThreadRequest) ar.userObj;
2145 ResultReceiver result = (ResultReceiver) request.argument;
2146
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002147 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002148 Bundle bundle = new Bundle();
2149 int resultCode = 0;
2150 if (ar.exception != null) {
2151 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2152 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002153 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002154 } else if (ar.result == null) {
2155 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002156 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002157 } else {
2158 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002159 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2160 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002161 }
2162
2163 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002164 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002165 }
2166 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2167 result.send(resultCode, bundle);
2168 notifyRequester(request);
2169 break;
2170 }
2171
Sarah Chin71b3a852022-09-28 15:54:19 -07002172 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002173 request = (MainThreadRequest) msg.obj;
2174 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002175 PurchasePremiumCapabilityArgument arg =
2176 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002177 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002178 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002179 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002180 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002181
Sarah Chin71b3a852022-09-28 15:54:19 -07002182 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002183 ar = (AsyncResult) msg.obj;
2184 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002185 PurchasePremiumCapabilityArgument arg =
2186 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002187 try {
2188 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002189 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002190 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002191 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002192 + ", result= "
2193 + TelephonyManager.convertPurchaseResultToString(result));
2194 } catch (RemoteException e) {
2195 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002196 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002197 + " failed: " + e;
2198 if (DBG) log(logStr);
2199 AnomalyReporter.reportAnomaly(
2200 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2201 }
2202 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002203 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002204
Michele Berionne5e411512020-11-13 02:36:59 +00002205 case CMD_PREPARE_UNATTENDED_REBOOT:
2206 request = (MainThreadRequest) msg.obj;
2207 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002208 UiccController.getInstance().getPinStorage()
2209 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002210 notifyRequester(request);
2211 break;
2212
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 default:
2214 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2215 break;
2216 }
2217 }
Jake Hambye994d462014-02-03 13:10:13 -08002218
Pengquan Menga1bb6272018-09-06 09:59:22 -07002219 private void notifyRequester(MainThreadRequest request) {
2220 synchronized (request) {
2221 request.notifyAll();
2222 }
2223 }
2224
Jake Hambye994d462014-02-03 13:10:13 -08002225 private void handleNullReturnEvent(Message msg, String command) {
2226 AsyncResult ar = (AsyncResult) msg.obj;
2227 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2228 if (ar.exception == null) {
2229 request.result = true;
2230 } else {
2231 request.result = false;
2232 if (ar.exception instanceof CommandException) {
2233 loge(command + ": CommandException: " + ar.exception);
2234 } else {
2235 loge(command + ": Unknown exception");
2236 }
2237 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002238 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
2243 * Posts the specified command to be executed on the main thread,
2244 * waits for the request to complete, and returns the result.
2245 * @see #sendRequestAsync
2246 */
2247 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002248 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2249 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002250 }
2251
2252 /**
2253 * Posts the specified command to be executed on the main thread,
2254 * waits for the request to complete, and returns the result.
2255 * @see #sendRequestAsync
2256 */
2257 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2258 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002259 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002260 }
2261
2262 /**
2263 * Posts the specified command to be executed on the main thread,
2264 * waits for the request to complete, and returns the result.
2265 * @see #sendRequestAsync
2266 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002267 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002268 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2269 }
2270
2271 /**
2272 * Posts the specified command to be executed on the main thread,
2273 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2274 * if not timeout or null otherwise.
2275 * @see #sendRequestAsync
2276 */
2277 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2278 long timeoutInMs) {
2279 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002280 }
2281
2282 /**
2283 * Posts the specified command to be executed on the main thread,
2284 * waits for the request to complete, and returns the result.
2285 * @see #sendRequestAsync
2286 */
Nathan Harold92bed182018-10-12 18:16:49 -07002287 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002288 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002289 }
2290
2291 /**
2292 * Posts the specified command to be executed on the main thread,
2293 * waits for the request to complete, and returns the result.
2294 * @see #sendRequestAsync
2295 */
2296 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002297 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2298 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002299 }
2300
2301 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002302 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2303 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2304 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002305 * @see #sendRequestAsync
2306 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002307 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2308 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2310 throw new RuntimeException("This method will deadlock if called from the main thread.");
2311 }
2312
Nathan Harold92bed182018-10-12 18:16:49 -07002313 MainThreadRequest request = null;
2314 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2315 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2316 } else if (phone != null) {
2317 request = new MainThreadRequest(argument, phone, workSource);
2318 } else {
2319 request = new MainThreadRequest(argument, subId, workSource);
2320 }
2321
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 Message msg = mMainThreadHandler.obtainMessage(command, request);
2323 msg.sendToTarget();
2324
Rambo Wang0f050d82021-02-12 11:43:36 -08002325
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 if (timeoutInMs >= 0) {
2328 // Wait for at least timeoutInMs before returning null request result
2329 long now = SystemClock.elapsedRealtime();
2330 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002331 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 try {
2333 request.wait(deadline - now);
2334 } catch (InterruptedException e) {
2335 // Do nothing, go back and check if request is completed or timeout
2336 } finally {
2337 now = SystemClock.elapsedRealtime();
2338 }
2339 }
2340 } else {
2341 // Wait for the request to complete
2342 while (request.result == null) {
2343 try {
2344 request.wait();
2345 } catch (InterruptedException e) {
2346 // Do nothing, go back and wait until the request is complete
2347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
2349 }
2350 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002351 if (request.result == null) {
2352 Log.wtf(LOG_TAG,
2353 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 return request.result;
2356 }
2357
2358 /**
2359 * Asynchronous ("fire and forget") version of sendRequest():
2360 * Posts the specified command to be executed on the main thread, and
2361 * returns immediately.
2362 * @see #sendRequest
2363 */
2364 private void sendRequestAsync(int command) {
2365 mMainThreadHandler.sendEmptyMessage(command);
2366 }
2367
2368 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002369 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002370 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002371 */
2372 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002373 sendRequestAsync(command, argument, null, null);
2374 }
2375
2376 /**
2377 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2378 * @see {@link #sendRequest(int,Object)}
2379 */
2380 private void sendRequestAsync(
2381 int command, Object argument, Phone phone, WorkSource workSource) {
2382 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002383 Message msg = mMainThreadHandler.obtainMessage(command, request);
2384 msg.sendToTarget();
2385 }
2386
2387 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 * Initialize the singleton PhoneInterfaceManager instance.
2389 * This is only done once, at startup, from PhoneApp.onCreate().
2390 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002391 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 synchronized (PhoneInterfaceManager.class) {
2393 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002394 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 } else {
2396 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2397 }
2398 return sInstance;
2399 }
2400 }
2401
2402 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002403 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002406 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002407 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002409 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002411 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002412 mTelephonySharedPreferences =
2413 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002414 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002415 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002416 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002417 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002418 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002419 mTelephony2gUpdater = new Telephony2gUpdater(
2420 Executors.newSingleThreadExecutor(), mApp);
2421 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 publish();
2423 }
2424
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002425 @VisibleForTesting
2426 public SharedPreferences getSharedPreferences() {
2427 return mTelephonySharedPreferences;
2428 }
2429
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002430 private Phone getDefaultPhone() {
2431 Phone thePhone = getPhone(getDefaultSubscription());
2432 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2433 }
2434
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 private void publish() {
2436 if (DBG) log("publish: " + this);
2437
Peter Wangc035ce42020-01-08 21:00:22 -08002438 TelephonyFrameworkInitializer
2439 .getTelephonyServiceManager()
2440 .getTelephonyServiceRegisterer()
2441 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 }
2443
Stuart Scott584921c2015-01-15 17:10:34 -08002444 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002445 if (request.phone != null) {
2446 return request.phone;
2447 } else {
2448 return getPhoneFromSubId(request.subId);
2449 }
2450 }
2451
2452 private Phone getPhoneFromSubId(int subId) {
2453 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2454 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002455 }
2456
Rambo Wange53e07d2022-05-10 13:01:13 -07002457 @Nullable
2458 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 Phone phone = getPhoneFromRequest(request);
2460 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002461 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002462 }
2463
Wink Saville36469e72014-06-11 15:17:00 -07002464 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002465 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002466 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468
Kai Shif70f46f2021-03-03 13:59:46 -08002469 private void sendEraseModemConfig(@NonNull Phone phone) {
2470 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2471 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2472 }
2473
2474 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2475 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2476 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002477 }
2478
Peter Wang44b186e2020-01-13 23:33:09 -08002479 private boolean isImsAvailableOnDevice() {
2480 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2481 if (pm == null) {
2482 // For some reason package manger is not available.. This will fail internally anyway,
2483 // so do not throw error and allow.
2484 return true;
2485 }
2486 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2487 }
2488
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002490 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002491 }
2492
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 if (DBG) log("dial: " + number);
2495 // No permission check needed here: This is just a wrapper around the
2496 // ACTION_DIAL intent, which is available to any app since it puts up
2497 // the UI before it does anything.
2498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 String url = createTelUrl(number);
2502 if (url == null) {
2503 return;
2504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 // PENDING: should we just silently fail if phone is offhook or ringing?
2507 PhoneConstants.State state = mCM.getState(subId);
2508 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2509 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2510 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2511 mApp.startActivity(intent);
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516 }
2517
2518 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002519 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002520 }
2521
Wink Savilleb564aae2014-10-23 10:18:09 -07002522 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 if (DBG) log("call: " + number);
2524
2525 // This is just a wrapper around the ACTION_CALL intent, but we still
2526 // need to do a permission check since we're calling startActivity()
2527 // from the context of the phone app.
2528 enforceCallPermission();
2529
Jordan Liu1617b712019-07-10 15:06:26 -07002530 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 != AppOpsManager.MODE_ALLOWED) {
2532 return;
2533 }
2534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 String url = createTelUrl(number);
2538 if (url == null) {
2539 return;
2540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 boolean isValid = false;
2543 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2544 if (slist != null) {
2545 for (SubscriptionInfo subInfoRecord : slist) {
2546 if (subInfoRecord.getSubscriptionId() == subId) {
2547 isValid = true;
2548 break;
2549 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002550 }
Wink Saville08874612014-08-31 19:19:58 -07002551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552 if (!isValid) {
2553 return;
2554 }
Wink Saville08874612014-08-31 19:19:58 -07002555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2557 intent.putExtra(SUBSCRIPTION_KEY, subId);
2558 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2559 mApp.startActivity(intent);
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
2562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 }
2564
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002566 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002567 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2568 }
2569
Wink Savilleb564aae2014-10-23 10:18:09 -07002570 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002571 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002572 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2573 }
2574
Wink Savilleb564aae2014-10-23 10:18:09 -07002575 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002580 Phone phone = getPhone(subId);
2581 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 checkSimPin.start();
2583 return checkSimPin.unlockSim(null, pin);
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
2586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002594 Phone phone = getPhone(subId);
2595 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 checkSimPuk.start();
2597 return checkSimPuk.unlockSim(puk, pin);
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
2600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 }
2602
2603 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002604 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 * a synchronous one.
2606 */
2607 private static class UnlockSim extends Thread {
2608
2609 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002610 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611
2612 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002613 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2614 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615
2616 // For replies from SimCard interface
2617 private Handler mHandler;
2618
2619 // For async handler to identify request type
2620 private static final int SUPPLY_PIN_COMPLETE = 100;
2621
Michele Berionne5e411512020-11-13 02:36:59 +00002622 UnlockSim(int phoneId, IccCard simCard) {
2623 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 mSimCard = simCard;
2625 }
2626
2627 @Override
2628 public void run() {
2629 Looper.prepare();
2630 synchronized (UnlockSim.this) {
2631 mHandler = new Handler() {
2632 @Override
2633 public void handleMessage(Message msg) {
2634 AsyncResult ar = (AsyncResult) msg.obj;
2635 switch (msg.what) {
2636 case SUPPLY_PIN_COMPLETE:
2637 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2638 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002639 mRetryCount = msg.arg1;
2640 if (ar.exception != null) {
2641 if (ar.exception instanceof CommandException &&
2642 ((CommandException)(ar.exception)).getCommandError()
2643 == CommandException.Error.PASSWORD_INCORRECT) {
2644 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002645 } //When UiccCardApp dispose,handle message and return exception
2646 else if (ar.exception instanceof CommandException &&
2647 ((CommandException) (ar.exception)).getCommandError()
2648 == CommandException.Error.ABORTED) {
2649 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002650 } else {
2651 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2652 }
2653 } else {
2654 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 mDone = true;
2657 UnlockSim.this.notifyAll();
2658 }
2659 break;
2660 }
2661 }
2662 };
2663 UnlockSim.this.notifyAll();
2664 }
2665 Looper.loop();
2666 }
2667
2668 /*
2669 * Use PIN or PUK to unlock SIM card
2670 *
2671 * If PUK is null, unlock SIM card with PIN
2672 *
2673 * If PUK is not null, unlock SIM card with PUK and set PIN code
2674 */
Wink Saville9de0f752013-10-22 19:04:03 -07002675 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676
2677 while (mHandler == null) {
2678 try {
2679 wait();
2680 } catch (InterruptedException e) {
2681 Thread.currentThread().interrupt();
2682 }
2683 }
2684 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2685
2686 if (puk == null) {
2687 mSimCard.supplyPin(pin, callback);
2688 } else {
2689 mSimCard.supplyPuk(puk, pin, callback);
2690 }
2691
2692 while (!mDone) {
2693 try {
2694 Log.d(LOG_TAG, "wait for done");
2695 wait();
2696 } catch (InterruptedException e) {
2697 // Restore the interrupted status
2698 Thread.currentThread().interrupt();
2699 }
2700 }
2701 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002702 int[] resultArray = new int[2];
2703 resultArray[0] = mResult;
2704 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002705
2706 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002707 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002708 }
2709
Wink Saville9de0f752013-10-22 19:04:03 -07002710 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 }
2712 }
2713
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002714 /**
2715 * This method has been removed due to privacy and stability concerns.
2716 */
2717 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002719 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2720 return;
Wink Saville36469e72014-06-11 15:17:00 -07002721 }
2722
Nathan Harold1f889d82020-06-04 17:05:26 -07002723 @Override
2724 public void updateServiceLocationWithPackageName(String callingPackage) {
2725 mApp.getSystemService(AppOpsManager.class)
2726 .checkPackage(Binder.getCallingUid(), callingPackage);
2727
Nathan Haroldf096d982020-11-18 17:18:06 -08002728 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002729 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2730 // Callers targeting S have no business invoking this method.
2731 return;
2732 }
2733
2734 LocationAccessPolicy.LocationPermissionResult locationResult =
2735 LocationAccessPolicy.checkLocationPermission(mApp,
2736 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2737 .setCallingPackage(callingPackage)
2738 .setCallingFeatureId(null)
2739 .setCallingPid(Binder.getCallingPid())
2740 .setCallingUid(Binder.getCallingUid())
2741 .setMethod("updateServiceLocation")
2742 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2743 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2744 .build());
2745 // Apps that lack location permission have no business calling this method;
2746 // however, because no permission was declared in the public API, denials must
2747 // all be "soft".
2748 switch (locationResult) {
2749 case DENIED_HARD: /* fall through */
2750 case DENIED_SOFT:
2751 return;
2752 }
2753
2754 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 final long identity = Binder.clearCallingIdentity();
2756 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002757 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002759 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 }
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
2765
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002766 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002767 @Override
2768 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002769 return isRadioOnWithFeature(callingPackage, null);
2770 }
2771
2772
2773 @Override
2774 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2775 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2776 callingFeatureId);
2777 }
2778
2779 @Deprecated
2780 @Override
2781 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2782 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002783 }
2784
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002786 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2787 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002789 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002790 return false;
2791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792
2793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 return isRadioOnForSubscriber(subId);
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002799 }
2800
2801 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
2806 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
2815 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002816 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
Wink Saville36469e72014-06-11 15:17:00 -07002818
Wink Savilleb564aae2014-10-23 10:18:09 -07002819 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
2826 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Wink Saville36469e72014-06-11 15:17:00 -07002831 }
2832
2833 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002834 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002835 }
2836
Wink Savilleb564aae2014-10-23 10:18:09 -07002837 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 final Phone phone = getPhone(subId);
2843 if (phone == null) {
2844 return false;
2845 }
2846 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2847 toggleRadioOnOffForSubscriber(subId);
2848 }
2849 return true;
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 }
Wink Saville36469e72014-06-11 15:17:00 -07002854
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002855 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002856 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002857 /*
2858 * If any of the Radios are available, it will need to be
2859 * shutdown. So return true if any Radio is available.
2860 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2864 Phone phone = PhoneFactory.getPhone(i);
2865 if (phone != null && phone.isRadioAvailable()) return true;
2866 }
2867 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2868 return false;
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002871 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002872 }
2873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002875 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 enforceModifyPermission();
2877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2881 logv("Shutting down Phone " + i);
2882 shutdownRadioUsingPhoneId(i);
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002886 }
2887 }
2888
2889 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002890 Phone phone = PhoneFactory.getPhone(phoneId);
2891 if (phone != null && phone.isRadioAvailable()) {
2892 phone.shutdownRadio();
2893 }
2894 }
2895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2902 if (defaultPhone != null) {
2903 defaultPhone.setRadioPower(turnOn);
2904 return true;
2905 } else {
2906 loge("There's no default phone.");
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002911 }
Wink Saville36469e72014-06-11 15:17:00 -07002912 }
2913
Wink Savilleb564aae2014-10-23 10:18:09 -07002914 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 final Phone phone = getPhone(subId);
2920 if (phone != null) {
2921 phone.setRadioPower(turnOn);
2922 return true;
2923 } else {
2924 return false;
2925 }
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002931 /**
2932 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2933 * no reason to power it off. When any of the voters want to power it off, it will be turned
2934 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2935 * powering it off, and these radio off votes will be cleared.
2936 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2937 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2938 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2939 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2940 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2941 * check its vote.
2942 *
2943 * @param subId The subscription ID.
2944 * @param reason The reason for powering off radio.
2945 * @return true on success and false on failure.
2946 */
2947 public boolean requestRadioPowerOffForReason(int subId,
2948 @TelephonyManager.RadioPowerReason int reason) {
2949 enforceModifyPermission();
2950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 final Phone phone = getPhone(subId);
2954 if (phone != null) {
2955 phone.setRadioPowerForReason(false, reason);
2956 return true;
2957 } else {
2958 return false;
2959 }
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
2963 }
2964
2965 /**
2966 * Remove the vote on powering off the radio for a reason, as requested by
2967 * {@link requestRadioPowerOffForReason}.
2968 *
2969 * @param subId The subscription ID.
2970 * @param reason The reason for powering off radio.
2971 * @return true on success and false on failure.
2972 */
2973 public boolean clearRadioPowerOffForReason(int subId,
2974 @TelephonyManager.RadioPowerReason int reason) {
2975 enforceModifyPermission();
2976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 final Phone phone = getPhone(subId);
2980 if (phone != null) {
2981 phone.setRadioPowerForReason(true, reason);
2982 return true;
2983 } else {
2984 return false;
2985 }
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 /**
2992 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2993 *
2994 * @param subId The subscription ID.
2995 * @param callingPackage The package making the call.
2996 * @param callingFeatureId The feature in the package.
2997 * @return List of reasons for powering off radio.
2998 */
2999 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3000 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3001
3002 final long identity = Binder.clearCallingIdentity();
3003 List result = new ArrayList();
3004 try {
3005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3006 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3007 return result;
3008 }
3009
3010 final Phone phone = getPhone(subId);
3011 if (phone != null) {
3012 result.addAll(phone.getRadioPowerOffReasons());
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
3017 return result;
3018 }
3019
Wink Saville36469e72014-06-11 15:17:00 -07003020 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003022 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
Jack Yu285100e2022-12-02 22:48:35 -08003027 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 final Phone phone = getPhone(subId);
3029 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003030 phone.getDataSettingsManager().setDataEnabled(
3031 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032 return true;
3033 } else {
3034 return false;
3035 }
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 }
3040
Wink Saville36469e72014-06-11 15:17:00 -07003041 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003042 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003043 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
Jack Yu285100e2022-12-02 22:48:35 -08003048 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final Phone phone = getPhone(subId);
3050 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003051 phone.getDataSettingsManager().setDataEnabled(
3052 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 return true;
3054 } else {
3055 return false;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
Sanket Padawe356d7632015-06-22 14:03:32 -07003062 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003063 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 final Phone phone = getPhone(subId);
3067 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003068 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 } else {
3070 return false;
3071 }
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
3076
3077 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003078 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003079 }
3080
pkanwarae03a6b2016-11-06 20:37:09 -08003081 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 enforceCallPermission();
3083
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3087 return;
3088 }
3089 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3090 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
pkanwar32d516d2016-10-14 19:37:38 -07003094 };
3095
Wink Savilleb564aae2014-10-23 10:18:09 -07003096 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3102 return false;
3103 }
3104 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003110 /**
3111 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3112 * tag on getCallState Binder call.
3113 */
3114 @Deprecated
3115 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003117 if (CompatChanges.isChangeEnabled(
3118 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3119 Binder.getCallingUid())) {
3120 // Do not allow this API to be called on API version 31+, it should only be
3121 // called on old apps using this Binder call directly.
3122 throw new SecurityException("This method can only be used for applications "
3123 + "targeting API version 30 or less.");
3124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003125 final long identity = Binder.clearCallingIdentity();
3126 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003127 Phone phone = getPhone(getDefaultSubscription());
3128 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3129 PhoneConstantConversions.convertCallState(phone.getState());
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
3135 @Override
3136 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3137 if (CompatChanges.isChangeEnabled(
3138 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3139 Binder.getCallingUid())) {
3140 // Check READ_PHONE_STATE for API version 31+
3141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3142 featureId, "getCallStateForSubscription")) {
3143 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3144 + "targeting API level 31+.");
3145 }
3146 }
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3151 PhoneConstantConversions.convertCallState(phone.getState());
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003155 }
3156
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003158 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003159 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003160 }
3161
3162 @Override
3163 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 final long identity = Binder.clearCallingIdentity();
3165 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003166 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003168 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 } else {
3170 return PhoneConstantConversions.convertDataState(
3171 PhoneConstants.DataState.DISCONNECTED);
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 }
3177
Sanket Padawe356d7632015-06-22 14:03:32 -07003178 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003179 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003180 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003181 }
3182
3183 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003184 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003187 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003189 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 } else {
3191 return TelephonyManager.DATA_ACTIVITY_NONE;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
3198 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003199 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003200 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003201 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003202
3203 LocationAccessPolicy.LocationPermissionResult locationResult =
3204 LocationAccessPolicy.checkLocationPermission(mApp,
3205 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3206 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003207 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003208 .setCallingPid(Binder.getCallingPid())
3209 .setCallingUid(Binder.getCallingUid())
3210 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003211 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003212 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3213 .build());
3214 switch (locationResult) {
3215 case DENIED_HARD:
3216 throw new SecurityException("Not allowed to access cell location");
3217 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003218 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3219 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 }
3221
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003226 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003227 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Svetoslav64fad262015-04-14 14:35:21 -07003231 }
3232
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003234 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003235 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3236 // registered cell info, so return a NULL country instead.
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003239 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3240 // Get default phone in this case.
3241 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3242 }
Jack Yu285100e2022-12-02 22:48:35 -08003243 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003245 if (phone == null) return "";
3246 ServiceStateTracker sst = phone.getServiceStateTracker();
3247 if (sst == null) return "";
3248 LocaleTracker lt = sst.getLocaleTracker();
3249 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003250 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003254 }
3255
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003256 /**
3257 * This method was removed due to potential issues caused by performing partial
3258 * updates of service state, and lack of a credible use case.
3259 *
3260 * This has the ability to break the telephony implementation by disabling notification of
3261 * changes in device connectivity. DO NOT USE THIS!
3262 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003263 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 public void enableLocationUpdates() {
3265 mApp.enforceCallingOrSelfPermission(
3266 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003269 /**
3270 * This method was removed due to potential issues caused by performing partial
3271 * updates of service state, and lack of a credible use case.
3272 *
3273 * This has the ability to break the telephony implementation by disabling notification of
3274 * changes in device connectivity. DO NOT USE THIS!
3275 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 @Override
3277 public void disableLocationUpdates() {
3278 mApp.enforceCallingOrSelfPermission(
3279 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 @Override
3283 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003284 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3285 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003286 try {
3287 mApp.getSystemService(AppOpsManager.class)
3288 .checkPackage(Binder.getCallingUid(), callingPackage);
3289 } catch (SecurityException e) {
3290 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3291 throw e;
3292 }
3293
Nathan Haroldf096d982020-11-18 17:18:06 -08003294 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003295 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3296 throw new SecurityException(
3297 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3298 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003299
Jordan Liu1617b712019-07-10 15:06:26 -07003300 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3302 return null;
3303 }
Svetoslav64fad262015-04-14 14:35:21 -07003304
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003305 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003307 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003308 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003309
Nathan Haroldf180aac2018-06-01 18:43:55 -07003310 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3311 for (CellInfo ci : info) {
3312 if (ci instanceof CellInfoGsm) {
3313 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3314 } else if (ci instanceof CellInfoWcdma) {
3315 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003318 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003319 }
3320
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003321 private List<CellInfo> getCachedCellInfo() {
3322 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3323 for (Phone phone : PhoneFactory.getPhones()) {
3324 List<CellInfo> info = phone.getAllCellInfo();
3325 if (info != null) cellInfos.addAll(info);
3326 }
3327 return cellInfos;
3328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003329
3330 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003331 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003333 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003334
3335 LocationAccessPolicy.LocationPermissionResult locationResult =
3336 LocationAccessPolicy.checkLocationPermission(mApp,
3337 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3338 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003339 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003340 .setCallingPid(Binder.getCallingPid())
3341 .setCallingUid(Binder.getCallingUid())
3342 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003343 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003344 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3345 .build());
3346 switch (locationResult) {
3347 case DENIED_HARD:
3348 throw new SecurityException("Not allowed to access cell info");
3349 case DENIED_SOFT:
3350 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 }
3352
Nathan Haroldf096d982020-11-18 17:18:06 -08003353 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003354 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3355 return getCachedCellInfo();
3356 }
3357
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003358 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3363 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003364 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003365 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003366 if (info != null) cellInfos.addAll(info);
3367 }
3368 return cellInfos;
3369 } finally {
3370 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003371 }
3372 }
3373
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003374 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003375 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3376 String callingFeatureId) {
3377 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3378 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003379 }
3380
3381 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003382 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3383 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003384 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003385 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003386 }
3387
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003388 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3389 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003391 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003392
3393 LocationAccessPolicy.LocationPermissionResult locationResult =
3394 LocationAccessPolicy.checkLocationPermission(mApp,
3395 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3396 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003397 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003398 .setCallingPid(Binder.getCallingPid())
3399 .setCallingUid(Binder.getCallingUid())
3400 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003401 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3402 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003403 .build());
3404 switch (locationResult) {
3405 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003406 if (TelephonyPermissions
3407 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003408 // Safetynet logging for b/154934934
3409 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3410 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003411 throw new SecurityException("Not allowed to access cell info");
3412 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003413 if (TelephonyPermissions
3414 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003415 // Safetynet logging for b/154934934
3416 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3417 }
Nathan Harold5320c422019-05-09 10:26:08 -07003418 try {
3419 cb.onCellInfo(new ArrayList<CellInfo>());
3420 } catch (RemoteException re) {
3421 // Drop without consequences
3422 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003423 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003424 }
3425
Nathan Harolda939a962019-05-09 10:13:47 -07003426
3427 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003428 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3429
3430 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3431 }
3432
3433 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003434 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003435 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003436 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003440 Phone phone = getPhone(subId);
3441 if (phone == null) {
3442 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3443 } else {
3444 phone.setCellInfoListRate(rateInMillis, workSource);
3445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 }
3450
Shishir Agrawala9f32182016-04-12 12:00:16 -07003451 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003452 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003453 Phone phone = PhoneFactory.getPhone(slotIndex);
3454 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003455 return null;
3456 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003457 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003458 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003459 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003460 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003461 return null;
3462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 return phone.getImei();
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003470 }
3471
3472 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003473 public String getTypeAllocationCodeForSlot(int slotIndex) {
3474 Phone phone = PhoneFactory.getPhone(slotIndex);
3475 String tac = null;
3476 if (phone != null) {
3477 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003478 try {
3479 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3480 } catch (IndexOutOfBoundsException e) {
3481 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3482 return null;
3483 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003484 }
3485 return tac;
3486 }
3487
3488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003490 try {
3491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3492 } catch (SecurityException se) {
3493 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3494 throw new SecurityException("Package " + callingPackage + " does not belong to "
3495 + Binder.getCallingUid());
3496 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003497 Phone phone = PhoneFactory.getPhone(slotIndex);
3498 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003499 return null;
3500 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003501
Jeff Davidson913390f2018-02-23 17:11:49 -08003502 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003503 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003504 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003505 return null;
3506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 return phone.getMeid();
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
Jack Yu2af8d712017-03-15 17:14:14 -07003514 }
3515
3516 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003517 public String getManufacturerCodeForSlot(int slotIndex) {
3518 Phone phone = PhoneFactory.getPhone(slotIndex);
3519 String manufacturerCode = null;
3520 if (phone != null) {
3521 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003522 try {
3523 manufacturerCode =
3524 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3525 } catch (IndexOutOfBoundsException e) {
3526 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3527 return null;
3528 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003529 }
3530 return manufacturerCode;
3531 }
3532
3533 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003534 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3535 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003536 Phone phone = PhoneFactory.getPhone(slotIndex);
3537 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003538 return null;
3539 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003540 int subId = phone.getSubId();
3541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 mApp, subId, callingPackage, callingFeatureId,
3543 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003544 return null;
3545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 return phone.getDeviceSvn();
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003553 }
3554
fionaxu43304da2017-11-27 22:51:16 -08003555 @Override
3556 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = getPhone(subId);
3560 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
fionaxu43304da2017-11-27 22:51:16 -08003564 }
3565
3566 @Override
3567 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 return phone == null ? null : phone.getCarrierName();
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
fionaxu43304da2017-11-27 22:51:16 -08003575 }
3576
calvinpanffe225e2018-11-01 19:43:06 +08003577 @Override
chen xu0026ca62019-03-06 15:28:50 -08003578 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003583 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
3587 }
3588
3589 @Override
chen xu0026ca62019-03-06 15:28:50 -08003590 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003594 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
chen xu651eec72018-11-11 19:03:44 -08003600 @Override
chen xu864e11c2018-12-06 22:10:03 -08003601 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3602 if (!isSubscriptionMccMnc) {
3603 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3604 }
chen xu651eec72018-11-11 19:03:44 -08003605 final Phone phone = PhoneFactory.getPhone(slotIndex);
3606 if (phone == null) {
3607 return TelephonyManager.UNKNOWN_CARRIER_ID;
3608 }
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
3615 }
3616
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003617 //
3618 // Internal helper methods.
3619 //
3620
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003621 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003622 * Make sure the caller is the calling package itself
3623 *
3624 * @throws SecurityException if the caller is not the calling package
3625 */
3626 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3627 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003628 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3629 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003630 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003631 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003632 } catch (PackageManager.NameNotFoundException e) {
3633 // packageUid is -1
3634 }
3635 if (packageUid != callingUid) {
3636 throw new SecurityException(message + ": Package " + callingPackage
3637 + " does not belong to " + callingUid);
3638 }
3639 }
3640
3641 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3643 *
3644 * @throws SecurityException if the caller does not have the required permission
3645 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003646 @VisibleForTesting
3647 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3649 }
3650
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003651 /**
3652 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3653 *
3654 * @throws SecurityException if the caller does not have the required permission
3655 */
3656 @VisibleForTesting
3657 public void enforceReadPermission() {
3658 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
3659 }
3660
Shuo Qian3b6ee772019-11-13 17:43:31 -08003661 private void enforceActiveEmergencySessionPermission() {
3662 mApp.enforceCallingOrSelfPermission(
3663 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3664 }
3665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 /**
3667 * Make sure the caller has the CALL_PHONE permission.
3668 *
3669 * @throws SecurityException if the caller does not have the required permission
3670 */
3671 private void enforceCallPermission() {
3672 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3673 }
3674
paulhu5a773602019-08-23 19:17:33 +08003675 private void enforceSettingsPermission() {
3676 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003677 }
3678
Michele Berionne5e411512020-11-13 02:36:59 +00003679 private void enforceRebootPermission() {
3680 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3681 }
3682
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003683 private String createTelUrl(String number) {
3684 if (TextUtils.isEmpty(number)) {
3685 return null;
3686 }
3687
Jake Hambye994d462014-02-03 13:10:13 -08003688 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003689 }
3690
Ihab Awadf9e92732013-12-05 18:02:52 -08003691 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003692 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3693 }
3694
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003695 private static void logv(String msg) {
3696 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3697 }
3698
Ihab Awadf9e92732013-12-05 18:02:52 -08003699 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003700 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3701 }
3702
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003703 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003704 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003705 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003706 }
3707
Sanket Padawe356d7632015-06-22 14:03:32 -07003708 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003709 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 final Phone phone = PhoneFactory.getPhone(slotIndex);
3713 if (phone == null) {
3714 return PhoneConstants.PHONE_TYPE_NONE;
3715 } else {
3716 return phone.getPhoneType();
3717 }
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 }
3722
3723 /**
3724 * Returns the CDMA ERI icon index to display
3725 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003726 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003727 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3728 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3729 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003730 }
3731
Sanket Padawe356d7632015-06-22 14:03:32 -07003732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003733 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3734 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003736 mApp, subId, callingPackage, callingFeatureId,
3737 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003738 return -1;
3739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740
3741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 final Phone phone = getPhone(subId);
3744 if (phone != null) {
3745 return phone.getCdmaEriIconIndex();
3746 } else {
3747 return -1;
3748 }
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003752 }
3753
3754 /**
3755 * Returns the CDMA ERI icon mode,
3756 * 0 - ON
3757 * 1 - FLASHING
3758 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3761 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3762 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003763 }
3764
Sanket Padawe356d7632015-06-22 14:03:32 -07003765 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003766 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3767 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003769 mApp, subId, callingPackage, callingFeatureId,
3770 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003771 return -1;
3772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773
3774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 final Phone phone = getPhone(subId);
3777 if (phone != null) {
3778 return phone.getCdmaEriIconMode();
3779 } else {
3780 return -1;
3781 }
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003785 }
3786
3787 /**
3788 * Returns the CDMA ERI text,
3789 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003791 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3792 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3793 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003794 }
3795
Sanket Padawe356d7632015-06-22 14:03:32 -07003796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003797 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3798 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003800 mApp, subId, callingPackage, callingFeatureId,
3801 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003802 return null;
3803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 final Phone phone = getPhone(subId);
3808 if (phone != null) {
3809 return phone.getCdmaEriText();
3810 } else {
3811 return null;
3812 }
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
3818 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003819 * Returns the CDMA MDN.
3820 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003821 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003822 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3824 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 return phone.getLine1Number();
3831 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003832 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 return null;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003837 }
3838 }
3839
3840 /**
3841 * Returns the CDMA MIN.
3842 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003844 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 final Phone phone = getPhone(subId);
3851 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3852 return phone.getCdmaMin();
3853 } else {
3854 return null;
3855 }
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003858 }
3859 }
3860
Hall Liud892bec2018-11-30 14:51:45 -08003861 @Override
3862 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3863 INumberVerificationCallback callback, String callingPackage) {
3864 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3865 != PERMISSION_GRANTED) {
3866 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3867 }
3868 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3869
3870 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3871 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003872 throw new SecurityException("Calling package must be configured in the device config: "
3873 + "calling package: " + callingPackage
3874 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003875 }
3876
3877 if (range == null) {
3878 throw new NullPointerException("Range must be non-null");
3879 }
3880
3881 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003882 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003883
3884 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3885 }
3886
Junda Liuca05d5d2014-08-14 22:36:34 -07003887 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003888 * Returns true if CDMA provisioning needs to run.
3889 */
3890 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003893 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
3898
3899 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003900 * Sets the voice mail number of a given subId.
3901 */
3902 @Override
3903 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003904 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3905 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3910 new Pair<String, String>(alphaTag, number), new Integer(subId));
3911 return success;
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003915 }
3916
Ta-wei Yen87c49842016-05-13 21:19:52 -07003917 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003918 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003920 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3921 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003922 if (!TextUtils.equals(callingPackage, systemDialer)) {
3923 throw new SecurityException("caller must be system dialer");
3924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3929 if (phoneAccountHandle == null) {
3930 return null;
3931 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003932 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003935 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003936 }
3937
3938 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003939 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3940 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003943 mApp, subId, callingPackage, callingFeatureId,
3944 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003945 return null;
3946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003948 final long identity = Binder.clearCallingIdentity();
3949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003950 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003951 } finally {
3952 Binder.restoreCallingIdentity(identity);
3953 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003954 }
3955
3956 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003957 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3958 VisualVoicemailSmsFilterSettings settings) {
3959 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003964 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003968 }
3969
3970 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003971 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003981 }
3982
3983 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003984 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3985 String callingPackage, int subId) {
3986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003995 }
3996
3997 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003998 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000
4001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004008 }
4009
4010 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004011 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4012 String callingAttributionTag, int subId, String number, int port, String text,
4013 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004015 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004016 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004017 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004018 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4019 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004020 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004021
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004022 /**
fionaxu0152e512016-11-14 13:36:14 -08004023 * Sets the voice activation state of a given subId.
4024 */
4025 @Override
4026 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4028 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 final Phone phone = getPhone(subId);
4033 if (phone != null) {
4034 phone.setVoiceActivationState(activationState);
4035 } else {
4036 loge("setVoiceActivationState fails with invalid subId: " + subId);
4037 }
4038 } finally {
4039 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004040 }
4041 }
4042
4043 /**
4044 * Sets the data activation state of a given subId.
4045 */
4046 @Override
4047 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4049 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 final Phone phone = getPhone(subId);
4054 if (phone != null) {
4055 phone.setDataActivationState(activationState);
4056 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004057 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 }
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004061 }
4062 }
4063
4064 /**
4065 * Returns the voice activation state of a given subId.
4066 */
4067 @Override
4068 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
fionaxu0152e512016-11-14 13:36:14 -08004071 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 if (phone != null) {
4075 return phone.getVoiceActivationState();
4076 } else {
4077 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4078 }
4079 } finally {
4080 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004081 }
4082 }
4083
4084 /**
4085 * Returns the data activation state of a given subId.
4086 */
4087 @Override
4088 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090
fionaxu0152e512016-11-14 13:36:14 -08004091 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 if (phone != null) {
4095 return phone.getDataActivationState();
4096 } else {
4097 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004101 }
4102 }
4103
4104 /**
Wink Saville36469e72014-06-11 15:17:00 -07004105 * Returns the unread count of voicemails for a subId
4106 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004108 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4109 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004111 mApp, subId, callingPackage, callingFeatureId,
4112 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004113 return 0;
4114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 final Phone phone = getPhone(subId);
4118 if (phone != null) {
4119 return phone.getVoiceMessageCount();
4120 } else {
4121 return 0;
4122 }
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004126 }
4127
4128 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004129 * returns true, if the device is in a state where both voice and data
4130 * are supported simultaneously. This can change based on location or network condition.
4131 */
4132 @Override
4133 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 final Phone phone = getPhone(subId);
4137 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004141 }
4142
4143 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004144 * Send the dialer code if called from the current default dialer or the caller has
4145 * carrier privilege.
4146 * @param inputCode The dialer code to send
4147 */
4148 @Override
4149 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004151 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004152 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4153 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004154 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004155 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004161 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
fionaxu235cc5e2017-03-06 22:25:57 -08004165 }
4166
Pengquan Menga1bb6272018-09-06 09:59:22 -07004167 @Override
4168 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004169 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004170 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004171 mApp, subId, "getNetworkSelectionMode");
4172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 if (!isActiveSubscription(subId)) {
4175 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4176 }
4177 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004180 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004181 }
4182
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004184 public boolean isInEmergencySmsMode() {
4185 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 for (Phone phone : PhoneFactory.getPhones()) {
4189 if (phone.isInEmergencySmsMode()) {
4190 return true;
4191 }
4192 }
4193 } finally {
4194 Binder.restoreCallingIdentity(identity);
4195 }
4196 return false;
4197 }
4198
shilu366312e2019-12-17 09:28:10 -08004199 /**
4200 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4201 * @param subId The subscription to use to check the configuration.
4202 * @param c The callback that will be used to send the result.
4203 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004204 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004205 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4206 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004207 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004208 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004209
4210 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4211 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4212 "IMS not available on device.");
4213 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long token = Binder.clearCallingIdentity();
4215 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004216 int slotId = getSlotIndexOrException(subId);
4217 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004218
4219 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4220 if (controller != null) {
4221 ImsManager imsManager = controller.getImsManager(subId);
4222 if (imsManager != null) {
4223 imsManager.addRegistrationCallbackForSubscription(c, subId);
4224 } else {
4225 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4226 }
4227 } else {
4228 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4229 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004230 } catch (ImsException e) {
4231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 } finally {
4233 Binder.restoreCallingIdentity(token);
4234 }
4235 }
4236
shilu366312e2019-12-17 09:28:10 -08004237 /**
4238 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4239 * @param subId The subscription to use to check the configuration.
4240 * @param c The callback that will be used to send the result.
4241 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004243 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004244 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004245 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004246 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4247 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4248 }
Meng Wangafbc5852019-09-19 17:37:13 -07004249 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004250
Meng Wangafbc5852019-09-19 17:37:13 -07004251 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004252 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4253 if (controller != null) {
4254 ImsManager imsManager = controller.getImsManager(subId);
4255 if (imsManager != null) {
4256 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4257 } else {
4258 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4259 + "is inactive, ignoring unregister.");
4260 // If the ImsManager is not valid, just return, since the callback
4261 // will already have been removed internally.
4262 }
4263 }
Meng Wangafbc5852019-09-19 17:37:13 -07004264 } finally {
4265 Binder.restoreCallingIdentity(token);
4266 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 }
4268
Brad Ebingera34a6c22019-10-22 17:36:18 -07004269 /**
4270 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4271 */
4272 @Override
4273 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4274 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4275 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4276 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4277 "IMS not available on device.");
4278 }
4279 final long token = Binder.clearCallingIdentity();
4280 try {
4281 Phone phone = getPhone(subId);
4282 if (phone == null) {
4283 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4284 + subId + "'");
4285 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4286 }
4287 phone.getImsRegistrationState(regState -> {
4288 try {
4289 consumer.accept((regState == null)
4290 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4291 } catch (RemoteException e) {
4292 // Ignore if the remote process is no longer available to call back.
4293 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4294 }
4295 });
4296 } finally {
4297 Binder.restoreCallingIdentity(token);
4298 }
4299 }
4300
4301 /**
4302 * Get the transport type for the IMS service registration state.
4303 */
4304 @Override
4305 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004306 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004307 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004308 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4309 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4310 "IMS not available on device.");
4311 }
4312 final long token = Binder.clearCallingIdentity();
4313 try {
4314 Phone phone = getPhone(subId);
4315 if (phone == null) {
4316 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4317 + subId + "'");
4318 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4319 }
4320 phone.getImsRegistrationTech(regTech -> {
4321 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4322 int regTechConverted = (regTech == null)
4323 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4324 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4325 regTechConverted);
4326 try {
4327 consumer.accept(regTechConverted);
4328 } catch (RemoteException e) {
4329 // Ignore if the remote process is no longer available to call back.
4330 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4331 }
4332 });
4333 } finally {
4334 Binder.restoreCallingIdentity(token);
4335 }
4336 }
4337
shilu366312e2019-12-17 09:28:10 -08004338 /**
4339 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4340 * @param subId The subscription to use to check the configuration.
4341 * @param c The callback that will be used to send the result.
4342 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004343 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004344 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4345 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004346 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004347 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004348 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4349 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4350 "IMS not available on device.");
4351 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 final long token = Binder.clearCallingIdentity();
4353 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004354 int slotId = getSlotIndexOrException(subId);
4355 verifyImsMmTelConfiguredOrThrow(slotId);
4356 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 } catch (ImsException e) {
4358 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 } finally {
4360 Binder.restoreCallingIdentity(token);
4361 }
4362 }
4363
shilu366312e2019-12-17 09:28:10 -08004364 /**
4365 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4366 * @param subId The subscription to use to check the configuration.
4367 * @param c The callback that will be used to send the result.
4368 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004370 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004371 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004372 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4374 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4375 }
Meng Wangafbc5852019-09-19 17:37:13 -07004376
4377 final long token = Binder.clearCallingIdentity();
4378 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004379 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004380 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004381 } catch (ImsException e) {
4382 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4383 + "is inactive, ignoring unregister.");
4384 // If the subscription is no longer active, just return, since the callback
4385 // will already have been removed internally.
4386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 }
4390
4391 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004392 public boolean isCapable(int subId, int capability, int regTech) {
4393 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 final long token = Binder.clearCallingIdentity();
4395 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004396 int slotId = getSlotIndexOrException(subId);
4397 verifyImsMmTelConfiguredOrThrow(slotId);
4398 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4399 } catch (com.android.ims.ImsException e) {
4400 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4401 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004402 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004403 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4404 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004405 } finally {
4406 Binder.restoreCallingIdentity(token);
4407 }
4408 }
4409
4410 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004411 public boolean isAvailable(int subId, int capability, int regTech) {
4412 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004413 final long token = Binder.clearCallingIdentity();
4414 try {
4415 Phone phone = getPhone(subId);
4416 if (phone == null) return false;
4417 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004418 } catch (com.android.ims.ImsException e) {
4419 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4420 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 } finally {
4422 Binder.restoreCallingIdentity(token);
4423 }
4424 }
4425
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004426 /**
4427 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4428 * subscription.
4429 * @param subId The subscription to use to check the configuration.
4430 * @param callback The callback that will be used to send the result.
4431 * @param capability The MmTelFeature capability that will be used to send the result.
4432 * @param transportType The transport type of the MmTelFeature capability.
4433 */
4434 @Override
4435 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4436 int transportType) {
4437 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004438 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4439 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4440 "IMS not available on device.");
4441 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004442 final long token = Binder.clearCallingIdentity();
4443 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004444 int slotId = getSlotIndex(subId);
4445 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4446 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4447 + subId + "'");
4448 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4449 }
4450 verifyImsMmTelConfiguredOrThrow(slotId);
4451 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4452 transportType, aBoolean -> {
4453 try {
4454 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4455 } catch (RemoteException e) {
4456 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4457 + "running. Ignore");
4458 }
4459 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 } catch (ImsException e) {
4461 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004462 } finally {
4463 Binder.restoreCallingIdentity(token);
4464 }
4465 }
4466
shilu366312e2019-12-17 09:28:10 -08004467 /**
4468 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4469 * @param subId The subscription to use to check the configuration.
4470 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 @Override
4472 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004473 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004474 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004475
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 final long token = Binder.clearCallingIdentity();
4477 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004479 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004481 } catch (ImsException e) {
4482 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 } finally {
4484 Binder.restoreCallingIdentity(token);
4485 }
4486 }
4487
4488 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004489 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004491 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 final long identity = Binder.clearCallingIdentity();
4493 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004495 // This setting doesn't require an active ImsService connection, so do not verify. The
4496 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
shilu366312e2019-12-17 09:28:10 -08004505 /**
4506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4507 * @param subId The subscription to use to check the configuration.
4508 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004510 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004511 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004512 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004516 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004518 } catch (ImsException e) {
4519 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
4525 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004526 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004528 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004531 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004532 // This setting doesn't require an active ImsService connection, so do not verify. The
4533 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (ImsException e) {
4536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 }
4541
shilu366312e2019-12-17 09:28:10 -08004542 /**
4543 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4544 * @param subId The subscription to use to check the configuration.
4545 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 @Override
4547 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004548 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004549 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 final long identity = Binder.clearCallingIdentity();
4551 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004552 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004553 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004554 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
4556 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
4562 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004563 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004565 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004566 final long identity = Binder.clearCallingIdentity();
4567 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004568 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004569 // This setting doesn't require an active ImsService connection, so do not verify. The
4570 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004571 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004572 } catch (ImsException e) {
4573 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
4577 }
4578
shilu366312e2019-12-17 09:28:10 -08004579 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004580 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4581 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4582 * @param subId The subscription to use to check the configuration.
4583 */
4584 @Override
4585 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004586 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004587 mApp, subId, "isCrossSimCallingEnabledByUser");
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004590 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004591 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004592 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004593 } catch (ImsException e) {
4594 throw new ServiceSpecificException(e.getCode());
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
4598 }
4599
4600 /**
4601 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4602 * Requires MODIFY_PHONE_STATE permission.
4603 * @param subId The subscription to use to check the configuration.
4604 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4605 * false otherwise
4606 */
4607 @Override
4608 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4610 "setCrossSimCallingEnabled");
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004614 // This setting doesn't require an active ImsService connection, so do not verify. The
4615 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004617 } catch (ImsException e) {
4618 throw new ServiceSpecificException(e.getCode());
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
4622 }
4623
4624 /**
shilu366312e2019-12-17 09:28:10 -08004625 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4626 * @param subId The subscription to use to check the configuration.
4627 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004629
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004631 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004632 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 final long identity = Binder.clearCallingIdentity();
4634 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004636 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (ImsException e) {
4639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
4645 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004646 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004648 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 final long identity = Binder.clearCallingIdentity();
4650 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004651 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004652 // This setting doesn't require an active ImsService connection, so do not verify. The
4653 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004655 } catch (ImsException e) {
4656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 } finally {
4658 Binder.restoreCallingIdentity(identity);
4659 }
4660 }
4661
4662 @Override
4663 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4665 "setVoWiFiNonPersistent");
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004669 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004671 } catch (ImsException e) {
4672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
4676 }
4677
shilu366312e2019-12-17 09:28:10 -08004678 /**
4679 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4680 * @param subId The subscription to use to check the configuration.
4681 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004682 @Override
4683 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004684 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004685 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 final long identity = Binder.clearCallingIdentity();
4687 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004689 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004691 } catch (ImsException e) {
4692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
4696 }
4697
4698 @Override
4699 public void setVoWiFiModeSetting(int subId, int mode) {
4700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4701 "setVoWiFiModeSetting");
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004704 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004705 // This setting doesn't require an active ImsService connection, so do not verify. The
4706 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004707 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004708 } catch (ImsException e) {
4709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
4713 }
4714
4715 @Override
4716 public int getVoWiFiRoamingModeSetting(int subId) {
4717 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4718 final long identity = Binder.clearCallingIdentity();
4719 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004720 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004721 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
4730 @Override
4731 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4733 "setVoWiFiRoamingModeSetting");
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004736 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004737 // This setting doesn't require an active ImsService connection, so do not verify. The
4738 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004739 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004740 } catch (ImsException e) {
4741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
4745 }
4746
4747 @Override
4748 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4750 "setRttCapabilityEnabled");
4751 final long identity = Binder.clearCallingIdentity();
4752 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004753 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004754 // This setting doesn't require an active ImsService connection, so do not verify. The
4755 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004756 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004757 } catch (ImsException e) {
4758 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
shilu366312e2019-12-17 09:28:10 -08004764 /**
4765 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4766 * @param subId The subscription to use to check the configuration.
4767 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 @Override
4769 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004770 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004771 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004772 final long identity = Binder.clearCallingIdentity();
4773 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004774 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004775 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004776 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004777 } catch (ImsException e) {
4778 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004784 @Override
4785 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4786 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004787
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004788 final long identity = Binder.clearCallingIdentity();
4789 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004790 if (!isImsAvailableOnDevice()) {
4791 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4792 "IMS not available on device.");
4793 }
4794 int slotId = getSlotIndexOrException(subId);
4795 verifyImsMmTelConfiguredOrThrow(slotId);
4796 ImsManager.getInstance(mApp, slotId)
4797 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004798 } catch (ImsException e) {
4799 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004800 } finally {
4801 Binder.restoreCallingIdentity(identity);
4802 }
4803 }
4804
4805 @Override
4806 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4807 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004808
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004809 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4811 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4812 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004813 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004814 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004815 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004816 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004817 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4818 + "is inactive, ignoring unregister.");
4819 // If the subscription is no longer active, just return, since the callback will already
4820 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
4824 }
4825
joonhunshincffb7fc2021-11-28 07:32:01 +00004826 @Override
4827 public void registerFeatureProvisioningChangedCallback(int subId,
4828 IFeatureProvisioningCallback callback) {
4829 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4830 mApp, subId, "registerFeatureProvisioningChangedCallback");
4831
4832 final long identity = Binder.clearCallingIdentity();
4833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4834 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4835 }
4836
joonhunshin91bc1952022-04-29 08:47:15 +00004837 try {
4838 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4839 if (controller == null) {
4840 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4841 "Device does not support IMS");
4842 }
4843 controller.addFeatureProvisioningChangedCallback(subId, callback);
4844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004847 }
4848
4849 @Override
4850 public void unregisterFeatureProvisioningChangedCallback(int subId,
4851 IFeatureProvisioningCallback callback) {
4852 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4853 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4854
4855 final long identity = Binder.clearCallingIdentity();
4856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4858 }
4859
joonhunshin91bc1952022-04-29 08:47:15 +00004860 try {
4861 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4862 if (controller == null) {
4863 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4864 return;
4865 }
4866 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004870 }
allenwtsu99c623b2020-01-03 18:24:23 +08004871
4872 private void checkModifyPhoneStatePermission(int subId, String message) {
4873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4874 message);
4875 }
4876
allenwtsu99c623b2020-01-03 18:24:23 +08004877 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004878 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004879 boolean isProvisioned) {
4880 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4881
4882 final long identity = Binder.clearCallingIdentity();
4883 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004884 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4885 if (controller == null) {
4886 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4887 return;
4888 }
4889 controller.setRcsProvisioningStatusForCapability(
4890 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004891 } finally {
4892 Binder.restoreCallingIdentity(identity);
4893 }
allenwtsu99c623b2020-01-03 18:24:23 +08004894 }
4895
4896
4897 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004898 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4899 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4900 mApp, subId, "getRcsProvisioningStatusForCapability");
4901
allenwtsu99c623b2020-01-03 18:24:23 +08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004904 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4905 if (controller == null) {
4906 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4907
4908 // device does not support IMS, this method will return true always.
4909 return true;
4910 }
4911 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
4915 }
4916
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004917 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4919 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004920 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004921
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004924 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4925 if (controller == null) {
4926 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4927 return;
4928 }
4929 controller.setImsProvisioningStatusForCapability(
4930 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
4934 }
4935
4936 @Override
4937 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004938 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4939 mApp, subId, "getProvisioningStatusForCapability");
4940
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004943 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4944 if (controller == null) {
4945 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946
joonhunshin91bc1952022-04-29 08:47:15 +00004947 // device does not support IMS, this method will return true always.
4948 return true;
4949 }
4950 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
4954 }
4955
4956 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004957 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4958 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4959 mApp, subId, "isProvisioningRequiredForCapability");
4960
4961 final long identity = Binder.clearCallingIdentity();
4962 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004963 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4964 if (controller == null) {
4965 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4966
4967 // device does not support IMS, this method will return false
4968 return false;
4969 }
4970 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 }
4975
4976 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004977 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4979 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980
joonhunshincffb7fc2021-11-28 07:32:01 +00004981 final long identity = Binder.clearCallingIdentity();
4982 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004983 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4984 if (controller == null) {
4985 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4986
4987 // device does not support IMS, this method will return false
4988 return false;
4989 }
4990 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 }
4995
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4999 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5000 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005001 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5002 mApp, subId, "getImsProvisioningInt");
5003
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005007 int slotId = getSlotIndex(subId);
5008 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5009 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5010 + subId + "' for key:" + key);
5011 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5012 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005013
joonhunshin91bc1952022-04-29 08:47:15 +00005014 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5015 if (controller == null) {
5016 loge("getImsProvisioningInt: Device does not support IMS");
5017
5018 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5019 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5020 }
5021 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005022 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5023 return retVal;
5024 }
5025
calvinpanb5a34062021-02-08 19:59:36 +08005026 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005027 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005028 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5029 + subId + "' for key:" + key);
5030 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
5034 }
5035
5036 @Override
5037 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005038 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5039 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5040 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005041 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5042 mApp, subId, "getImsProvisioningString");
5043
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005047 int slotId = getSlotIndex(subId);
5048 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5049 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5050 + subId + "' for key:" + key);
5051 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5052 }
calvinpanb5a34062021-02-08 19:59:36 +08005053 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005055 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5056 + subId + "' for key:" + key);
5057 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
5061 }
5062
5063 @Override
5064 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005065 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5066 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5067 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5069 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005070
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005074 int slotId = getSlotIndex(subId);
5075 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5076 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5077 + subId + "' for key:" + key);
5078 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5079 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005080
joonhunshin91bc1952022-04-29 08:47:15 +00005081 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5082 if (controller == null) {
5083 loge("setImsProvisioningInt: Device does not support IMS");
5084
5085 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5086 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5087 }
5088 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005089 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5090 return retVal;
5091 }
5092
calvinpanb5a34062021-02-08 19:59:36 +08005093 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5094 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005095 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005096 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005097 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
5102
5103 @Override
5104 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005105 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5106 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5107 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5109 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005113 int slotId = getSlotIndex(subId);
5114 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5115 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5116 + subId + "' for key:" + key);
5117 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5118 }
calvinpanb5a34062021-02-08 19:59:36 +08005119 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5120 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005121 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005122 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
5127 }
5128
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 /**
5130 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5131 * for the given slot ID or no ImsResolver instance has been created.
5132 * @param slotId The slot ID that the IMS service is created for.
5133 * @throws ImsException If there is no ImsService configured for this slot.
5134 */
5135 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5136 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5137 ImsFeature.FEATURE_MMTEL)) {
5138 throw new ImsException("This subscription does not support MMTEL over IMS",
5139 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5140 }
5141 }
5142
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005143 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 int slotId = SubscriptionManager.getSlotIndex(subId);
5145 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005146 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5147 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 }
5149 return slotId;
5150 }
5151
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005152 private int getSlotIndex(int subId) {
5153 int slotId = SubscriptionManager.getSlotIndex(subId);
5154 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5155 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5156 }
5157 return slotId;
5158 }
5159
Wink Saville36469e72014-06-11 15:17:00 -07005160 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005161 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005162 */
5163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005164 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5165 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005166 try {
5167 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5168 } catch (SecurityException se) {
5169 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5170 throw new SecurityException("Package " + callingPackage + " does not belong to "
5171 + Binder.getCallingUid());
5172 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005173 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005174 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005175 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005176 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005177 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005178 mApp, subId, callingPackage, callingFeatureId,
5179 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005180 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5181 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 final Phone phone = getPhone(subId);
5186 if (phone != null) {
5187 return phone.getServiceState().getDataNetworkType();
5188 } else {
5189 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5190 }
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005194 }
5195
5196 /**
5197 * Returns the data network type
5198 */
5199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005200 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005201 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005202 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005203 }
5204
5205 /**
5206 * Returns the data network type for a subId
5207 */
5208 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005209 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5210 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005211 String functionName = "getDataNetworkTypeForSubscriber";
5212 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5213 mApp, functionName)) {
5214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5215 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5216 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5217 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005218 }
5219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 final Phone phone = getPhone(subId);
5223 if (phone != null) {
5224 return phone.getServiceState().getDataNetworkType();
5225 } else {
5226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5227 }
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005231 }
5232
5233 /**
Wink Saville36469e72014-06-11 15:17:00 -07005234 * Returns the Voice network type for a subId
5235 */
5236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005237 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5238 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005239 String functionName = "getVoiceNetworkTypeForSubscriber";
5240 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5241 mApp, functionName)) {
5242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5243 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5245 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005246 }
5247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 final Phone phone = getPhone(subId);
5251 if (phone != null) {
5252 return phone.getServiceState().getVoiceNetworkType();
5253 } else {
5254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5255 }
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005259 }
5260
5261 /**
5262 * @return true if a ICC card is present
5263 */
5264 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005265 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005266 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005267 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005268 }
5269
5270 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005271 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005272 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005273 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005274 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 final Phone phone = PhoneFactory.getPhone(slotIndex);
5278 if (phone != null) {
5279 return phone.getIccCard().hasIccCard();
5280 } else {
5281 return false;
5282 }
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005286 }
5287
5288 /**
5289 * Return if the current radio is LTE on CDMA. This
5290 * is a tri-state return value as for a period of time
5291 * the mode may be unknown.
5292 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005293 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005294 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005295 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005296 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005298 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5299 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5300 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005301 }
5302
Sanket Padawe356d7632015-06-22 14:03:32 -07005303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005304 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5305 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005306 try {
5307 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5308 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005309 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5310 }
5311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 final Phone phone = getPhone(subId);
5315 if (phone == null) {
5316 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5317 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005318 return TelephonyProperties.lte_on_cdma_device()
5319 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 }
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005323 }
Wink Saville36469e72014-06-11 15:17:00 -07005324 }
5325
Wink Saville36469e72014-06-11 15:17:00 -07005326 /**
5327 * {@hide}
5328 * Returns Default subId, 0 in the case of single standby.
5329 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005330 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005331 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005332 }
5333
Shishir Agrawala9f32182016-04-12 12:00:16 -07005334 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005335 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005336 }
5337
Wink Savilleb564aae2014-10-23 10:18:09 -07005338 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005339 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005340 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005341
Pengquan Menge92a50d2018-09-21 15:54:48 -07005342 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005343 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5344 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5345 mApp.getOpPackageName(), mApp.getFeatureId());
5346 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005347 return mSubscriptionController.isActiveSubId(subId);
5348 }
5349
Ihab Awadf2177b72013-11-25 13:33:23 -08005350 /**
5351 * @see android.telephony.TelephonyManager.WifiCallingChoices
5352 */
5353 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005356 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5358 getWhenToMakeWifiCallsDefaultPreference());
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005362 }
5363
5364 /**
5365 * @see android.telephony.TelephonyManager.WifiCallingChoices
5366 */
5367 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005371 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005376 }
5377
Sailesh Nepald1e68152013-12-12 19:08:02 -08005378 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005379 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005380 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005381 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005382
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005383 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5384 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5385 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005386 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005387 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5388 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005389 }
5390 return PhoneFactory.getPhone(phoneId);
5391 }
5392
Shishir Agrawal566b7612013-10-28 14:41:00 -07005393 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005394 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005395 @NonNull IccLogicalChannelRequest request) {
5396 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5397 /*message=*/ "iccOpenLogicalChannel");
5398
5399 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5400 // Verify that the callingPackage in the request belongs to the calling UID
5401 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5402
5403 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005404 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005405
Rambo Wanga1782702021-11-10 20:15:19 -08005406 private Phone getPhoneFromValidIccLogicalChannelRequest(
5407 @NonNull IccLogicalChannelRequest request, String message) {
5408 Phone phone;
5409 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5411 mApp, request.subId, message);
5412 phone = getPhoneFromSubId(request.subId);
5413 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5414 enforceModifyPermission();
5415 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5416 } else {
5417 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005418 }
Rambo Wanga1782702021-11-10 20:15:19 -08005419 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005420 }
5421
5422 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005423 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005426 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005428 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5429 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005430 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5431 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 loge("The calling package is not allowed to access ISD-R.");
5433 throw new SecurityException(
5434 "The calling package is not allowed to access ISD-R.");
5435 }
Derek Tan740e1672017-06-27 14:56:27 -07005436 }
Derek Tan740e1672017-06-27 14:56:27 -07005437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005439 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5440 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 return response;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005445 }
5446
5447 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005448 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5449 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5450 /*message=*/"iccCloseLogicalChannel");
5451
5452 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5453
5454 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005455 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005456
Rambo Wanga1782702021-11-10 20:15:19 -08005457 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5458 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005459 // before this feature is enabled, this API should only return false if
5460 // the operation fails instead of throwing runtime exception for
5461 // backward-compatibility.
5462 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5463 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 final long identity = Binder.clearCallingIdentity();
5465 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005466 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005467 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 }
Chen Xue9d737e2022-01-01 23:41:31 -08005469 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005470 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005471 Boolean success = false;
5472 if (result instanceof RuntimeException) {
5473 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005474 if (shouldThrowExceptionOnFailure) {
5475 throw (RuntimeException) result;
5476 } else {
5477 return false;
5478 }
Chen Xue9d737e2022-01-01 23:41:31 -08005479 } else if (result instanceof Boolean) {
5480 success = (Boolean) result;
5481 } else {
5482 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5483 }
Rambo Wanga1782702021-11-10 20:15:19 -08005484 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 return success;
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005488 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005489 }
5490
5491 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005492 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005493 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5495 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005496 if (DBG) {
5497 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5498 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5499 + p3 + " data=" + data);
5500 }
5501 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5502 command, p1, p2, p3, data);
5503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005504
Jordan Liu4c733742019-02-28 12:03:40 -08005505 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005506 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5507 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005508 enforceModifyPermission();
5509 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005510 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5511 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5512 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005513 }
5514 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005515 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5516 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005517 }
5518
5519 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5520 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 final long identity = Binder.clearCallingIdentity();
5522 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005523 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 return "";
5525 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005528 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5529 null /* workSource */);
5530 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 // Append the returned status code to the end of the response payload.
5533 String s = Integer.toHexString(
5534 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5535 if (response.payload != null) {
5536 s = IccUtils.bytesToHexString(response.payload) + s;
5537 }
5538 return s;
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005542 }
Jake Hambye994d462014-02-03 13:10:13 -08005543
Evan Charltonc66da362014-05-16 14:06:40 -07005544 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005545 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5546 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5548 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005550 if (DBG) {
5551 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5552 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5553 }
5554 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5555 cla, command, p1, p2, p3, data);
5556 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005557
Jordan Liu4c733742019-02-28 12:03:40 -08005558 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005559 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5560 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005561 enforceModifyPermission();
5562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5563 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005564 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5565 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5566 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005567 }
5568
5569 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005570 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5571 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005572 }
5573
5574 // open APDU basic channel assuming the caller has sufficient permissions
5575 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5576 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5580 && TextUtils.equals(ISDR_AID, data)) {
5581 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005582 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5583 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 if (bestComponent == null
5585 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5586 loge("The calling package is not allowed to select ISD-R.");
5587 throw new SecurityException(
5588 "The calling package is not allowed to select ISD-R.");
5589 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005590 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005593 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5594 null /* workSource */);
5595 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 // Append the returned status code to the end of the response payload.
5598 String s = Integer.toHexString(
5599 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5600 if (response.payload != null) {
5601 s = IccUtils.bytesToHexString(response.payload) + s;
5602 }
5603 return s;
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005606 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005607 }
5608
5609 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005610 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005611 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 if (DBG) {
5618 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5619 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5620 }
5621
5622 IccIoResult response =
5623 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5624 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5625 subId);
5626
5627 if (DBG) {
5628 log("Exchange SIM_IO [R]" + response);
5629 }
5630
5631 byte[] result = null;
5632 int length = 2;
5633 if (response.payload != null) {
5634 length = 2 + response.payload.length;
5635 result = new byte[length];
5636 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5637 } else {
5638 result = new byte[length];
5639 }
5640
5641 result[length - 1] = (byte) response.sw2;
5642 result[length - 2] = (byte) response.sw1;
5643 return result;
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005646 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005647 }
5648
Nathan Haroldb3014052017-01-25 15:57:32 -08005649 /**
5650 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5651 * on a particular subscription
5652 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005653 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5654 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005656 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005657 return null;
5658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 if (appType != TelephonyManager.APPTYPE_USIM
5663 && appType != TelephonyManager.APPTYPE_SIM) {
5664 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5665 return null;
5666 }
5667 Object response = sendRequest(
5668 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5669 if (response instanceof String[]) {
5670 return (String[]) response;
5671 }
yincheng zhao2737e882019-09-06 17:06:54 -07005672 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005674 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005677 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005678 }
5679
yincheng zhao2737e882019-09-06 17:06:54 -07005680 /**
5681 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5682 * subscription.
5683 *
5684 * @param subId the id of the subscription.
5685 * @param appType the uicc app type, must be USIM or SIM.
5686 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5687 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005688 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005689 * @return number of fplmns that is successfully written to the SIM.
5690 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005691 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5692 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "setForbiddenPlmns");
5695
yincheng zhao2737e882019-09-06 17:06:54 -07005696 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5697 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5698 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5699 }
5700 if (fplmns == null) {
5701 throw new IllegalArgumentException("Fplmn List provided is null");
5702 }
5703 for (String fplmn : fplmns) {
5704 if (!CellIdentity.isValidPlmn(fplmn)) {
5705 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5706 }
5707 }
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 Object response = sendRequest(
5711 CMD_SET_FORBIDDEN_PLMNS,
5712 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5713 subId);
5714 return (int) response;
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
5718 }
5719
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005720 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005721 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5723 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5728 if (response.payload == null) {
5729 return "";
5730 }
Evan Charltonc66da362014-05-16 14:06:40 -07005731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 // Append the returned status code to the end of the response payload.
5733 String s = Integer.toHexString(
5734 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5735 s = IccUtils.bytesToHexString(response.payload) + s;
5736 return s;
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Evan Charltonc66da362014-05-16 14:06:40 -07005740 }
5741
Jake Hambye994d462014-02-03 13:10:13 -08005742 /**
5743 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5744 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5745 *
5746 * @param itemID the ID of the item to read
5747 * @return the NV item as a String, or null on error.
5748 */
5749 @Override
5750 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005751 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5753 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005758 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5760 return value;
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
Jake Hambye994d462014-02-03 13:10:13 -08005764 }
5765
5766 /**
5767 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5768 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5769 *
5770 * @param itemID the ID of the item to read
5771 * @param itemValue the value to write, as a String
5772 * @return true on success; false on any failure
5773 */
5774 @Override
5775 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005776 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5778 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5783 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005784 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5786 return success;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Jake Hambye994d462014-02-03 13:10:13 -08005790 }
5791
5792 /**
5793 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5794 * Used for device configuration by some CDMA operators.
5795 *
5796 * @param preferredRoamingList byte array containing the new PRL
5797 * @return true on success; false on any failure
5798 */
5799 @Override
5800 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5802 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803
5804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5807 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5808 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5809 return success;
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
Jake Hambye994d462014-02-03 13:10:13 -08005813 }
5814
5815 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005816 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005817 * Used for device configuration by some CDMA operators.
5818 *
chen xu6dac5ab2018-10-26 17:39:23 -07005819 * @param slotIndex - device slot.
5820 *
Jake Hambye994d462014-02-03 13:10:13 -08005821 * @return true on success; false on any failure
5822 */
5823 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005824 public boolean resetModemConfig(int slotIndex) {
5825 Phone phone = PhoneFactory.getPhone(slotIndex);
5826 if (phone != null) {
5827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5828 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829
chen xu6dac5ab2018-10-26 17:39:23 -07005830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5833 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5834 return success;
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 }
chen xu6dac5ab2018-10-26 17:39:23 -07005839 return false;
5840 }
5841
5842 /**
5843 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5844 *
5845 * @param slotIndex - device slot.
5846 *
5847 * @return true on success; false on any failure
5848 */
5849 @Override
5850 public boolean rebootModem(int slotIndex) {
5851 Phone phone = PhoneFactory.getPhone(slotIndex);
5852 if (phone != null) {
5853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5854 mApp, phone.getSubId(), "rebootModem");
5855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5859 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5860 return success;
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
5864 }
5865 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005866 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005867
Brad Ebinger51f743a2017-01-23 13:50:20 -08005868 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005869 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5870 * {@link #disableIms(int)}.
5871 * @param slotIndex device slot.
5872 */
5873 public void resetIms(int slotIndex) {
5874 enforceModifyPermission();
5875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
5878 if (mImsResolver == null) {
5879 // may happen if the does not support IMS.
5880 return;
5881 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005882 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
5886 }
5887
5888 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005889 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5890 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005891 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005892 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005893 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005897 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005898 // may happen if the device does not support IMS.
5899 return;
5900 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005905 }
5906
5907 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005908 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5909 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005910 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005911 public void disableIms(int slotId) {
5912 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005917 // may happen if the device does not support IMS.
5918 return;
5919 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005924 }
5925
5926 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005927 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5928 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005929 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005930 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005931 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005937 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5938 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005939 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005940 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005944 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005945 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005946 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5947 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005948 @Override
5949 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005950 enforceModifyPermission();
5951
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005955 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
5959 }
5960
5961 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005962 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005963 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005964 */
5965 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005970 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005971 // may happen if the device does not support IMS.
5972 return null;
5973 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005974 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005978 }
5979
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005980 /**
5981 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005982 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005983 */
5984 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986
5987 final long identity = Binder.clearCallingIdentity();
5988 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005989 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005990 // may happen if the device does not support IMS.
5991 return null;
5992 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005993 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005997 }
5998
Brad Ebinger884c07b2018-02-15 16:17:40 -08005999 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006000 * Sets the ImsService Package Name that Telephony will bind to.
6001 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006002 * @param slotIndex the slot ID that the ImsService should bind for.
6003 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006004 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006005 * @param featureTypes An integer array of feature types associated with a packageName.
6006 * @param packageName The name of the package that the current configuration will be replaced
6007 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006008 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006009 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006010 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6011 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006014 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 final long identity = Binder.clearCallingIdentity();
6017 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006018 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006019 // may happen if the device does not support IMS.
6020 return false;
6021 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006022 Map<Integer, String> featureConfig = new HashMap<>();
6023 for (int featureType : featureTypes) {
6024 featureConfig.put(featureType, packageName);
6025 }
6026 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6027 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006031 }
6032
6033 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006034 * Clears any carrier ImsService overrides for the slot index specified that were previously
6035 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6036 *
6037 * This should only be used for testing.
6038 *
6039 * @param slotIndex the slot ID that the ImsService should bind for.
6040 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6041 */
6042 @Override
6043 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6045 "clearCarrierImsServiceOverride");
6046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006047 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006048
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
6051 if (mImsResolver == null) {
6052 // may happen if the device does not support IMS.
6053 return false;
6054 }
6055 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
6060
6061 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006062 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006063 *
6064 * @param slotId The slot that the ImsService is associated with.
6065 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6066 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006067 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006068 * @return the package name of the ImsService configuration.
6069 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006070 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6071 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006072 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006073 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6074 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 final long identity = Binder.clearCallingIdentity();
6077 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006078 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006079 // may happen if the device does not support IMS.
6080 return "";
6081 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006082 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006083 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6084 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 } finally {
6086 Binder.restoreCallingIdentity(identity);
6087 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006088 }
6089
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006090 /**
6091 * Get the MmTelFeature state associated with the requested subscription id.
6092 * @param subId The subscription that the MmTelFeature is associated with.
6093 * @param callback A callback with an integer containing the
6094 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6095 */
6096 @Override
6097 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6098 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006099 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6101 "IMS not available on device.");
6102 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006103 final long token = Binder.clearCallingIdentity();
6104 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006105 int slotId = getSlotIndex(subId);
6106 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6107 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6108 + subId + "'");
6109 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6110 }
6111 verifyImsMmTelConfiguredOrThrow(slotId);
6112 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6113 try {
6114 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6115 } catch (RemoteException e) {
6116 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6117 + "Ignore");
6118 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006119 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006120 } catch (ImsException e) {
6121 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006122 } finally {
6123 Binder.restoreCallingIdentity(token);
6124 }
6125 }
6126
Daniel Brightbb5840b2021-01-12 15:48:18 -08006127 /**
6128 * Sets the ims registration state on all valid {@link Phone}s.
6129 */
6130 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006135 // NOTE: Before S, this method only set the default phone.
6136 for (final Phone phone : PhoneFactory.getPhones()) {
6137 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6138 phone.setImsRegistrationState(registered);
6139 }
6140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Wink Saville36469e72014-06-11 15:17:00 -07006144 }
6145
6146 /**
Stuart Scott54788802015-03-30 13:18:01 -07006147 * Set the network selection mode to automatic.
6148 *
6149 */
6150 @Override
6151 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6153 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154
6155 final long identity = Binder.clearCallingIdentity();
6156 try {
shilufc958392020-01-20 11:36:01 -08006157 if (!isActiveSubscription(subId)) {
6158 return;
6159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006161 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6162 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Stuart Scott54788802015-03-30 13:18:01 -07006166 }
6167
Jack Yud10cdd42020-09-28 20:28:01 -07006168 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006169 * Ask the radio to connect to the input network and change selection mode to manual.
6170 *
6171 * @param subId the id of the subscription.
6172 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6173 * the operator to attach to.
6174 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6175 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6176 * normal network selection next time.
6177 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006178 */
6179 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006180 public boolean setNetworkSelectionModeManual(
6181 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6183 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006184
Jack Yu285100e2022-12-02 22:48:35 -08006185 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006186 if (!isActiveSubscription(subId)) {
6187 return false;
6188 }
6189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006191 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006193 if (DBG) {
6194 log("setNetworkSelectionModeManual: subId: " + subId
6195 + " operator: " + operatorInfo);
6196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006201 }
shilu84f6e8b2019-12-19 13:58:01 -08006202 /**
6203 * Get the manual network selection
6204 *
6205 * @param subId the id of the subscription.
6206 *
6207 * @return the previously saved user selected PLMN
6208 */
6209 @Override
6210 public String getManualNetworkSelectionPlmn(int subId) {
6211 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006212 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006213 mApp, subId, "getManualNetworkSelectionPlmn");
6214
6215 final long identity = Binder.clearCallingIdentity();
6216 try {
6217 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006218 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006219 }
6220
6221 final Phone phone = getPhone(subId);
6222 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006223 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006224 }
6225 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6226 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6227 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006232
6233 /**
6234 * Scans for available networks.
6235 */
6236 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006237 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6238 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6240 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006241 LocationAccessPolicy.LocationPermissionResult locationResult =
6242 LocationAccessPolicy.checkLocationPermission(mApp,
6243 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6244 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006245 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006246 .setCallingPid(Binder.getCallingPid())
6247 .setCallingUid(Binder.getCallingUid())
6248 .setMethod("getCellNetworkScanResults")
6249 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006250 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6251 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006252 .build());
6253 switch (locationResult) {
6254 case DENIED_HARD:
6255 throw new SecurityException("Not allowed to access scan results -- location");
6256 case DENIED_SOFT:
6257 return null;
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259
Pengquan Menga1bb6272018-09-06 09:59:22 -07006260 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 try {
6262 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006263 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006268 }
6269
6270 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006271 * Get the call forwarding info, given the call forwarding reason.
6272 */
6273 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006274 public void getCallForwarding(int subId, int callForwardingReason,
6275 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006276 enforceReadPrivilegedPermission("getCallForwarding");
6277 long identity = Binder.clearCallingIdentity();
6278 try {
6279 if (DBG) {
6280 log("getCallForwarding: subId " + subId
6281 + " callForwardingReason" + callForwardingReason);
6282 }
Hall Liu27d24262020-09-18 19:04:59 -07006283
6284 Phone phone = getPhone(subId);
6285 if (phone == null) {
6286 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006287 callback.onError(
6288 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006289 } catch (RemoteException e) {
6290 // ignore
6291 }
6292 return;
6293 }
6294
6295 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6296 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6297 @Override
6298 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6299 try {
6300 callback.onCallForwardingInfoAvailable(info);
6301 } catch (RemoteException e) {
6302 // ignore
6303 }
6304 }
6305
6306 @Override
6307 public void onError(int error) {
6308 try {
6309 callback.onError(error);
6310 } catch (RemoteException e) {
6311 // ignore
6312 }
6313 }
6314 });
6315 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
6319 }
6320
6321 /**
6322 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6323 * reason, the number to forward, and the timeout before the forwarding is attempted.
6324 */
6325 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006326 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6327 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006328 enforceModifyPermission();
6329 long identity = Binder.clearCallingIdentity();
6330 try {
6331 if (DBG) {
6332 log("setCallForwarding: subId " + subId
6333 + " callForwardingInfo" + callForwardingInfo);
6334 }
Hall Liu27d24262020-09-18 19:04:59 -07006335
6336 Phone phone = getPhone(subId);
6337 if (phone == null) {
6338 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006339 callback.accept(
6340 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006341 } catch (RemoteException e) {
6342 // ignore
6343 }
6344 return;
6345 }
6346
6347 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6348 FunctionalUtils.ignoreRemoteException(callback::accept));
6349
6350 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
6354 }
6355
6356 /**
Hall Liu27d24262020-09-18 19:04:59 -07006357 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006358 */
6359 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006360 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006361 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006362 long identity = Binder.clearCallingIdentity();
6363 try {
Hall Liu27d24262020-09-18 19:04:59 -07006364 Phone phone = getPhone(subId);
6365 if (phone == null) {
6366 try {
6367 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6368 } catch (RemoteException e) {
6369 // ignore
6370 }
6371 return;
6372 }
SongFerngWang0e767992021-03-31 22:08:45 +08006373 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6374 PersistableBundle c = configManager.getConfigForSubId(subId);
6375 boolean requireUssd = c.getBoolean(
6376 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006377
Shuo Qian4a594052020-01-23 11:59:30 -08006378 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006379 if (requireUssd) {
6380 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6381 getSubscriptionCarrierId(subId));
6382 String newUssdCommand = "";
6383 try {
6384 newUssdCommand = carrierXmlParser.getFeature(
6385 CarrierXmlParser.FEATURE_CALL_WAITING)
6386 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6387 } catch (NullPointerException e) {
6388 loge("Failed to generate USSD number" + e);
6389 }
6390 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6391 mMainThreadHandler, callback, carrierXmlParser,
6392 CarrierXmlParser.SsEntry.SSAction.QUERY);
6393 final String ussdCommand = newUssdCommand;
6394 Executors.newSingleThreadExecutor().execute(() -> {
6395 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6396 });
6397 } else {
6398 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6399 callback::accept);
6400 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6401 }
Shuo Qian4a594052020-01-23 11:59:30 -08006402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
6405 }
6406
6407 /**
Hall Liu27d24262020-09-18 19:04:59 -07006408 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006409 */
6410 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006411 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006412 enforceModifyPermission();
6413 long identity = Binder.clearCallingIdentity();
6414 try {
Hall Liu27d24262020-09-18 19:04:59 -07006415 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6416
6417 Phone phone = getPhone(subId);
6418 if (phone == null) {
6419 try {
6420 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6421 } catch (RemoteException e) {
6422 // ignore
6423 }
6424 return;
6425 }
6426
SongFerngWang0e767992021-03-31 22:08:45 +08006427 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6428 PersistableBundle c = configManager.getConfigForSubId(subId);
6429 boolean requireUssd = c.getBoolean(
6430 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006431
SongFerngWang0e767992021-03-31 22:08:45 +08006432 if (DBG) log("getCallWaitingStatus: subId " + subId);
6433 if (requireUssd) {
6434 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6435 getSubscriptionCarrierId(subId));
6436 CarrierXmlParser.SsEntry.SSAction ssAction =
6437 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6438 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6439 String newUssdCommand = "";
6440 try {
6441 newUssdCommand = carrierXmlParser.getFeature(
6442 CarrierXmlParser.FEATURE_CALL_WAITING)
6443 .makeCommand(ssAction, null);
6444 } catch (NullPointerException e) {
6445 loge("Failed to generate USSD number" + e);
6446 }
6447 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6448 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6449 final String ussdCommand = newUssdCommand;
6450 Executors.newSingleThreadExecutor().execute(() -> {
6451 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6452 });
6453 } else {
6454 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6455 FunctionalUtils.ignoreRemoteException(callback::accept));
6456
6457 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6458 }
Shuo Qian4a594052020-01-23 11:59:30 -08006459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
6462 }
6463
6464 /**
yinxub1bed742017-04-17 11:45:04 -07006465 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006466 *
yinxub1bed742017-04-17 11:45:04 -07006467 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006468 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6469 * location related information which will be sent if the caller already possess
6470 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006471 * @param request contains the radio access networks with bands/channels to scan
6472 * @param messenger callback messenger for scan results or errors
6473 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006474 * @return the id of the requested scan which can be used to stop the scan.
6475 */
6476 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006477 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6478 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006479 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6481 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006482 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006483 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6484 if (!renounceFineLocationAccess) {
6485 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6486 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6487 .setCallingPackage(callingPackage)
6488 .setCallingFeatureId(callingFeatureId)
6489 .setCallingPid(Binder.getCallingPid())
6490 .setCallingUid(Binder.getCallingUid())
6491 .setMethod("requestNetworkScan")
6492 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6493 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6494 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6495 .build());
6496 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006497 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006498 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6499 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006500 if (e != null) {
6501 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6502 throw e;
6503 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006504 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006505 return TelephonyScanManager.INVALID_SCAN_ID;
6506 }
6507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 }
Hall Liu912dfd32019-04-25 14:02:26 -07006509 int callingUid = Binder.getCallingUid();
6510 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006511 final long identity = Binder.clearCallingIdentity();
6512 try {
6513 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006514 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006515 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
yinxu504e1392017-04-12 16:03:22 -07006519 }
6520
Hall Liub2ac8ef2019-02-28 15:56:23 -08006521 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006522 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006523 boolean hasCarrierPriv;
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6527 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
Hall Liu558027f2019-05-15 19:14:05 -07006531 boolean hasNetworkScanPermission =
6532 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6533 == PERMISSION_GRANTED;
6534
6535 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6536 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6537 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006538 }
6539
6540 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6541 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006542 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6543 return new SecurityException("Specific channels must not be"
6544 + " scanned without location access.");
6545 }
6546 }
6547 }
6548
Hall Liub2ac8ef2019-02-28 15:56:23 -08006549 return null;
6550 }
6551
yinxu504e1392017-04-12 16:03:22 -07006552 /**
6553 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006554 *
6555 * @param subId id of the subscription
6556 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006557 */
6558 @Override
6559 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6561 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
Hall Liu912dfd32019-04-25 14:02:26 -07006563 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 final long identity = Binder.clearCallingIdentity();
6565 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006566 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
yinxu504e1392017-04-12 16:03:22 -07006570 }
6571
6572 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006573 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006574 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006575 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006576 */
6577 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006578 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006579 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006580 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006581 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582
6583 final long identity = Binder.clearCallingIdentity();
6584 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006585 if (DBG) log("getAllowedNetworkTypesBitmask");
6586 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6587 int networkTypesBitmask = (result != null ? result[0] : -1);
6588 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6589 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
6592 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006593 }
6594
6595 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006596 * Get the allowed network types for certain reason.
6597 *
6598 * @param subId the id of the subscription.
6599 * @param reason the reason the allowed network type change is taking place
6600 * @return the allowed network types.
6601 */
6602 @Override
6603 public long getAllowedNetworkTypesForReason(int subId,
6604 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006605 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006606 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
6614
6615 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006616 * Enable/Disable E-UTRA-NR Dual Connectivity
6617 * @param subId subscription id of the sim card
6618 * @param nrDualConnectivityState expected NR dual connectivity state
6619 * This can be passed following states
6620 * <ol>
6621 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6622 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6623 * <li>Disable NR dual connectivity and force secondary cell to be released
6624 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6625 * </ol>
6626 * @return operation result.
6627 */
6628 @Override
6629 public int setNrDualConnectivityState(int subId,
6630 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6632 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006633 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006634 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6635 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6636 }
6637
Sooraj Sasindran37444802020-08-11 10:40:43 -07006638 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6642 nrDualConnectivityState, subId,
6643 workSource);
6644 if (DBG) log("enableNRDualConnectivity result: " + result);
6645 return result;
6646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
6649 }
6650
6651 /**
6652 * Is E-UTRA-NR Dual Connectivity enabled
6653 * @return true if dual connectivity is enabled else false
6654 */
6655 @Override
6656 public boolean isNrDualConnectivityEnabled(int subId) {
6657 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006659 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006660 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006661 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6662 return false;
6663 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006664 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6668 null, subId, workSource);
6669 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6670 return isEnabled;
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
6673 }
6674 }
6675
6676 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006677 * Set the allowed network types of the device and
6678 * provide the reason triggering the allowed network change.
6679 *
6680 * @param subId the id of the subscription.
6681 * @param reason the reason the allowed network type change is taking place
6682 * @param allowedNetworkTypes the allowed network types.
6683 * @return true on success; false on any failure.
6684 */
6685 @Override
6686 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006687 @TelephonyManager.AllowedNetworkTypesReason int reason,
6688 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6690 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006691 // If the caller only has carrier privileges, then they should not be able to override
6692 // any network types which were set for security reasons.
6693 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6694 != PERMISSION_GRANTED
6695 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6696 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6697 throw new SecurityException(
6698 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6699 + " reason "
6700 + reason);
6701 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006702 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006703 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6704 return false;
6705 }
6706 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6707 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006708 return false;
6709 }
6710
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006711 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6712 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6713
6714
6715 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6716 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6717 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006718 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006719
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006720 final long identity = Binder.clearCallingIdentity();
6721 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006722 Boolean success = (Boolean) sendRequest(
6723 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6724 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6725
6726 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6727 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
6731 }
6732
6733 /**
Miaoa84611c2019-03-15 09:21:10 +08006734 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006735 *
Miaoa84611c2019-03-15 09:21:10 +08006736 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006737 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006738 * @hide
6739 */
6740 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006741 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006744 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 try {
Miaoa84611c2019-03-15 09:21:10 +08006746 if (phone != null) {
6747 return phone.hasMatchedTetherApnSetting();
6748 } else {
6749 return false;
6750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 } finally {
6752 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006753 }
Junda Liu475951f2014-11-07 16:45:03 -08006754 }
6755
6756 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006757 * Get the user enabled state of Mobile Data.
6758 *
6759 * TODO: remove and use isUserDataEnabled.
6760 * This can't be removed now because some vendor codes
6761 * calls through ITelephony directly while they should
6762 * use TelephonyManager.
6763 *
6764 * @return true on enabled
6765 */
6766 @Override
6767 public boolean getDataEnabled(int subId) {
6768 return isUserDataEnabled(subId);
6769 }
6770
6771 /**
6772 * Get whether mobile data is enabled per user setting.
6773 *
6774 * There are other factors deciding whether mobile data is actually enabled, but they are
6775 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006776 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006777 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6778 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006779 *
6780 * @return {@code true} if data is enabled else {@code false}
6781 */
6782 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006783 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006784 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006785 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006786 try {
6787 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6788 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006789 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006790 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6791 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006792 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 mApp, subId, functionName);
6795
Robert Greenwalt646120a2014-05-23 11:54:03 -07006796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
Jack Yu285100e2022-12-02 22:48:35 -08006800 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6802 Phone phone = PhoneFactory.getPhone(phoneId);
6803 if (phone != null) {
6804 boolean retVal = phone.isUserDataEnabled();
6805 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6806 return retVal;
6807 } else {
6808 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6809 return false;
6810 }
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006813 }
6814 }
6815
6816 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006817 * Checks if the device is capable of mobile data by considering whether whether the
6818 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6819 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006820 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006821 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006822 */
6823 @Override
6824 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006825 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006826 try {
6827 try {
6828 mApp.enforceCallingOrSelfPermission(
6829 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006830 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006831 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006832 try {
6833 mApp.enforceCallingOrSelfPermission(
6834 android.Manifest.permission.READ_PHONE_STATE,
6835 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006836 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006837 mApp.enforceCallingOrSelfPermission(
6838 permission.READ_BASIC_PHONE_STATE, functionName);
6839 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006840 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006841 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006842 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006843 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844
6845 final long identity = Binder.clearCallingIdentity();
6846 try {
Jack Yu285100e2022-12-02 22:48:35 -08006847 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 Phone phone = PhoneFactory.getPhone(phoneId);
6849 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006850 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006851 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 return retVal;
6853 } else {
6854 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6855 return false;
6856 }
6857 } finally {
6858 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006859 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006860 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006861
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006862 /**
6863 * Check if data is enabled for a specific reason
6864 * @param subId Subscription index
6865 * @param reason the reason the data enable change is taking place
6866 * @return {@code true} if the overall data is enabled; {@code false} if not.
6867 */
6868 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006869 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006870 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006871 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006872 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006873 try {
6874 mApp.enforceCallingOrSelfPermission(
6875 android.Manifest.permission.ACCESS_NETWORK_STATE,
6876 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006877 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006878 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6879 functionName);
6880 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006881 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006882 try {
6883 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006884 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006885 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006887 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006888 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006889 }
6890
6891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
Jack Yu285100e2022-12-02 22:48:35 -08006894 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006895 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006896 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006897 + " reason=" + reason);
6898 }
6899 Phone phone = PhoneFactory.getPhone(phoneId);
6900 if (phone != null) {
6901 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006902 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006903 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006904 return retVal;
6905 } else {
6906 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006907 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006908 + subId + " retVal=false");
6909 }
6910 return false;
6911 }
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
6915 }
6916
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006918 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006919 // No permission needed; this only lets the caller inspect their own status.
6920 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006921 }
Junda Liu29340342014-07-10 15:23:27 -07006922
6923 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006924 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006925 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006926 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6927 }
6928
6929 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6930 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006931 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006932 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6934 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006935 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6936 if (cpt == null) {
6937 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6939 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006941 }
6942
6943 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006944 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006945 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006946 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006947 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006948 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006949 Phone phone = getPhone(subId);
6950 if (phone == null) {
6951 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6952 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6953 }
6954 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6955 if (cpt == null) {
6956 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006957 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6958 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006959 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006960 }
6961
6962 @Override
6963 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006964 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006965 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6966 }
6967
6968 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006969 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006970 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006971 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006972 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006973 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6974 Phone phone = PhoneFactory.getPhone(phoneId);
6975 if (phone == null) {
6976 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006977 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006978 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6979 if (cpt == null) {
6980 continue;
6981 }
6982 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006983 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6984 break;
6985 }
6986 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006987 return result;
Junda Liu29340342014-07-10 15:23:27 -07006988 }
Derek Tan89e89d42014-07-08 17:00:10 -07006989
6990 @Override
Junda Liue64de782015-04-16 17:19:16 -07006991 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006992 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006993 Phone phone = PhoneFactory.getPhone(phoneId);
6994 if (phone == null) {
6995 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006996 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006997 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6998 if (cpt == null) {
6999 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007000 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007001 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007002 }
7003
Amith Yamasani6e118872016-02-19 12:53:51 -08007004 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007005 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007006 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007007 Phone phone = PhoneFactory.getPhone(phoneId);
7008 if (phone == null) {
7009 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007010 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007011 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7012 if (cpt == null) {
7013 return Collections.emptyList();
7014 }
7015 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007016 }
7017
chen xuf7e9fe82019-05-09 19:31:02 -07007018 @Override
7019 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007020 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007021 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007022 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007023 try {
7024 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7025 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7026 }
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007029 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007030 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007031 }
7032
Rambo Wang6812ffb2022-03-15 16:54:17 -07007033 @Override
7034 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7035 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7036
7037 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7038 if (phone == null) {
7039 return null;
7040 }
7041 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7042 if (cpt == null) {
7043 return null;
7044 }
7045 return cpt.getCarrierServicePackageName();
7046 }
7047
Wink Savilleb564aae2014-10-23 10:18:09 -07007048 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007049 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007050 UiccPort port = phone == null ? null : phone.getUiccPort();
7051 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007052 return null;
7053 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007054 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007055 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007056 return null;
7057 }
7058 return iccId;
7059 }
7060
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007061 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007062 public void setCallComposerStatus(int subId, int status) {
7063 enforceModifyPermission();
7064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 Phone phone = getPhone(subId);
7068 if (phone != null) {
7069 Phone defaultPhone = phone.getImsPhone();
7070 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7071 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7072 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007073 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7074 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007075 }
7076 }
Shuo Qian284ae752020-12-22 19:10:14 -08007077 } catch (ImsException e) {
7078 throw new ServiceSpecificException(e.getCode());
7079 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
7084 @Override
7085 public int getCallComposerStatus(int subId) {
7086 enforceReadPrivilegedPermission("getCallComposerStatus");
7087
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = getPhone(subId);
7091 if (phone != null) {
7092 Phone defaultPhone = phone.getImsPhone();
7093 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7094 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7095 return imsPhone.getCallComposerStatus();
7096 }
7097 }
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
7100 }
7101 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7102 }
7103
7104 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007105 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7106 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007107 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007108 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 final String iccId = getIccId(subId);
7113 final Phone phone = getPhone(subId);
7114 if (phone == null) {
7115 return false;
7116 }
7117 final String subscriberId = phone.getSubscriberId();
7118
7119 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007120 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 + subscriberId + " to " + number);
7122 }
7123
7124 if (TextUtils.isEmpty(iccId)) {
7125 return false;
7126 }
7127
7128 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7129
7130 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7131 if (alphaTag == null) {
7132 editor.remove(alphaTagPrefKey);
7133 } else {
7134 editor.putString(alphaTagPrefKey, alphaTag);
7135 }
7136
7137 // Record both the line number and IMSI for this ICCID, since we need to
7138 // track all merged IMSIs based on line number
7139 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7140 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7141 if (number == null) {
7142 editor.remove(numberPrefKey);
7143 editor.remove(subscriberPrefKey);
7144 } else {
7145 editor.putString(numberPrefKey, number);
7146 editor.putString(subscriberPrefKey, subscriberId);
7147 }
7148
7149 editor.commit();
7150 return true;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007153 }
Derek Tan7226c842014-07-02 17:42:23 -07007154 }
7155
7156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007157 public String getLine1NumberForDisplay(int subId, String callingPackage,
7158 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007159 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007161 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007162 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007163 return null;
7164 }
Derek Tan97ebb422014-09-05 16:55:38 -07007165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 String iccId = getIccId(subId);
7169 if (iccId != null) {
7170 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7171 if (DBG_MERGE) {
7172 log("getLine1NumberForDisplay returning "
7173 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7174 }
7175 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7178 return null;
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007181 }
Derek Tan7226c842014-07-02 17:42:23 -07007182 }
7183
7184 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007185 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7186 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007188 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007189 return null;
7190 }
Derek Tan97ebb422014-09-05 16:55:38 -07007191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 String iccId = getIccId(subId);
7195 if (iccId != null) {
7196 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7197 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7198 }
7199 return null;
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007202 }
Derek Tan7226c842014-07-02 17:42:23 -07007203 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007204
7205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007206 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7207 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007208 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7209 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007211 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007212 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007213 return null;
7214 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007215
Jordan Liub49b04b2019-05-06 14:45:15 -07007216 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7217 // the process, where TelephonyManager was instantiated.
7218 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007219 final long identity = Binder.clearCallingIdentity();
7220 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007221 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 final TelephonyManager tele = TelephonyManager.from(context);
7223 final SubscriptionManager sub = SubscriptionManager.from(context);
7224
7225 // Figure out what subscribers are currently active
7226 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227
Jordan Liub49b04b2019-05-06 14:45:15 -07007228 // Only consider subs which match the current subId
7229 // This logic can be simplified. See b/131189269 for progress.
7230 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007231 activeSubscriberIds.add(tele.getSubscriberId(subId));
7232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233
7234 // First pass, find a number override for an active subscriber
7235 String mergeNumber = null;
7236 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7237 for (String key : prefs.keySet()) {
7238 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7239 final String subscriberId = (String) prefs.get(key);
7240 if (activeSubscriberIds.contains(subscriberId)) {
7241 final String iccId = key.substring(
7242 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7243 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7244 mergeNumber = (String) prefs.get(numberKey);
7245 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007246 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 + " for active subscriber " + subscriberId);
7248 }
7249 if (!TextUtils.isEmpty(mergeNumber)) {
7250 break;
7251 }
7252 }
7253 }
7254 }
7255
7256 // Shortcut when no active merged subscribers
7257 if (TextUtils.isEmpty(mergeNumber)) {
7258 return null;
7259 }
7260
7261 // Second pass, find all subscribers under that line override
7262 final ArraySet<String> result = new ArraySet<>();
7263 for (String key : prefs.keySet()) {
7264 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7265 final String number = (String) prefs.get(key);
7266 if (mergeNumber.equals(number)) {
7267 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7268 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7269 final String subscriberId = (String) prefs.get(subscriberKey);
7270 if (!TextUtils.isEmpty(subscriberId)) {
7271 result.add(subscriberId);
7272 }
7273 }
7274 }
7275 }
7276
7277 final String[] resultArray = result.toArray(new String[result.size()]);
7278 Arrays.sort(resultArray);
7279 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007280 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007281 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7282 }
7283 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007284 } finally {
7285 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007286 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007287 }
7288
7289 @Override
zoey chen38003472019-12-13 17:16:31 +08007290 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7291 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007292
7293 final long identity = Binder.clearCallingIdentity();
7294 try {
7295 final TelephonyManager telephonyManager = mApp.getSystemService(
7296 TelephonyManager.class);
7297 String subscriberId = telephonyManager.getSubscriberId(subId);
7298 if (subscriberId == null) {
7299 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007300 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007301 + subId);
7302 }
7303 return null;
7304 }
7305
Jack Yu285100e2022-12-02 22:48:35 -08007306 ParcelUuid groupUuid;
7307 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7308 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7309 .getSubscriptionInfo(subId);
7310 groupUuid = info.getGroupUuid();
7311 } else {
7312 final SubscriptionInfo info = mSubscriptionController
7313 .getSubscriptionInfo(subId);
7314 groupUuid = info.getGroupUuid();
7315 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007316 // If it doesn't belong to any group, return just subscriberId of itself.
7317 if (groupUuid == null) {
7318 return new String[]{subscriberId};
7319 }
7320
7321 // Get all subscriberIds from the group.
7322 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007323 List<SubscriptionInfo> groupInfos;
7324 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7325 groupInfos = SubscriptionManagerService.getInstance()
7326 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7327 mApp.getAttributionTag());
7328 } else {
7329 groupInfos = mSubscriptionController
7330 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7331 mApp.getAttributionTag());
7332 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007333 for (SubscriptionInfo subInfo : groupInfos) {
7334 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7335 if (subscriberId != null) {
7336 mergedSubscriberIds.add(subscriberId);
7337 }
7338 }
7339
7340 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343
7344 }
7345 }
7346
7347 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007348 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007349 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007350 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351
7352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 final Phone phone = getPhone(subId);
7355 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
7358 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007359 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007360
7361 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007362 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007363 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7364 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007365 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7366 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367
7368 final long identity = Binder.clearCallingIdentity();
7369 try {
7370 final Phone phone = getPhone(subId);
7371 if (phone == null) {
7372 return false;
7373 }
7374 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7375 cdmaNonRoamingList);
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007378 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007379 }
7380
7381 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007382 @Deprecated
7383 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7384 enforceModifyPermission();
7385
7386 int returnValue = 0;
7387 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007388 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007389 if(result.exception == null) {
7390 if (result.result != null) {
7391 byte[] responseData = (byte[])(result.result);
7392 if(responseData.length > oemResp.length) {
7393 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7394 responseData.length + "bytes. Buffer Size is " +
7395 oemResp.length + "bytes.");
7396 }
7397 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7398 returnValue = responseData.length;
7399 }
7400 } else {
7401 CommandException ex = (CommandException) result.exception;
7402 returnValue = ex.getCommandError().ordinal();
7403 if(returnValue > 0) returnValue *= -1;
7404 }
7405 } catch (RuntimeException e) {
7406 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7407 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7408 if(returnValue > 0) returnValue *= -1;
7409 }
7410
7411 return returnValue;
7412 }
7413
7414 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007415 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007416 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007417 try {
7418 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007419 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007420 mApp, phone.getSubId(), "getRadioAccessFamily");
7421 } catch (SecurityException e) {
7422 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7423 throw e;
7424 }
chen xub97461a2018-10-26 14:17:57 -07007425 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007426 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007427 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 final long identity = Binder.clearCallingIdentity();
7430 try {
chen xub97461a2018-10-26 14:17:57 -07007431 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007432 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007433 mApp, phone.getSubId(), "getRadioAccessFamily");
7434 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
chen xub97461a2018-10-26 14:17:57 -07007438 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007439 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007440
7441 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007442 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007443 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007444 try {
7445 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7446 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007447 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007448 }
7449 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007450 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007451 }
7452 RoleManager rm = mApp.getSystemService(RoleManager.class);
7453 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7454 if (!dialerRoleHolders.contains(callingPackage)) {
7455 throw new SecurityException("App must be the dialer role holder to"
7456 + " upload a call composer pic");
7457 }
7458
7459 Executors.newSingleThreadExecutor().execute(() -> {
7460 ByteArrayOutputStream output = new ByteArrayOutputStream(
7461 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7462 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7463 boolean readUntilEnd = false;
7464 int totalBytesRead = 0;
7465 byte[] buffer = new byte[16 * 1024];
7466 while (true) {
7467 int numRead;
7468 try {
7469 numRead = input.read(buffer);
7470 } catch (IOException e) {
7471 try {
7472 fd.checkError();
7473 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7474 null);
7475 } catch (IOException e1) {
7476 // This means that the other side closed explicitly with an error. If this
7477 // happens, log and ignore.
7478 loge("Remote end of call composer picture pipe closed: " + e1);
7479 }
7480 break;
7481 }
7482 if (numRead == -1) {
7483 readUntilEnd = true;
7484 break;
7485 }
7486 totalBytesRead += numRead;
7487 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7488 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7489 try {
7490 input.close();
7491 } catch (IOException e) {
7492 // ignore
7493 }
7494 break;
7495 }
7496 output.write(buffer, 0, numRead);
7497 }
7498 // Generally, the remote end will close the file descriptors. The only case where we
7499 // close is above, where the picture size is too big.
7500
7501 try {
7502 fd.checkError();
7503 } catch (IOException e) {
7504 loge("Remote end for call composer closed with an error: " + e);
7505 return;
7506 }
7507
Hall Liuaa4211e2021-01-20 15:43:39 -08007508 if (!readUntilEnd) {
7509 loge("Did not finish reading entire image; aborting");
7510 return;
7511 }
Hall Liu82694d52020-12-11 18:22:04 -08007512
Hall Liuaa4211e2021-01-20 15:43:39 -08007513 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7514 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7515 new CallComposerPictureTransfer.Factory() {},
7516 imageData,
7517 (result) -> {
7518 if (result.first != null) {
7519 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7520 Bundle outputResult = new Bundle();
7521 outputResult.putParcelable(
7522 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7523 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7524 outputResult);
7525 } else {
7526 callback.send(result.second, null);
7527 }
7528 }
7529 );
Hall Liu82694d52020-12-11 18:22:04 -08007530 });
7531 }
7532
7533 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007534 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007536 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 ImsManager.getInstance(defaultPhone.getContext(),
7541 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007545 }
7546
7547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007548 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7551 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007552 return false;
7553 }
Svet Ganovb320e182015-04-16 12:30:10 -07007554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 // Check the user preference and the system-level IMS setting. Even if the user has
7558 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7559 // In the long run, we may instead need to check if there exists a connection service
7560 // which can support video calling.
7561 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 return imsManager.isVtEnabledByPlatform()
7564 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7565 && imsManager.isVtEnabledByUser();
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007569 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007570
Andrew Leea1239f22015-03-02 17:44:07 -08007571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007572 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7573 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 mApp, subId, callingPackage, callingFeatureId,
7576 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 return false;
7578 }
7579
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 CarrierConfigManager configManager =
7583 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007584 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7586 } finally {
7587 Binder.restoreCallingIdentity(identity);
7588 }
Andrew Leea1239f22015-03-02 17:44:07 -08007589 }
7590
7591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007592 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007594 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 return false;
7596 }
7597
7598 final long identity = Binder.clearCallingIdentity();
7599 try {
7600 CarrierConfigManager configManager =
7601 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007602 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
Andrew Leea1239f22015-03-02 17:44:07 -08007607 }
7608
Andrew Lee9431b832015-03-09 18:46:45 -07007609 @Override
7610 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007611 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007612 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007613 }
7614
7615 @Override
7616 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 final long identity = Binder.clearCallingIdentity();
7618 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007619 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 } finally {
7621 Binder.restoreCallingIdentity(identity);
7622 }
Andrew Lee9431b832015-03-09 18:46:45 -07007623 }
7624
Hall Liuf6668912018-10-31 17:05:23 -07007625 /**
7626 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7627 * support for the feature and device firmware support.
7628 *
7629 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7630 */
7631 @Override
7632 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007634 final Phone phone = getPhone(subscriptionId);
7635 if (phone == null) {
7636 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7637 return false;
7638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7642 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 return isCarrierSupported && isDeviceSupported;
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
Hall Liu98187582018-01-22 19:15:32 -08007648 }
7649
Hall Liuf6668912018-10-31 17:05:23 -07007650 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007651 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7652 * RTT setting, will return true if the device and carrier both support RTT.
7653 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007654 */
7655 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 final long identity = Binder.clearCallingIdentity();
7657 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007658 boolean isRttSupported = isRttSupported(subscriptionId);
7659 boolean isUserRttSettingOn = Settings.Secure.getInt(
7660 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7661 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7662 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7663 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 } finally {
7665 Binder.restoreCallingIdentity(identity);
7666 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007667 }
7668
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007669 @Deprecated
7670 @Override
7671 public String getDeviceId(String callingPackage) {
7672 return getDeviceIdWithFeature(callingPackage, null);
7673 }
7674
Sanket Padawe7310cc72015-01-14 09:53:20 -08007675 /**
7676 * Returns the unique device ID of phone, for example, the IMEI for
7677 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7678 *
7679 * <p>Requires Permission:
7680 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7681 */
7682 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007683 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007684 try {
7685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7686 } catch (SecurityException se) {
7687 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7688 throw new SecurityException("Package " + callingPackage + " does not belong to "
7689 + Binder.getCallingUid());
7690 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007691 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007692 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007693 return null;
7694 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007695 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007696 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007698 return null;
7699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 return phone.getDeviceId();
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007707 }
7708
Ping Sunc67b7c22016-03-02 19:16:45 +08007709 /**
7710 * {@hide}
7711 * Returns the IMS Registration Status on a particular subid
7712 *
7713 * @param subId
7714 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007715 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007716 Phone phone = getPhone(subId);
7717 if (phone != null) {
7718 return phone.isImsRegistered();
7719 } else {
7720 return false;
7721 }
7722 }
7723
Santos Cordon7a1885b2015-02-03 11:15:19 -08007724 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007725 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007726 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007728 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007729 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7730 }
7731 final long identity = Binder.clearCallingIdentity();
7732 try {
7733 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
7736 }
7737 }
7738
7739 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007740 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007741 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007742 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007743 mApp,
7744 subscriptionId,
7745 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 Phone phone = getPhone(subscriptionId);
7749 if (phone == null) {
7750 return null;
7751 }
7752 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
7755 }
7756 }
7757
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007758 /**
7759 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007760 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007761 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 final long identity = Binder.clearCallingIdentity();
7763 try {
7764 Phone phone = getPhone(subId);
7765 if (phone != null) {
7766 return phone.isWifiCallingEnabled();
7767 } else {
7768 return false;
7769 }
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007772 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007773 }
7774
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007775 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007776 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007777 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007778 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 final long identity = Binder.clearCallingIdentity();
7780 try {
7781 Phone phone = getPhone(subId);
7782 if (phone != null) {
7783 return phone.isVideoEnabled();
7784 } else {
7785 return false;
7786 }
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007789 }
7790 }
7791
7792 /**
7793 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7794 * defined in {@link ImsRegistrationImplBase}.
7795 */
7796 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 final long identity = Binder.clearCallingIdentity();
7798 try {
7799 Phone phone = getPhone(subId);
7800 if (phone != null) {
7801 return phone.getImsRegistrationTech();
7802 } else {
7803 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7804 }
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007807 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007808 }
7809
Stuart Scott8eef64f2015-04-08 15:13:54 -07007810 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007811 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007812 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007813 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7814 return;
7815 }
Kai Shif70f46f2021-03-03 13:59:46 -08007816 Phone defaultPhone = getDefaultPhone();
7817 if (defaultPhone != null) {
7818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7819 mApp, getDefaultPhone().getSubId(), "factoryReset");
7820 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007821 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007822
Svet Ganovcc087f82015-05-12 20:35:54 -07007823 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007824 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7825 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007826 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007827 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007828 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007829 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007830 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007831 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007832 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007833 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007834 // There has been issues when Sms raw table somehow stores orphan
7835 // fragments. They lead to garbled message when new fragments come
7836 // in and combined with those stale ones. In case this happens again,
7837 // user can reset all network settings which will clean up this table.
7838 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007839 // Clean up IMS settings as well here.
7840 int slotId = getSlotIndex(subId);
7841 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7842 ImsManager.getInstance(mApp, slotId).factoryReset();
7843 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007844
Kai Shif70f46f2021-03-03 13:59:46 -08007845 if (defaultPhone == null) {
7846 return;
7847 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007848 // Erase modem config if erase modem on network setting is enabled.
7849 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7850 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7851 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007852 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007853 }
Kai Shif70f46f2021-03-03 13:59:46 -08007854
7855 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007856 } finally {
7857 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007858 }
7859 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860
SongFerngWangfd89b102021-05-27 22:44:54 +08007861 @VisibleForTesting
7862 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7863 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7864 return;
7865 }
7866 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7867 RILConstants.PREFERRED_NETWORK_MODE);
7868 SubscriptionManager.setSubscriptionProperty(subId,
7869 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7870 "user=" + defaultNetworkType);
7871 phone.loadAllowedNetworksFromSubscriptionDatabase();
7872 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7873 defaultNetworkType, null);
7874 }
7875
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007876 private void cleanUpSmsRawTable(Context context) {
7877 ContentResolver resolver = context.getContentResolver();
7878 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7879 resolver.delete(uri, null, null);
7880 }
7881
Narayan Kamath1c496c22015-04-16 14:40:19 +01007882 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007883 public String getSimLocaleForSubscriber(int subId) {
7884 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7885 final Phone phone = getPhone(subId);
7886 if (phone == null) {
7887 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007888 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890 final long identity = Binder.clearCallingIdentity();
7891 try {
Jack Yu285100e2022-12-02 22:48:35 -08007892 SubscriptionInfo info;
7893 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7894 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7895 phone.getContext().getOpPackageName(),
7896 phone.getContext().getAttributionTag());
7897 if (info == null) {
7898 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7899 return null;
7900 }
7901 } else {
7902 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7903 phone.getContext().getOpPackageName(),
7904 phone.getContext().getAttributionTag());
7905 if (info == null) {
7906 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7907 return null;
7908 }
chen xu6291c472019-02-04 12:55:53 -08007909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 // Try and fetch the locale from the carrier properties or from the SIM language
7911 // preferences (EF-PL and EF-LI)...
7912 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007914 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7915 if (localeFromDefaultSim != null) {
7916 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7917 if (DBG) log("Using locale from subId: " + subId + " locale: "
7918 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007919 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007920 } else {
7921 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 }
7923 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 // The SIM language preferences only store a language (e.g. fr = French), not an
7926 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7927 // the SIM and carrier preferences does not include a country we add the country
7928 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007929 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007931 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007932 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 }
7934
7935 if (DBG) log("No locale found - returning null");
7936 return null;
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
7939 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007940 }
7941
tom hsu0b59d292022-09-29 23:49:21 +08007942 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007943 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007944 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007945 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007946 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007947 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7948 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007949 Locale.forLanguageTag(localeTag).getCountry())) {
7950 return localeTag;
7951 }
7952 }
7953 return inputLocale.toLanguageTag();
7954 }
7955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 /**
7957 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7958 */
7959 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007960 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7961 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7962 mApp.getOpPackageName(), mApp.getAttributionTag());
7963 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007964 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007965 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007966 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007967
Gary Jian3aa9a762022-01-24 16:41:19 +08007968 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7969 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007970
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007971 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007972 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7973 * representing the state of the modem.
7974 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007975 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7976 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007977 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007978 */
7979 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007980 public void requestModemActivityInfo(ResultReceiver result) {
7981 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007982 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983
7984 final long identity = Binder.clearCallingIdentity();
7985 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007986 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 } finally {
7988 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007989 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007990 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007991
Siddharth Rayb8114062018-06-17 15:02:38 -07007992 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7993 // less than total activity duration.
7994 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7995 if (info == null) {
7996 return false;
7997 }
7998 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007999 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
8000 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8001
Siddharth Rayb8114062018-06-17 15:02:38 -07008002 return (info.isValid()
8003 && (info.getSleepTimeMillis() <= activityDurationMs)
8004 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07008005 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07008006 && (totalTxTimeMs <= activityDurationMs));
8007 }
8008
Gary Jian3aa9a762022-01-24 16:41:19 +08008009 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8010 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8011 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8012 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8013
8014 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8015 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8016 }
8017
8018 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8019 mLastModemActivityInfo.setReceiveTimeMillis(
8020 rat,
8021 freq,
8022 info.getReceiveTimeMillis(rat, freq)
8023 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8024 }
8025
8026 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8027 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8028 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8029 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8030
8031 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8032 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8033 }
8034 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8035 mLastModemActivityInfo.setReceiveTimeMillis(
8036 rat,
8037 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8038 }
8039
8040 /**
8041 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8042 * @param info recent ModemActivityInfo
8043 */
8044 private void mergeModemActivityInfo(ModemActivityInfo info) {
8045 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008046 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008047 boolean matched;
8048 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8049 matched = false;
8050 int rat = info.getSpecificInfoRat(i);
8051 int freq = info.getSpecificInfoFrequencyRange(i);
8052 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8053 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8054 //if it already exists
8055 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8056 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8057 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8058 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8059 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8060 updateLastModemActivityInfo(info, rat, freq);
8061 matched = true;
8062 }
8063 } else {
8064 updateLastModemActivityInfo(info, rat);
8065 matched = true;
8066 }
8067 }
8068 }
8069
8070 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008071 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008072 new ActivityStatsTechSpecificInfo(
8073 rat,
8074 freq,
8075 info.getTransmitTimeMillis(rat, freq),
8076 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008077 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008078 }
8079 }
8080 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8081 mLastModemActivitySpecificInfo =
8082 new ActivityStatsTechSpecificInfo[merged.size()];
8083 merged.toArray(mLastModemActivitySpecificInfo);
8084
8085 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8086 mLastModemActivityInfo.setSleepTimeMillis(
8087 info.getSleepTimeMillis()
8088 + mLastModemActivityInfo.getSleepTimeMillis());
8089 mLastModemActivityInfo.setIdleTimeMillis(
8090 info.getIdleTimeMillis()
8091 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008092
8093 mLastModemActivityInfo =
8094 new ModemActivityInfo(
8095 mLastModemActivityInfo.getTimestampMillis(),
8096 mLastModemActivityInfo.getSleepTimeMillis(),
8097 mLastModemActivityInfo.getIdleTimeMillis(),
8098 mLastModemActivitySpecificInfo);
8099 }
8100
8101 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8102 ActivityStatsTechSpecificInfo[] info) {
8103 int infoSize = info.length;
8104 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8105 for (int i = 0; i < infoSize; i++) {
8106 ret[i] = new ActivityStatsTechSpecificInfo(
8107 info[i].getRat(), info[i].getFrequencyRange(),
8108 info[i].getTransmitTimeMillis(),
8109 (int) info[i].getReceiveTimeMillis());
8110 }
8111 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008112 }
8113
Jack Yu85bd38a2015-11-09 11:34:32 -08008114 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008115 * Returns the service state information on specified subscription.
8116 */
8117 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008118 public ServiceState getServiceStateForSubscriber(int subId,
8119 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8120 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008122 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008123 return null;
8124 }
8125
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008126 boolean hasFinePermission = false;
8127 boolean hasCoarsePermission = false;
8128 if (!renounceFineLocationAccess) {
8129 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8130 LocationAccessPolicy.checkLocationPermission(mApp,
8131 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8132 .setCallingPackage(callingPackage)
8133 .setCallingFeatureId(callingFeatureId)
8134 .setCallingPid(Binder.getCallingPid())
8135 .setCallingUid(Binder.getCallingUid())
8136 .setMethod("getServiceStateForSubscriber")
8137 .setLogAsInfo(true)
8138 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8139 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8140 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8141 .build());
8142 hasFinePermission =
8143 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8144 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008145
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008146 if (!renounceCoarseLocationAccess) {
8147 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8148 LocationAccessPolicy.checkLocationPermission(mApp,
8149 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8150 .setCallingPackage(callingPackage)
8151 .setCallingFeatureId(callingFeatureId)
8152 .setCallingPid(Binder.getCallingPid())
8153 .setCallingUid(Binder.getCallingUid())
8154 .setMethod("getServiceStateForSubscriber")
8155 .setLogAsInfo(true)
8156 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8157 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8158 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8159 .build());
8160 hasCoarsePermission =
8161 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8162 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008163
Jack Yu479f40e2020-10-27 21:29:25 -07008164 final Phone phone = getPhone(subId);
8165 if (phone == null) {
8166 return null;
8167 }
8168
Jordan Liu0f2bc442020-11-18 16:47:37 -08008169 final long identity = Binder.clearCallingIdentity();
8170
Jack Yu479f40e2020-10-27 21:29:25 -07008171 boolean isCallingPackageDataService = phone.getDataServicePackages()
8172 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008174 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008175 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8176 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8177 .getSubscriptionInfoInternal(subId);
8178 if (subInfo == null || !subInfo.isActive()) {
8179 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8180 + "subId=" + subId);
8181 return null;
8182 }
8183 } else {
8184 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8185 callingFeatureId)) {
8186 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8187 + "subId=" + subId);
8188 return null;
8189 }
Jordan Liuc437b192020-08-17 10:59:12 -07008190 }
8191
Hall Liuf19c44f2018-11-27 14:38:17 -08008192 ServiceState ss = phone.getServiceState();
8193
8194 // Scrub out the location info in ServiceState depending on what level of access
8195 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008196 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008197 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8198 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008202 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008203
8204 /**
8205 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8206 *
8207 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8208 * voicemail ringtone.
8209 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8210 * PhoneAccount.
8211 */
8212 @Override
8213 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8217 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008218 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
8224 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008225 }
8226
8227 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008228 * Sets the per-account voicemail ringtone.
8229 *
8230 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8231 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8232 *
8233 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8234 * voicemail ringtone.
8235 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8236 * PhoneAccount.
8237 */
8238 @Override
8239 public void setVoicemailRingtoneUri(String callingPackage,
8240 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008241 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008243 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8244 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8246 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8247 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
8252 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8253 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008254 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 }
8256 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008259 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008260 }
8261
8262 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008263 * Returns whether vibration is set for voicemail notification in Phone settings.
8264 *
8265 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8266 * voicemail vibration setting.
8267 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8268 */
8269 @Override
8270 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8274 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008275 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008282 }
8283
Youhan Wange64578a2016-05-02 15:32:42 -07008284 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008285 * Sets the per-account voicemail vibration.
8286 *
8287 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8288 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8289 *
8290 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8291 * voicemail vibration setting.
8292 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8293 * specific PhoneAccount.
8294 */
8295 @Override
8296 public void setVoicemailVibrationEnabled(String callingPackage,
8297 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008298 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008299 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008300 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8301 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8303 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8304 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008305 }
8306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 final long identity = Binder.clearCallingIdentity();
8308 try {
8309 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8310 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008311 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 }
8313 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8314 } finally {
8315 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008316 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008317 }
8318
8319 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008320 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8321 *
8322 * @throws SecurityException if the caller does not have the required permission
8323 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008324 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008326 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008327 }
8328
8329 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008330 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8331 * permission.
8332 *
8333 * @throws SecurityException if the caller does not have the required permission
8334 */
8335 private void enforceSendSmsPermission() {
8336 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8337 }
8338
8339 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008340 * Make sure either called from same process as self (phone) or IPC caller has interact across
8341 * users permission.
8342 *
8343 * @throws SecurityException if the caller does not have the required permission
8344 */
8345 private void enforceInteractAcrossUsersPermission(String message) {
8346 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8347 }
8348
8349 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008350 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008351 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008352 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008353 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008354 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 final long identity = Binder.clearCallingIdentity();
8356 try {
8357 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008358 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359 if (componentName == null) {
8360 throw new SecurityException(
8361 "Caller not current active visual voicemail package[null]");
8362 }
8363 String vvmPackage = componentName.getPackageName();
8364 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008365 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 }
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008369 }
8370 }
8371
8372 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008373 * Return the application ID for the app type.
8374 *
8375 * @param subId the subscription ID that this request applies to.
8376 * @param appType the uicc app type.
8377 * @return Application ID for specificied app type, or null if no uicc.
8378 */
8379 @Override
8380 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008381 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008382 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383
8384 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008385 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 if (phone == null) {
8387 return null;
8388 }
8389 String aid = null;
8390 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008391 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 .getApplicationByType(appType).getAid();
8393 } catch (Exception e) {
8394 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8395 }
8396 return aid;
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008399 }
Youhan Wange64578a2016-05-02 15:32:42 -07008400 }
8401
Youhan Wang4001d252016-05-11 10:29:41 -07008402 /**
8403 * Return the Electronic Serial Number.
8404 *
8405 * @param subId the subscription ID that this request applies to.
8406 * @return ESN or null if error.
8407 */
8408 @Override
8409 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008410 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008411 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412
8413 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008414 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415 if (phone == null) {
8416 return null;
8417 }
8418 String esn = null;
8419 try {
8420 esn = phone.getEsn();
8421 } catch (Exception e) {
8422 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8423 }
8424 return esn;
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008427 }
Youhan Wang4001d252016-05-11 10:29:41 -07008428 }
8429
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008430 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008431 * Return the Preferred Roaming List Version.
8432 *
8433 * @param subId the subscription ID that this request applies to.
8434 * @return PRLVersion or null if error.
8435 */
8436 @Override
8437 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008438 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008439 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440
8441 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008442 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008443 if (phone == null) {
8444 return null;
8445 }
8446 String cdmaPrlVersion = null;
8447 try {
8448 cdmaPrlVersion = phone.getCdmaPrlVersion();
8449 } catch (Exception e) {
8450 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8451 }
8452 return cdmaPrlVersion;
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008455 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008456 }
8457
8458 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008459 * Get snapshot of Telephony histograms
8460 * @return List of Telephony histograms
8461 * @hide
8462 */
8463 @Override
8464 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8466 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 return RIL.getTelephonyRILTimingHistograms();
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008474 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008475
8476 /**
8477 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008478 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8479 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008480 * Require system privileges. In the future we may add this to carrier APIs.
8481 *
Michele Berionne482f8202018-11-27 18:57:59 -08008482 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008483 */
8484 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008485 @TelephonyManager.SetCarrierRestrictionResult
8486 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008487 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008489
Michele Berionne482f8202018-11-27 18:57:59 -08008490 if (carrierRestrictionRules == null) {
8491 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008492 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 final long identity = Binder.clearCallingIdentity();
8495 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008496 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008497 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008498 } finally {
8499 Binder.restoreCallingIdentity(identity);
8500 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008501 }
8502
8503 /**
8504 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008505 * Get the allowed carrier list and the excluded carrier list, including the priority between
8506 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008507 * Require system privileges. In the future we may add this to carrier APIs.
8508 *
Michele Berionne482f8202018-11-27 18:57:59 -08008509 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008510 */
8511 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008512 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008513 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008518 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8519 if (response instanceof CarrierRestrictionRules) {
8520 return (CarrierRestrictionRules) response;
8521 }
8522 // Response is an Exception of some kind,
8523 // which is signalled to the user as a NULL retval
8524 return null;
8525 } catch (Exception e) {
8526 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8527 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528 } finally {
8529 Binder.restoreCallingIdentity(identity);
8530 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008531 }
8532
fionaxu59545b42016-05-25 15:53:37 -07008533 /**
fionaxu59545b42016-05-25 15:53:37 -07008534 * Action set from carrier signalling broadcast receivers to enable/disable radio
8535 * @param subId the subscription ID that this action applies to.
8536 * @param enabled control enable or disable radio.
8537 * {@hide}
8538 */
8539 @Override
8540 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8541 enforceModifyPermission();
8542 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543
8544 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008545 if (phone == null) {
8546 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8547 return;
8548 }
8549 try {
8550 phone.carrierActionSetRadioEnabled(enabled);
8551 } catch (Exception e) {
8552 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553 } finally {
8554 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008555 }
8556 }
8557
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008558 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008559 * Enable or disable Voice over NR (VoNR)
8560 * @param subId the subscription ID that this action applies to.
8561 * @param enabled enable or disable VoNR.
8562 * @return operation result.
8563 */
8564 @Override
8565 public int setVoNrEnabled(int subId, boolean enabled) {
8566 enforceModifyPermission();
8567 final Phone phone = getPhone(subId);
8568
8569 final long identity = Binder.clearCallingIdentity();
8570 if (phone == null) {
8571 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8572 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8573 }
8574
8575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8576 try {
8577 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8578 workSource);
8579 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008580
8581 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8582 if (DBG) {
8583 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8584 }
8585 SubscriptionManager.setSubscriptionProperty(
8586 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8587 (enabled ? "1" : "0"));
8588 }
8589
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008590 return result;
8591 } finally {
8592 Binder.restoreCallingIdentity(identity);
8593 }
8594 }
8595
8596 /**
8597 * Is voice over NR enabled
8598 * @return true if VoNR is enabled else false
8599 */
8600 @Override
8601 public boolean isVoNrEnabled(int subId) {
8602 enforceReadPrivilegedPermission("isVoNrEnabled");
8603 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8607 null, subId, workSource);
8608 if (DBG) log("isVoNrEnabled: " + isEnabled);
8609 return isEnabled;
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
8612 }
8613 }
8614
8615 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008616 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8617 * network status based on which carrier apps could apply actions accordingly,
8618 * enable/disable default url handler for example.
8619 *
8620 * @param subId the subscription ID that this action applies to.
8621 * @param report control start/stop reporting the default network status.
8622 * {@hide}
8623 */
8624 @Override
8625 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8626 enforceModifyPermission();
8627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008628
8629 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008630 if (phone == null) {
8631 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8632 return;
8633 }
8634 try {
8635 phone.carrierActionReportDefaultNetworkStatus(report);
8636 } catch (Exception e) {
8637 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638 } finally {
8639 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008640 }
8641 }
8642
8643 /**
fionaxud9622282017-07-17 17:51:30 -07008644 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8645 * @param subId the subscription ID that this action applies to.
8646 * {@hide}
8647 */
8648 @Override
8649 public void carrierActionResetAll(int subId) {
8650 enforceModifyPermission();
8651 final Phone phone = getPhone(subId);
8652 if (phone == null) {
8653 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8654 return;
8655 }
8656 try {
8657 phone.carrierActionResetAll();
8658 } catch (Exception e) {
8659 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8660 }
8661 }
8662
8663 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008664 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8665 * bug report is being generated.
8666 */
8667 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008668 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008669 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8670 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008671 writer.println("Permission Denial: can't dump Phone from pid="
8672 + Binder.getCallingPid()
8673 + ", uid=" + Binder.getCallingUid()
8674 + "without permission "
8675 + android.Manifest.permission.DUMP);
8676 return;
8677 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008678 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008679 }
Jack Yueb89b242016-06-22 13:27:47 -07008680
Brad Ebingerdac2f002018-04-03 15:17:52 -07008681 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008682 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8683 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8684 @NonNull String[] args) {
8685 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8686 this, in.getFileDescriptor(), out.getFileDescriptor(),
8687 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008688 }
8689
Jack Yueb89b242016-06-22 13:27:47 -07008690 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008691 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008692 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008693 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008694 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008695 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008696 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008697 */
8698 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008699 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008700 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008701 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8702 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8703 try {
8704 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008705 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008706 } catch (SecurityException se) {
8707 enforceModifyPermission();
8708 }
8709 } else {
8710 enforceModifyPermission();
8711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008712
8713 final long identity = Binder.clearCallingIdentity();
8714 try {
8715 Phone phone = getPhone(subId);
8716 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008717 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8718 phone.carrierActionSetMeteredApnsEnabled(enabled);
8719 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008720 phone.getDataSettingsManager().setDataEnabled(
8721 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008723 }
8724 } finally {
8725 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008726 }
8727 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008728
8729 /**
8730 * Get Client request stats
8731 * @return List of Client Request Stats
8732 * @hide
8733 */
8734 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008735 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8736 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008738 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008739 return null;
8740 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008741 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 if (phone != null) {
8746 return phone.getClientRequestStats();
8747 }
8748
8749 return null;
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008753 }
8754
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008755 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008756 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008757 if (uid == Process.ROOT_UID && packageName == null) {
8758 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8759 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8760 // exception. ROOT_UID seems not to have a valid package name returned by
8761 // PackageManager, so just fake it here to avoid issues when running telephony shell
8762 // commands that plumb through the RIL as root, like so:
8763 // $ adb root
8764 // $ adb shell cmd phone ...
8765 packageName = "root";
8766 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008767 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008768 }
Jack Yueb4124c2017-02-16 15:32:43 -08008769
8770 /**
Grace Chen70990072017-03-24 17:21:30 -07008771 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008772 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008773 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008774 * @param state State of SIM (power down, power up, pass through)
8775 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8776 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8777 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008778 *
8779 **/
8780 @Override
Grace Chen70990072017-03-24 17:21:30 -07008781 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008782 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008783 Phone phone = PhoneFactory.getPhone(slotIndex);
8784
vagdeviaf9a5b92018-08-15 16:01:53 -07008785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008790 phone.setSimPowerState(state, null, workSource);
8791 }
8792 } finally {
8793 Binder.restoreCallingIdentity(identity);
8794 }
8795 }
8796
8797 /**
8798 * Set SIM card power state.
8799 *
8800 * @param slotIndex SIM slot id.
8801 * @param state State of SIM (power down, power up, pass through)
8802 * @param callback callback to trigger after success or failure
8803 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8804 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8805 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8806 *
8807 **/
8808 @Override
8809 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8810 IIntegerConsumer callback) {
8811 enforceModifyPermission();
8812 Phone phone = PhoneFactory.getPhone(slotIndex);
8813
8814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8815
8816 final long identity = Binder.clearCallingIdentity();
8817 try {
8818 if (phone != null) {
8819 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8820 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008821 }
8822 } finally {
8823 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008824 }
8825 }
Shuo Qiandd210312017-04-12 22:11:33 +00008826
Tyler Gunn65d45c22017-06-05 11:22:26 -07008827 private boolean isUssdApiAllowed(int subId) {
8828 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008829 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008830 if (configManager == null) {
8831 return false;
8832 }
8833 PersistableBundle pb = configManager.getConfigForSubId(subId);
8834 if (pb == null) {
8835 return false;
8836 }
8837 return pb.getBoolean(
8838 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8839 }
8840
Shuo Qiandd210312017-04-12 22:11:33 +00008841 /**
8842 * Check if phone is in emergency callback mode
8843 * @return true if phone is in emergency callback mode
8844 * @param subId sub id
8845 */
goneil9c5f4872017-12-05 14:07:56 -08008846 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008847 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008848 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008849 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850
8851 final long identity = Binder.clearCallingIdentity();
8852 try {
8853 if (phone != null) {
8854 return phone.isInEcm();
8855 } else {
8856 return false;
8857 }
8858 } finally {
8859 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008860 }
8861 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008862
8863 /**
8864 * Get the current signal strength information for the given subscription.
8865 * Because this information is not updated when the device is in a low power state
8866 * it should not be relied-upon to be current.
8867 * @param subId Subscription index
8868 * @return the most recent cached signal strength info from the modem
8869 */
8870 @Override
8871 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008872 final long identity = Binder.clearCallingIdentity();
8873 try {
8874 Phone p = getPhone(subId);
8875 if (p == null) {
8876 return null;
8877 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008879 return p.getSignalStrength();
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008883 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008884
Pengquan Meng77b7f132018-08-22 14:49:57 -07008885 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008886 * Get the current modem radio state for the given slot.
8887 * @param slotIndex slot index.
8888 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008890 * @return the current radio power state from the modem
8891 */
8892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008894 Phone phone = PhoneFactory.getPhone(slotIndex);
8895 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8897 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008898 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8899 }
8900
8901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 return phone.getRadioPowerState();
8904 } finally {
8905 Binder.restoreCallingIdentity(identity);
8906 }
8907 }
8908 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8909 }
8910
8911 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008912 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8913 *
8914 * <p>Requires one of the following permissions:
8915 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008916 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008917 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8918 * privileges.
8919 *
8920 * @param subId subscription id
8921 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8922 * {@code false}.
8923 */
8924 @Override
8925 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008926 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008927 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008928 try {
8929 mApp.enforceCallingOrSelfPermission(
8930 android.Manifest.permission.ACCESS_NETWORK_STATE,
8931 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008932 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008933 mApp.enforceCallingOrSelfPermission(
8934 permission.READ_BASIC_PHONE_STATE, functionName);
8935 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008936 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008937 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008938 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008939 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008940
Pengquan Menga1bb6272018-09-06 09:59:22 -07008941 boolean isEnabled = false;
8942 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008943 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008944 Phone phone = getPhone(subId);
8945 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008946 } finally {
8947 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008948 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008949 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008950 }
8951
8952
8953 /**
8954 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8955 *
8956 * <p> Requires permission:
8957 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8958 * privileges.
8959 *
8960 * @param subId subscription id
8961 * @param isEnabled {@code true} means enable, {@code false} means disable.
8962 */
8963 @Override
8964 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8966 mApp, subId, "setDataRoamingEnabled");
8967
Pengquan Menga1bb6272018-09-06 09:59:22 -07008968 final long identity = Binder.clearCallingIdentity();
8969 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008970 Phone phone = getPhone(subId);
8971 if (phone != null) {
8972 phone.setDataRoamingEnabled(isEnabled);
8973 }
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008976 }
8977 }
8978
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008979 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008980 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008981 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008982 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008983 mApp, subId, "isManualNetworkSelectionAllowed");
8984
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008985 boolean isAllowed = true;
8986 final long identity = Binder.clearCallingIdentity();
8987 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008988 Phone phone = getPhone(subId);
8989 if (phone != null) {
8990 isAllowed = phone.isCspPlmnEnabled();
8991 }
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
8995 return isAllowed;
8996 }
8997
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008998 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8999 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009000 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009001 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009002 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009003 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9004 if (phone == null) {
9005 return false;
9006 }
9007 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9008 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9009 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009010 }
9011
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009012 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009013 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009014 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009015 mApp.getSystemService(AppOpsManager.class)
9016 .checkPackage(Binder.getCallingUid(), callingPackage);
9017
Jordan Liu1e142fc2019-04-22 15:10:43 -07009018 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009019 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009020 try {
9021 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009022 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009023 } catch (SecurityException e) {
9024 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9025 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009026 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009027 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009028 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009029 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009030 }
sandeepjsb6c87872021-09-27 15:34:44 +00009031 // checking compatibility, if calling app's target SDK is T and beyond.
9032 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9033 Binder.getCallingUid())) {
9034 isIccIdAccessRestricted = true;
9035 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009036 final long identity = Binder.clearCallingIdentity();
9037 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009038 UiccController uiccController = UiccController.getInstance();
9039 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009040 if (hasReadPermission) {
9041 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009042 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009043
9044 // Remove private info if the caller doesn't have access
9045 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9046 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009047 //setting the value after compatibility check
9048 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009049 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9050 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009051 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009052 if (card == null) {
9053 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009054 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009055 continue;
9056 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009057 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9058 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009059 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009060 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009061 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009062 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9063 for (UiccPortInfo portInfo : portInfos) {
9064 UiccPort port = uiccController.getUiccPortForSlot(
9065 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9066 if (port == null) {
9067 // assume no access if port is null
9068 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9069 continue;
9070 }
9071 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9072 uiccPortInfos.add(portInfo);
9073 } else {
9074 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9075 }
9076 }
9077 filteredInfos.add(new UiccCardInfo(
9078 cardInfo.isEuicc(),
9079 cardInfo.getCardId(),
9080 null,
9081 cardInfo.getPhysicalSlotIndex(),
9082 cardInfo.isRemovable(),
9083 cardInfo.isMultipleEnabledProfilesSupported(),
9084 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009085 }
9086 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009087 } finally {
9088 Binder.restoreCallingIdentity(identity);
9089 }
9090 }
9091
sandeepjsb6c87872021-09-27 15:34:44 +00009092 /**
9093 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9094 * generally private and require carrier privileges to view.
9095 *
9096 * @hide
9097 */
9098 @NonNull
9099 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9100 List<UiccPortInfo> portinfo = new ArrayList<>();
9101 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9102 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9103 }
9104 return new UiccCardInfo(
9105 cardInfo.isEuicc(),
9106 cardInfo.getCardId(),
9107 null,
9108 cardInfo.getPhysicalSlotIndex(),
9109 cardInfo.isRemovable(),
9110 cardInfo.isMultipleEnabledProfilesSupported(),
9111 portinfo
9112 );
9113 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009114
sandeepjsb6c87872021-09-27 15:34:44 +00009115 /**
9116 * @hide
9117 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9118 * These values are generally private and require carrier privileges to view.
9119 */
9120 @NonNull
9121 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9122 return new UiccPortInfo(
9123 UiccPortInfo.ICCID_REDACTED,
9124 portInfo.getPortIndex(),
9125 portInfo.getLogicalSlotIndex(),
9126 portInfo.isActive()
9127 );
9128 }
9129 @Override
9130 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009131 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009132 mApp.getSystemService(AppOpsManager.class)
9133 .checkPackage(Binder.getCallingUid(), callingPackage);
9134
sandeepjsb6c87872021-09-27 15:34:44 +00009135 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009136
Aman Guptaf3c90b32022-03-17 04:54:16 +00009137 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9138 // we are reading iccId which is PII data.
9139 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009140
9141 // checking compatibility, if calling app's target SDK is T and beyond.
9142 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9143 Binder.getCallingUid())) {
9144 isLogicalSlotAccessRestricted = true;
9145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146 final long identity = Binder.clearCallingIdentity();
9147 try {
9148 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009149 if (slots == null || slots.length == 0) {
9150 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009151 return null;
9152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9154 for (int i = 0; i < slots.length; i++) {
9155 UiccSlot slot = slots[i];
9156 if (slot == null) {
9157 continue;
9158 }
9159
Jordan Liu7be7e652019-05-06 18:55:02 +00009160 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161 UiccCard card = slot.getUiccCard();
9162 if (card != null) {
9163 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009164 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009165 cardId = slot.getEid();
9166 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009167 // If cardId is null, use iccId of default port as cardId.
9168 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009170 }
9171
Jordan Liu857451f2019-05-09 16:35:35 -07009172 if (cardId != null) {
9173 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9174 // if cardId is an EID, it's all digits so this is fine
9175 cardId = IccUtils.stripTrailingFs(cardId);
9176 }
9177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009178 int cardState = 0;
9179 switch (slot.getCardState()) {
9180 case CARDSTATE_ABSENT:
9181 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9182 break;
9183 case CARDSTATE_PRESENT:
9184 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9185 break;
9186 case CARDSTATE_ERROR:
9187 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9188 break;
9189 case CARDSTATE_RESTRICTED:
9190 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9191 break;
9192 default:
9193 break;
9194
9195 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009196 List<UiccPortInfo> portInfos = new ArrayList<>();
9197 int[] portIndexes = slot.getPortList();
9198 for (int portIdx : portIndexes) {
9199 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009200 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009201 portInfos.add(new UiccPortInfo(iccId, portIdx,
9202 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009204 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009205 slot.isEuicc(),
9206 cardId,
9207 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009208 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009209 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009210 //setting the value after compatibility check
9211 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009212 }
9213 return infos;
9214 } finally {
9215 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009216 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009217 }
9218
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009219 /* Returns null if doesn't have read permission or carrier privilege access. */
9220 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9221 boolean hasReadPermission) {
9222 String iccId = slot.getIccId(portIndex);
9223 if (hasReadPermission) { // if has read permission
9224 return iccId;
9225 } else {
9226 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9227 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9228 // if no read permission, checking carrier privilege access
9229 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9230 return iccId;
9231 }
9232 }
9233 }
9234 // No read permission or carrier privilege access.
9235 return UiccPortInfo.ICCID_REDACTED;
9236 }
9237
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009238 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009239 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009240 public boolean switchSlots(int[] physicalSlots) {
9241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009242
9243 final long identity = Binder.clearCallingIdentity();
9244 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009245 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9246 for (int i = 0; i < physicalSlots.length; i++) {
9247 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9248 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9249 physicalSlots[i], i));
9250 }
9251 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009255 }
Jack Yu4c988042018-02-27 15:30:01 -08009256
9257 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009258 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9259 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9260 enforceModifyPermission();
9261
9262 final long identity = Binder.clearCallingIdentity();
9263 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009264 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009265 } finally {
9266 Binder.restoreCallingIdentity(identity);
9267 }
9268 }
9269
9270 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009271 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009272 final long identity = Binder.clearCallingIdentity();
9273 try {
9274 return UiccController.getInstance().getCardIdForDefaultEuicc();
9275 } finally {
9276 Binder.restoreCallingIdentity(identity);
9277 }
9278 }
9279
Pengquan Meng85728fb2018-03-12 16:31:21 -07009280 /**
goneil47ffb6e2018-04-06 15:40:58 -07009281 * A test API to reload the UICC profile.
9282 *
9283 * <p>Requires that the calling app has permission
9284 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9285 * @hide
9286 */
9287 @Override
9288 public void refreshUiccProfile(int subId) {
9289 enforceModifyPermission();
9290
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 Phone phone = getPhone(subId);
9294 if (phone == null) {
9295 return;
9296 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009297 UiccPort uiccPort = phone.getUiccPort();
9298 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009299 return;
9300 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009301 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009302 if (uiccProfile == null) {
9303 return;
9304 }
9305 uiccProfile.refresh();
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 }
9310
9311 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009312 * Returns false if the mobile data is disabled by default, otherwise return true.
9313 */
9314 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009315 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009316 }
9317
9318 /**
9319 * Returns true if the data roaming is enabled by default, i.e the system property
9320 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9321 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9322 */
9323 private boolean getDefaultDataRoamingEnabled(int subId) {
9324 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009325 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009326 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009327 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9328 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9329 return isDataRoamingEnabled;
9330 }
9331
9332 /**
9333 * Returns the default network type for the given {@code subId}, if the default network type is
9334 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9335 */
9336 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009337 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009338 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009339 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9340 return list.get(phoneId);
9341 }
9342 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009343 }
fionaxua13278b2018-03-21 00:08:13 -07009344
9345 @Override
9346 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009347 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 final Phone phone = getPhone(subId);
9353 if (phone == null) {
9354 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9355 return;
9356 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009357 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9358 if (cpt != null) {
9359 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9360 }
9361 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009362 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9363 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009364 if (carrierPrivilegeRules == null) {
9365 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9366 } else {
9367 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009369 } finally {
9370 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009371 }
fionaxua13278b2018-03-21 00:08:13 -07009372 }
9373
9374 @Override
9375 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009376 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009377
9378 final long identity = Binder.clearCallingIdentity();
9379 try {
9380 final Phone phone = getPhone(subId);
9381 if (phone == null) {
9382 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9383 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9384 }
9385 return phone.getCarrierIdListVersion();
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009388 }
fionaxua13278b2018-03-21 00:08:13 -07009389 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009390
9391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009392 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9393 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009395 mApp, subId, callingPackage, callingFeatureId,
9396 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009397 return -1;
9398 }
9399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009407
9408 @Override
9409 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009410 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009411 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009412 mApp, subId, "getCdmaRoamingMode");
9413
9414 final long identity = Binder.clearCallingIdentity();
9415 try {
9416 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
9422 @Override
9423 public boolean setCdmaRoamingMode(int subId, int mode) {
9424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9425 mApp, subId, "setCdmaRoamingMode");
9426
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
9435 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009436 public int getCdmaSubscriptionMode(int subId) {
9437 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009438 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009439 mApp, subId, "getCdmaSubscriptionMode");
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
9447 }
9448
9449 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009450 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9452 mApp, subId, "setCdmaSubscriptionMode");
9453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
9456 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009461
sqianc5eccab2018-10-19 18:46:41 -07009462 @Override
sqian8c685422019-02-22 15:55:18 -08009463 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009464 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009466 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9467 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9469 }
9470 final long identity = Binder.clearCallingIdentity();
9471 try {
sqian854d44b2018-12-12 16:48:18 -08009472 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9473 for (Phone phone: PhoneFactory.getPhones()) {
9474 if (phone.getEmergencyNumberTracker() != null
9475 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9476 emergencyNumberListInternal.put(
9477 phone.getSubId(),
9478 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9479 }
sqian11b7a0e2018-12-05 18:48:28 -08009480 }
sqian854d44b2018-12-12 16:48:18 -08009481 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009482 } finally {
9483 Binder.restoreCallingIdentity(identity);
9484 }
sqianc5eccab2018-10-19 18:46:41 -07009485 }
9486
9487 @Override
sqian8c685422019-02-22 15:55:18 -08009488 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009489 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009490 if (!exactMatch) {
9491 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009492 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009493 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009494 }
9495 final long identity = Binder.clearCallingIdentity();
9496 try {
sqian854d44b2018-12-12 16:48:18 -08009497 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009498 //Note: we ignore passed in param exactMatch. We can remove it once
9499 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009500 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009501 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009502 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009503 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009504 }
sqian11b7a0e2018-12-05 18:48:28 -08009505 }
9506 return false;
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
9511
sqianf4ca7ed2019-01-15 18:32:07 -08009512 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009513 * Start emergency callback mode for GsmCdmaPhone for testing.
9514 */
9515 @Override
9516 public void startEmergencyCallbackMode() {
9517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9518 "startEmergencyCallbackMode");
9519 enforceModifyPermission();
9520 final long identity = Binder.clearCallingIdentity();
9521 try {
9522 for (Phone phone : PhoneFactory.getPhones()) {
9523 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9524 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9525 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9526 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9527 gsmCdmaPhone.obtainMessage(
9528 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9529 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9530 }
9531 }
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
9536
9537 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009538 * Update emergency number list for test mode.
9539 */
9540 @Override
9541 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9543 "updateEmergencyNumberListTestMode");
9544
9545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 for (Phone phone: PhoneFactory.getPhones()) {
9548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9549 if (tracker != null) {
9550 tracker.executeEmergencyNumberTestModeCommand(action, num);
9551 }
9552 }
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 /**
9559 * Get the full emergency number list for test mode.
9560 */
9561 @Override
9562 public List<String> getEmergencyNumberListTestMode() {
9563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9564 "getEmergencyNumberListTestMode");
9565
9566 final long identity = Binder.clearCallingIdentity();
9567 try {
9568 Set<String> emergencyNumbers = new HashSet<>();
9569 for (Phone phone: PhoneFactory.getPhones()) {
9570 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9571 if (tracker != null) {
9572 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9573 emergencyNumbers.add(num.getNumber());
9574 }
9575 }
9576 }
9577 return new ArrayList<>(emergencyNumbers);
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 }
9582
chen xud6b45bd2018-10-30 22:27:10 -07009583 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009584 public int getEmergencyNumberDbVersion(int subId) {
9585 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9586
9587 final long identity = Binder.clearCallingIdentity();
9588 try {
9589 final Phone phone = getPhone(subId);
9590 if (phone == null) {
9591 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9592 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9593 }
9594 return phone.getEmergencyNumberDbVersion();
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
9597 }
9598 }
9599
9600 @Override
9601 public void notifyOtaEmergencyNumberDbInstalled() {
9602 enforceModifyPermission();
9603
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
9606 for (Phone phone: PhoneFactory.getPhones()) {
9607 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9608 if (tracker != null) {
9609 tracker.updateOtaEmergencyNumberDatabase();
9610 }
9611 }
9612 } finally {
9613 Binder.restoreCallingIdentity(identity);
9614 }
9615 }
9616
9617 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009618 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009619 enforceActiveEmergencySessionPermission();
9620
9621 final long identity = Binder.clearCallingIdentity();
9622 try {
9623 for (Phone phone: PhoneFactory.getPhones()) {
9624 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9625 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009626 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9627 }
9628 }
9629 } finally {
9630 Binder.restoreCallingIdentity(identity);
9631 }
9632 }
9633
9634 @Override
9635 public void resetOtaEmergencyNumberDbFilePath() {
9636 enforceActiveEmergencySessionPermission();
9637
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 for (Phone phone: PhoneFactory.getPhones()) {
9641 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9642 if (tracker != null) {
9643 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009644 }
9645 }
9646 } finally {
9647 Binder.restoreCallingIdentity(identity);
9648 }
9649 }
9650
9651 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009652 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9653 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9654 Phone phone = getPhone(subId);
9655 if (phone == null) {
9656 return null;
9657 }
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 UiccProfile profile = UiccController.getInstance()
9661 .getUiccProfileForPhone(phone.getPhoneId());
9662 if (profile != null) {
9663 return profile.getCertsFromCarrierPrivilegeAccessRules();
9664 }
9665 } finally {
9666 Binder.restoreCallingIdentity(identity);
9667 }
9668 return null;
9669 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009670
9671 /**
9672 * Enable or disable a modem stack.
9673 */
9674 @Override
9675 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9676 enforceModifyPermission();
9677
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 Phone phone = PhoneFactory.getPhone(slotIndex);
9681 if (phone == null) {
9682 return false;
9683 } else {
9684 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9685 }
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 }
Michelecea4cf22018-12-21 15:00:11 -08009690
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009691 /**
9692 * Whether a modem stack is enabled or not.
9693 */
9694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009695 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9696 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009697 Phone phone = PhoneFactory.getPhone(slotIndex);
9698 if (phone == null) return false;
9699
9700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009701 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9702 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009703 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9704 }
9705
9706 final long identity = Binder.clearCallingIdentity();
9707 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009708 try {
9709 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9710 } catch (NoSuchElementException ex) {
9711 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9712 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
Michelecea4cf22018-12-21 15:00:11 -08009718 @Override
Michele0ea7d782019-03-19 14:58:42 -07009719 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009720 enforceModifyPermission();
9721
9722 final long identity = Binder.clearCallingIdentity();
9723 try {
9724 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009725 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009726 .commit();
9727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
9731
9732 @Override
Michele0ea7d782019-03-19 14:58:42 -07009733 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009734 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009736 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9737 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009738 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009739 }
Michelecea4cf22018-12-21 15:00:11 -08009740
9741 final long identity = Binder.clearCallingIdentity();
9742 try {
Michele0ea7d782019-03-19 14:58:42 -07009743 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009748
Michele0ea7d782019-03-19 14:58:42 -07009749 @TelephonyManager.IsMultiSimSupportedResult
9750 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009751 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9752 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9753 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009754 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9755 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009756 }
9757 // Check if the hardware supports multisim functionality. If usage of multisim is not
9758 // supported by the modem, indicate that it is restricted.
9759 PhoneCapability staticCapability =
9760 mPhoneConfigurationManager.getStaticPhoneCapability();
9761 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009762 loge("isMultiSimSupportedInternal: no static configuration available");
9763 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009764 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009765 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009766 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9767 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009768 }
9769 // Check if support of multiple SIMs is restricted by carrier
9770 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009771 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009772 }
9773
Michele0ea7d782019-03-19 14:58:42 -07009774 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009775 }
9776
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009777 /**
9778 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009779 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9780 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9781 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009782 * @param numOfSims number of active sims we want to switch to
9783 */
9784 @Override
9785 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009786 if (numOfSims == 1) {
9787 enforceModifyPermission();
9788 } else {
9789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9790 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9791 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009792 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009793
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009794 try {
Michele30b57b22019-03-01 12:01:14 -08009795 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009796 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009797 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9798 return;
9799 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009800 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
9805
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009806 @Override
9807 public boolean isApplicationOnUicc(int subId, int appType) {
9808 enforceReadPrivilegedPermission("isApplicationOnUicc");
9809 Phone phone = getPhone(subId);
9810 if (phone == null) {
9811 return false;
9812 }
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009815 UiccPort uiccPort = phone.getUiccPort();
9816 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009817 return false;
9818 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009819 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009820 if (uiccProfile == null) {
9821 return false;
9822 }
9823 if (TelephonyManager.APPTYPE_SIM <= appType
9824 && appType <= TelephonyManager.APPTYPE_ISIM) {
9825 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9826 }
9827 return false;
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009833 /**
chen xub4baa772019-04-03 10:23:41 -07009834 * Get whether making changes to modem configurations will trigger reboot.
9835 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009836 */
9837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009838 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9839 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009841 mApp, subId, callingPackage, callingFeatureId,
9842 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009843 return false;
9844 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009845 final long identity = Binder.clearCallingIdentity();
9846 try {
9847 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9848 } finally {
9849 Binder.restoreCallingIdentity(identity);
9850 }
9851 }
9852
Nathan Harold29f5f052019-02-15 13:41:57 -08009853 private void updateModemStateMetrics() {
9854 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9855 // TODO: check the state for each modem if the api is ready.
9856 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9857 }
9858
Pengquan Meng3889a572019-01-23 11:16:29 -08009859 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009860 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009861 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009862 // Verify that the callingPackage belongs to the calling UID
9863 mApp.getSystemService(AppOpsManager.class)
9864 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009865 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009866 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009867 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009868 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9869 if (slotInfos != null) {
9870 for (int i = 0; i < slotInfos.length; i++) {
9871 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9872 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9873 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9874 portInfo.getLogicalSlotIndex()));
9875 }
9876 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009877 }
9878 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009879 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009884
9885 /**
9886 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009887 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009888 */
jimsunf9ec1622022-09-13 21:18:43 +08009889 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009890 @Override
9891 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009892 return getHalVersion(HAL_SERVICE_RADIO);
9893 }
9894
9895 /**
9896 * Get the HAL Version of a specific service
9897 */
9898 @Override
9899 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009900 Phone phone = getDefaultPhone();
9901 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009902 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009903 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9904 return hv.major * 100 + hv.minor;
9905 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009906
9907 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009908 * Get the current calling package name.
9909 * @return the current calling package name
9910 */
9911 @Override
9912 public String getCurrentPackageName() {
9913 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9914 }
9915
9916 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009917 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9918 * corresponding network requests on a subId.
9919 *
9920 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009921 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009922 * 2) APN is un-metered for this subscription, or
9923 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009924 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009925 *
9926 * @return whether data is allowed for a apn type.
9927 *
9928 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009929 */
9930 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009931 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009932 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9933 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009934
9935 // Now that all security checks passes, perform the operation as ourselves.
9936 final long identity = Binder.clearCallingIdentity();
9937 try {
9938 Phone phone = getPhone(subId);
9939 if (phone == null) return false;
9940
Jack Yu27422a52022-03-21 10:38:05 -07009941 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009942 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009943 isMetered = phone.getDataNetworkController().getDataConfigManager()
9944 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9945 phone.getServiceState().getDataRoaming());
9946 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009947 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009948 } finally {
9949 Binder.restoreCallingIdentity(identity);
9950 }
9951 }
9952
9953 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009954 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009955 enforceReadPrivilegedPermission("isApnMetered");
9956
9957 // Now that all security checks passes, perform the operation as ourselves.
9958 final long identity = Binder.clearCallingIdentity();
9959 try {
9960 Phone phone = getPhone(subId);
9961 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009962 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9963 DataUtils.apnTypeToNetworkCapability(apnType),
9964 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009969
9970 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009971 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9972 int subscriptionId, IBooleanConsumer resultCallback) {
9973 enforceModifyPermission();
9974 long token = Binder.clearCallingIdentity();
9975 try {
9976 Phone phone = getPhone(subscriptionId);
9977 if (phone == null) {
9978 try {
9979 if (resultCallback != null) {
9980 resultCallback.accept(false);
9981 }
9982 } catch (RemoteException e) {
9983 // ignore
9984 }
9985 return;
9986 }
9987 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9988 Pair.create(specifiers, (x) -> {
9989 try {
9990 if (resultCallback != null) {
9991 resultCallback.accept(x);
9992 }
9993 } catch (RemoteException e) {
9994 // ignore
9995 }
9996 });
9997 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9998 } finally {
9999 Binder.restoreCallingIdentity(token);
10000 }
10001 }
10002
10003 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010004 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10005 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010006 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010007 mApp, subId, "getSystemSelectionChannels");
10008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10009 final long identity = Binder.clearCallingIdentity();
10010 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010011 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10012 if (result instanceof IllegalStateException) {
10013 throw (IllegalStateException) result;
10014 }
10015 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010016 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10017 return specifiers;
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
10022
10023 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010024 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010025 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010026 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010027 }
10028
10029 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010030 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10031 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010032 if (callingPackage == null) {
10033 callingPackage = getCurrentPackageName();
10034 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010035 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10036 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010037 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10038 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010039 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10040 }
10041 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10042 Intent intent = new Intent();
10043 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10044 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10045 // Bring up choose default SMS subscription dialog right now
10046 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10047 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10048 mApp.startActivity(intent);
10049 }
chen xud5ca2d52019-05-28 15:20:57 -070010050
10051 @Override
10052 public String getMmsUAProfUrl(int subId) {
10053 //TODO investigate if this API should require proper permission check in R b/133791609
10054 final long identity = Binder.clearCallingIdentity();
10055 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010056 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10057 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10058 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10059 return carrierUAProfUrl;
10060 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010061 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10062 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
10066 }
10067
10068 @Override
10069 public String getMmsUserAgent(int subId) {
10070 //TODO investigate if this API should require proper permission check in R b/133791609
10071 final long identity = Binder.clearCallingIdentity();
10072 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010073 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10074 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10075 if (!TextUtils.isEmpty(carrierUserAgent)) {
10076 return carrierUserAgent;
10077 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010078 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10079 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010080 } finally {
10081 Binder.restoreCallingIdentity(identity);
10082 }
10083 }
Jack Yub07d4972019-05-28 16:12:25 -070010084
10085 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010086 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10087 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010088
Jack Yub07d4972019-05-28 16:12:25 -070010089 final long identity = Binder.clearCallingIdentity();
10090 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010091 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010092 if (phone == null) return false;
10093
Ling Maf188d502022-09-16 15:22:36 -070010094 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 }
10099
10100 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010101 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010102 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010103 enforceModifyPermission();
10104
changbettyd5c246e2019-12-24 15:40:37 +080010105 final long identity = Binder.clearCallingIdentity();
10106 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010107 Phone phone = getPhone(subscriptionId);
10108 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010109
Ling Maf188d502022-09-16 15:22:36 -070010110 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010116 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010117 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010118 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10119 * otherwise.
10120 */
10121 @Override
10122 public void setCepEnabled(boolean isCepEnabled) {
10123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10124
10125 final long identity = Binder.clearCallingIdentity();
10126 try {
10127 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10128 for (Phone phone : PhoneFactory.getPhones()) {
10129 Phone defaultPhone = phone.getImsPhone();
10130 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10131 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10132 ImsPhoneCallTracker imsPhoneCallTracker =
10133 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10134 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10135 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10136 + imsPhone.getMsisdn());
10137 }
10138 }
10139 } finally {
10140 Binder.restoreCallingIdentity(identity);
10141 }
10142 }
allenwtsu46dcc572020-01-08 18:24:03 +080010143
10144 /**
10145 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10146 *
10147 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10148 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10149 * before being read.
10150 */
10151 @Override
10152 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10153 isCompressed) {
10154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10155 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10157 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10158 }
10159 if (!isImsAvailableOnDevice()) {
10160 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10161 "IMS not available on device.");
10162 }
10163
10164 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010165 try {
Hui Wang761a6682020-10-31 05:12:53 +000010166 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010169 }
10170 }
zoey chene02881a2019-12-30 16:11:23 +080010171
10172 @Override
10173 public boolean isIccLockEnabled(int subId) {
10174 enforceReadPrivilegedPermission("isIccLockEnabled");
10175
10176 // Now that all security checks passes, perform the operation as ourselves.
10177 final long identity = Binder.clearCallingIdentity();
10178 try {
10179 Phone phone = getPhone(subId);
10180 if (phone != null && phone.getIccCard() != null) {
10181 return phone.getIccCard().getIccLockEnabled();
10182 } else {
10183 return false;
10184 }
10185 } finally {
10186 Binder.restoreCallingIdentity(identity);
10187 }
10188 }
10189
10190 /**
10191 * Set the ICC pin lock enabled or disabled.
10192 *
10193 * @return an integer representing the status of IccLock enabled or disabled in the following
10194 * three cases:
10195 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10196 * successfully.
10197 * - Positive number and zero for remaining password attempts.
10198 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10199 *
10200 */
10201 @Override
10202 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10203 enforceModifyPermission();
10204
10205 Phone phone = getPhone(subId);
10206 if (phone == null) {
10207 return 0;
10208 }
10209 // Now that all security checks passes, perform the operation as ourselves.
10210 final long identity = Binder.clearCallingIdentity();
10211 try {
10212 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10213 new Pair<Boolean, String>(enabled, password), phone, null);
10214 return attemptsRemaining;
10215
10216 } catch (Exception e) {
10217 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 return 0;
10222 }
10223
10224 /**
10225 * Change the ICC password used in ICC pin lock.
10226 *
10227 * @return an integer representing the status of IccLock changed in the following three cases:
10228 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10229 * - Positive number and zero for remaining password attempts.
10230 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10231 *
10232 */
10233 @Override
10234 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10235 enforceModifyPermission();
10236
10237 Phone phone = getPhone(subId);
10238 if (phone == null) {
10239 return 0;
10240 }
10241 // Now that all security checks passes, perform the operation as ourselves.
10242 final long identity = Binder.clearCallingIdentity();
10243 try {
10244 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10245 new Pair<String, String>(oldPassword, newPassword), phone, null);
10246 return attemptsRemaining;
10247
10248 } catch (Exception e) {
10249 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 return 0;
10254 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010255
10256 /**
10257 * Request for receiving user activity notification
10258 */
10259 @Override
10260 public void requestUserActivityNotification() {
10261 if (!mNotifyUserActivity.get()
10262 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10263 mNotifyUserActivity.set(true);
10264 }
10265 }
10266
10267 /**
10268 * Called when userActivity is signalled in the power manager.
10269 * This is safe to call from any thread, with any window manager locks held or not.
10270 */
10271 @Override
10272 public void userActivity() {
10273 // ***************************************
10274 // * Inherited from PhoneWindowManager *
10275 // ***************************************
10276 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10277 // WITH ITS LOCKS HELD.
10278 //
10279 // This code must be VERY careful about the locks
10280 // it acquires.
10281 // In fact, the current code acquires way too many,
10282 // and probably has lurking deadlocks.
10283
10284 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10285 throw new SecurityException("Only the OS may call notifyUserActivity()");
10286 }
10287
10288 if (mNotifyUserActivity.getAndSet(false)) {
10289 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10290 USER_ACTIVITY_NOTIFICATION_DELAY);
10291 }
10292 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010293
10294 @Override
10295 public boolean canConnectTo5GInDsdsMode() {
10296 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10297 }
Jack Yud10cdd42020-09-28 20:28:01 -070010298
10299 @Override
10300 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10301 String callingFeatureId) {
10302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10303 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10304 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10305 }
10306
10307 Phone phone = getPhone(subId);
10308 if (phone == null) {
10309 throw new RuntimeException("phone is not available");
10310 }
10311 // Now that all security checks passes, perform the operation as ourselves.
10312 final long identity = Binder.clearCallingIdentity();
10313 try {
10314 return phone.getEquivalentHomePlmns();
10315 } finally {
10316 Binder.restoreCallingIdentity(identity);
10317 }
10318 }
Daniel Bright59e67312020-11-13 11:49:37 -080010319
10320 @Override
10321 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010322 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10323 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010324 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010325 if (radioInterfaceCapabilities == null) {
10326 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010327 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010328 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010329 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010330
Hui Wang641e81c2020-10-12 12:14:23 -070010331 @Override
10332 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10333 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010334 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10335 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10336 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10337 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10338 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010339 if (DBG) {
10340 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10341 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10342 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10343 }
10344
10345 if (!SubscriptionManager.isValidSubscriptionId(subId)
10346 || appType < TelephonyManager.APPTYPE_UNKNOWN
10347 || appType > TelephonyManager.APPTYPE_ISIM
10348 || nafUrl == null || securityProtocol == null || callback == null) {
10349 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10350 if (callback != null) {
10351 try {
10352 callback.onAuthenticationFailure(
10353 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10354 } catch (RemoteException exception) {
10355 log("Fail to notify onAuthenticationFailure due to " + exception);
10356 }
10357 return;
10358 }
10359 }
10360
10361 final long token = Binder.clearCallingIdentity();
10362 try {
10363 getGbaManager(subId).bootstrapAuthenticationRequest(
10364 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10365 forceBootStrapping, callback));
10366 } finally {
10367 Binder.restoreCallingIdentity(token);
10368 }
10369 }
10370
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010371 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010372 * Attempts to set the radio power state for all phones for thermal reason.
10373 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010374 * requested radio power state will actually be set. See {@link
10375 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10376 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010377 * @param enable {@code true} if trying to turn radio on.
10378 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10379 * false}.
10380 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010381 private boolean setRadioPowerForThermal(boolean enable) {
10382 boolean isPhoneAvailable = false;
10383 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10384 Phone phone = PhoneFactory.getPhone(i);
10385 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010386 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010387 isPhoneAvailable = true;
10388 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010389 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010390
10391 // return true if successfully informed the phone object about the thermal radio power
10392 // request.
10393 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010394 }
10395
10396 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010397 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010398 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10399 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10400 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10401 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10402 throw new IllegalArgumentException("modem does not support data throttling");
10403 }
10404
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010405 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10406 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010407 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010408 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10409 }
10410
Sarah Chinecc78c42022-03-31 21:16:48 -070010411 setDataEnabledForReason(
10412 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010413
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010414 if (isDataThrottlingSupported) {
10415 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010416 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010417 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10418 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10419 } else if (thermalMitigationResult
10420 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010421 log("Modem likely does not support data throttling on secondary carrier. Data " +
10422 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10423 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010424 }
10425 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010426 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010427
10428 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010429 }
10430
Jack Nudelman644b91a2021-03-12 14:09:48 -080010431 private static List<String> getThermalMitigationAllowlist(Context context) {
10432 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10433 for (String pckg : context.getResources()
10434 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10435 sThermalMitigationAllowlistedPackages.add(pckg);
10436 }
10437 }
10438
10439 return sThermalMitigationAllowlistedPackages;
10440 }
10441
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010442 private boolean isAnyPhoneInEmergencyState() {
10443 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10444 if (tm.isInEmergencyCall()) {
10445 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10446 return true;
10447 }
10448 for (Phone phone : PhoneFactory.getPhones()) {
10449 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10450 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10451 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10452 + phone.isInEcm());
10453 return true;
10454 }
10455 }
10456
10457 return false;
10458 }
10459
Jack Nudelman644b91a2021-03-12 14:09:48 -080010460 /**
10461 * Used by shell commands to add an authorized package name for thermal mitigation.
10462 * @param packageName name of package to be allowlisted
10463 * @param context
10464 */
10465 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10466 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10467 sThermalMitigationAllowlistedPackages.add(packageName);
10468 }
10469
10470 /**
10471 * Used by shell commands to remove an authorized package name for thermal mitigation.
10472 * @param packageName name of package to remove from allowlist
10473 * @param context
10474 */
10475 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10476 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10477 sThermalMitigationAllowlistedPackages.remove(packageName);
10478 }
10479
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010480 /**
10481 * Thermal mitigation request to control functionalities at modem.
10482 *
10483 * @param subId the id of the subscription.
10484 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010485 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010486 *
10487 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10488 */
10489 @Override
10490 @ThermalMitigationResult
10491 public int sendThermalMitigationRequest(
10492 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010493 ThermalMitigationRequest thermalMitigationRequest,
10494 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010495 enforceModifyPermission();
10496
Jack Nudelman644b91a2021-03-12 14:09:48 -080010497 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10498 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10499 .contains(callingPackage)) {
10500 throw new SecurityException("Calling package must be configured in the device config. "
10501 + "calling package: " + callingPackage);
10502 }
10503
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10505 final long identity = Binder.clearCallingIdentity();
10506
10507 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10508 try {
10509 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10510 switch (thermalMitigationAction) {
10511 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10512 thermalMitigationResult =
10513 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010514 thermalMitigationRequest.getDataThrottlingRequest(),
10515 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010516 break;
10517 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10518 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10519 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10520 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10521 }
10522
10523 // Ensure that radio is on. If not able to power on due to phone being
10524 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010525 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010526 thermalMitigationResult =
10527 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10528 break;
10529 }
10530
10531 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010532 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010533 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10534 break;
10535 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10536 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10537 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10538 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10539 }
10540
10541 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10542 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010543 Phone phone = getPhone(subId);
10544 if (phone == null) {
10545 thermalMitigationResult =
10546 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10547 break;
10548 }
10549
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010550 TelephonyConnectionService service =
10551 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010552 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010553 Log.e(LOG_TAG, "An emergency call is pending");
10554 thermalMitigationResult =
10555 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10556 break;
10557 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 thermalMitigationResult =
10559 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10560 break;
10561 }
10562 } else {
10563 thermalMitigationResult =
10564 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10565 break;
10566 }
10567
10568 // Turn radio off. If not able to power off due to phone being unavailable,
10569 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010570 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010571 thermalMitigationResult =
10572 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10573 break;
10574 }
10575 thermalMitigationResult =
10576 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10577 break;
10578 default:
10579 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10580 + "not exist. Requested action: " + thermalMitigationAction);
10581 }
10582 } catch (IllegalArgumentException e) {
10583 throw e;
10584 } catch (Exception e) {
10585 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10586 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10587 } finally {
10588 Binder.restoreCallingIdentity(identity);
10589 }
10590
10591 if (DBG) {
10592 log("thermalMitigationRequest returning with thermalMitigationResult: "
10593 + thermalMitigationResult);
10594 }
10595
10596 return thermalMitigationResult;
10597 }
Hui Wang641e81c2020-10-12 12:14:23 -070010598
10599 /**
10600 * Set the GbaService Package Name that Telephony will bind to.
10601 *
10602 * @param subId The sim that the GbaService is associated with.
10603 * @param packageName The name of the package to be replaced with.
10604 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10605 */
10606 @Override
10607 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10608 enforceModifyPermission();
10609
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
10612 return getGbaManager(subId).overrideServicePackage(packageName);
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
10617
10618 /**
10619 * Return the package name of the currently bound GbaService.
10620 *
10621 * @param subId The sim that the GbaService is associated with.
10622 * @return the package name of the GbaService configuration, null if GBA is not supported.
10623 */
10624 @Override
10625 public String getBoundGbaService(int subId) {
10626 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10627
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 return getGbaManager(subId).getServicePackage();
10631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
10635
10636 /**
10637 * Set the release time for telephony to unbind GbaService.
10638 *
10639 * @param subId The sim that the GbaService is associated with.
10640 * @param interval The release time to unbind GbaService by millisecond.
10641 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10642 */
10643 @Override
10644 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10645 enforceModifyPermission();
10646
10647 final long identity = Binder.clearCallingIdentity();
10648 try {
10649 return getGbaManager(subId).overrideReleaseTime(interval);
10650 } finally {
10651 Binder.restoreCallingIdentity(identity);
10652 }
10653 }
10654
10655 /**
10656 * Return the release time for telephony to unbind GbaService.
10657 *
10658 * @param subId The sim that the GbaService is associated with.
10659 * @return The release time to unbind GbaService by millisecond.
10660 */
10661 @Override
10662 public int getGbaReleaseTime(int subId) {
10663 enforceReadPrivilegedPermission("getGbaReleaseTime");
10664
10665 final long identity = Binder.clearCallingIdentity();
10666 try {
10667 return getGbaManager(subId).getReleaseTime();
10668 } finally {
10669 Binder.restoreCallingIdentity(identity);
10670 }
10671 }
10672
10673 private GbaManager getGbaManager(int subId) {
10674 GbaManager instance = GbaManager.getInstance(subId);
10675 if (instance == null) {
10676 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10677 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10678 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10679 }
10680 return instance;
10681 }
Hui Wang761a6682020-10-31 05:12:53 +000010682
10683 /**
10684 * indicate whether the device and the carrier can support
10685 * RCS VoLTE single registration.
10686 */
10687 @Override
10688 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010689 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10690 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10691 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10692 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010693
10694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10695 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10696 }
10697
10698 final long identity = Binder.clearCallingIdentity();
10699 try {
10700 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10701 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010702 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10703 if (isCapable != null) {
10704 return isCapable;
10705 }
Hui Wang761a6682020-10-31 05:12:53 +000010706 }
Hui Wang67af90e2021-06-04 16:57:15 -070010707 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10708 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
10713
10714 /**
10715 * Register RCS provisioning callback.
10716 */
10717 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010718 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010719 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010720 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010721 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010722 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10723 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010724
10725 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10726 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10727 }
10728 if (!isImsAvailableOnDevice()) {
10729 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10730 "IMS not available on device.");
10731 }
10732
10733 final long identity = Binder.clearCallingIdentity();
10734 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010735 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010736 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010737 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10738 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010739 }
Hui Wang761a6682020-10-31 05:12:53 +000010740 } finally {
10741 Binder.restoreCallingIdentity(identity);
10742 }
10743 }
10744
10745 /**
10746 * Unregister RCS provisioning callback.
10747 */
10748 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010749 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010750 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010751 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010752 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010753 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10754 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010755
10756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10757 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10758 }
10759 if (!isImsAvailableOnDevice()) {
10760 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10761 "IMS not available on device.");
10762 }
10763
10764 final long identity = Binder.clearCallingIdentity();
10765 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010766 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010767 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
10772
10773 /**
10774 * trigger RCS reconfiguration.
10775 */
10776 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010777 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10778 "triggerRcsReconfiguration",
10779 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010780
10781 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10782 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10783 }
10784 if (!isImsAvailableOnDevice()) {
10785 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10786 "IMS not available on device.");
10787 }
10788
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10792 } finally {
10793 Binder.restoreCallingIdentity(identity);
10794 }
10795 }
10796
10797 /**
10798 * Provide the client configuration parameters of the RCS application.
10799 */
10800 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010801 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10802 "setRcsClientConfiguration",
10803 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010804
10805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10807 }
10808 if (!isImsAvailableOnDevice()) {
10809 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10810 "IMS not available on device.");
10811 }
10812
10813 final long identity = Binder.clearCallingIdentity();
10814
10815 try {
10816 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10817 if (configBinder == null) {
10818 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010819 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10820 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010821 } else {
10822 configBinder.setRcsClientConfiguration(rcc);
10823 }
joonhunshin3e154242021-09-17 06:33:39 +000010824
10825 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10826 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010827 } catch (RemoteException e) {
10828 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010829 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10830 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010831 } finally {
10832 Binder.restoreCallingIdentity(identity);
10833 }
10834 }
10835
10836 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010837 * Enables or disables the test mode for RCS VoLTE single registration.
10838 */
10839 @Override
10840 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10842 "setRcsSingleRegistrationTestModeEnabled");
10843
10844 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10845 }
10846
10847 /**
10848 * Gets the test mode for RCS VoLTE single registration.
10849 */
10850 @Override
10851 public boolean getRcsSingleRegistrationTestModeEnabled() {
10852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10853 "getRcsSingleRegistrationTestModeEnabled");
10854
10855 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10856 }
10857
10858 /**
Hui Wang761a6682020-10-31 05:12:53 +000010859 * Overrides the config of RCS VoLTE single registration enabled for the device.
10860 */
10861 @Override
10862 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10864 "setDeviceSingleRegistrationEnabledOverride");
10865 enforceModifyPermission();
10866
10867 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10868 : Boolean.parseBoolean(enabledStr);
10869 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010870 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010871 }
10872
10873 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010874 * Sends a device to device communication message. Only usable via shell.
10875 * @param message message to send.
10876 * @param value message value.
10877 */
10878 @Override
10879 public void sendDeviceToDeviceMessage(int message, int value) {
10880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010881 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010882 enforceModifyPermission();
10883
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 TelephonyConnectionService service =
10887 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10888 if (service == null) {
10889 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10890 return;
10891 }
10892 service.sendTestDeviceToDeviceMessage(message, value);
10893 } finally {
10894 Binder.restoreCallingIdentity(identity);
10895 }
10896 }
10897
Tyler Gunnbabbda02021-02-10 11:05:02 -080010898 /**
10899 * Sets the specified device to device transport active.
10900 * @param transport The transport to set active.
10901 */
10902 @Override
10903 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10905 "setActiveDeviceToDeviceTransport");
10906 enforceModifyPermission();
10907
10908 final long identity = Binder.clearCallingIdentity();
10909 try {
10910 TelephonyConnectionService service =
10911 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10912 if (service == null) {
10913 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10914 return;
10915 }
10916 service.setActiveDeviceToDeviceTransport(transport);
10917 } finally {
10918 Binder.restoreCallingIdentity(identity);
10919 }
10920 }
Tyler Gunn92479152021-01-20 16:30:10 -080010921
Tyler Gunnd4339262021-05-03 14:46:49 -070010922 @Override
10923 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10925 "setDeviceToDeviceForceEnabled");
10926
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 Arrays.stream(PhoneFactory.getPhones()).forEach(
10930 p -> {
10931 Phone thePhone = p.getImsPhone();
10932 if (thePhone != null && thePhone instanceof ImsPhone) {
10933 ImsPhone imsPhone = (ImsPhone) thePhone;
10934 CallTracker tracker = imsPhone.getCallTracker();
10935 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10936 ImsPhoneCallTracker imsPhoneCallTracker =
10937 (ImsPhoneCallTracker) tracker;
10938 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10939 }
10940 }
10941 }
10942 );
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
Tyler Gunn92479152021-01-20 16:30:10 -080010948 /**
Hui Wang761a6682020-10-31 05:12:53 +000010949 * Gets the config of RCS VoLTE single registration enabled for the device.
10950 */
10951 @Override
10952 public boolean getDeviceSingleRegistrationEnabled() {
10953 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10954 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10955 }
10956
10957 /**
10958 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10959 */
10960 @Override
10961 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10963 "setCarrierSingleRegistrationEnabledOverride");
10964 enforceModifyPermission();
10965
10966 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10967 : Boolean.parseBoolean(enabledStr);
10968 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10969 subId, enabled);
10970 }
10971
10972 /**
10973 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10974 */
10975 @Override
10976 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10977 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10978 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10979 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010980
10981 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010982 * Overrides the ims feature validation result
10983 */
10984 @Override
10985 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10987 "setImsFeatureValidationOverride");
10988
10989 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10990 : Boolean.parseBoolean(enabledStr);
10991 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10992 subId, enabled);
10993 }
10994
10995 /**
10996 * Gets the ims feature validation override value
10997 */
10998 @Override
10999 public boolean getImsFeatureValidationOverride(int subId) {
11000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11001 "getImsFeatureValidationOverride");
11002 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11003 }
11004
11005 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011006 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11007 * their mobile plan.
11008 */
11009 @Override
11010 public String getMobileProvisioningUrl() {
11011 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11012 final long identity = Binder.clearCallingIdentity();
11013 try {
11014 return getDefaultPhone().getMobileProvisioningUrl();
11015 } finally {
11016 Binder.restoreCallingIdentity(identity);
11017 }
11018 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011019
James.cf Linbcdf8b32021-01-14 16:44:13 +080011020 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011021 * Get the EAB contact from the EAB database.
11022 */
11023 @Override
11024 public String getContactFromEab(String contact) {
11025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11026 enforceModifyPermission();
11027 final long identity = Binder.clearCallingIdentity();
11028 try {
11029 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11030 } finally {
11031 Binder.restoreCallingIdentity(identity);
11032 }
11033 }
11034
11035 /**
Calvin Pana1434322021-07-01 19:27:01 +080011036 * Get the EAB capability from the EAB database.
11037 */
11038 @Override
11039 public String getCapabilityFromEab(String contact) {
11040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11041 enforceModifyPermission();
11042 final long identity = Binder.clearCallingIdentity();
11043 try {
11044 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
11049
11050 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011051 * Remove the EAB contacts from the EAB database.
11052 */
11053 @Override
11054 public int removeContactFromEab(int subId, String contacts) {
11055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11056 enforceModifyPermission();
11057 final long identity = Binder.clearCallingIdentity();
11058 try {
11059 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
11064
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011065 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011066 public boolean getDeviceUceEnabled() {
11067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11068 final long identity = Binder.clearCallingIdentity();
11069 try {
11070 return mApp.getDeviceUceEnabled();
11071 } finally {
11072 Binder.restoreCallingIdentity(identity);
11073 }
11074 }
11075
11076 @Override
11077 public void setDeviceUceEnabled(boolean isEnabled) {
11078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 mApp.setDeviceUceEnabled(isEnabled);
11082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
11086
Brad Ebinger14d467f2021-02-12 06:18:28 +000011087 /**
11088 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11089 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11090 */
11091 // Used for SHELL command only right now.
11092 @Override
11093 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11094 List<String> featureTags) {
11095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11096 "addUceRegistrationOverrideShell");
11097 final long identity = Binder.clearCallingIdentity();
11098 try {
11099 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11100 new ArraySet<>(featureTags));
11101 } catch (ImsException e) {
11102 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11103 } finally {
11104 Binder.restoreCallingIdentity(identity);
11105 }
11106 }
11107
11108 /**
11109 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11110 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11111 */
11112 // Used for SHELL command only right now.
11113 @Override
11114 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11115 List<String> featureTags) {
11116 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11117 "removeUceRegistrationOverrideShell");
11118 final long identity = Binder.clearCallingIdentity();
11119 try {
11120 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11121 new ArraySet<>(featureTags));
11122 } catch (ImsException e) {
11123 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
11129 /**
11130 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11131 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11132 */
11133 // Used for SHELL command only right now.
11134 @Override
11135 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11137 "clearUceRegistrationOverrideShell");
11138 final long identity = Binder.clearCallingIdentity();
11139 try {
11140 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11141 } catch (ImsException e) {
11142 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11143 } finally {
11144 Binder.restoreCallingIdentity(identity);
11145 }
11146 }
11147
11148 /**
11149 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11150 */
11151 // Used for SHELL command only right now.
11152 @Override
11153 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11155 "getLatestRcsContactUceCapabilityShell");
11156 final long identity = Binder.clearCallingIdentity();
11157 try {
11158 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11159 } catch (ImsException e) {
11160 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11161 } finally {
11162 Binder.restoreCallingIdentity(identity);
11163 }
11164 }
11165
11166 /**
11167 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11168 * device does not have an active PUBLISH.
11169 */
11170 // Used for SHELL command only right now.
11171 @Override
11172 public String getLastUcePidfXmlShell(int subId) {
11173 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11174 final long identity = Binder.clearCallingIdentity();
11175 try {
11176 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11177 } catch (ImsException e) {
11178 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11179 } finally {
11180 Binder.restoreCallingIdentity(identity);
11181 }
11182 }
11183
James.cf Line8713a42021-04-29 16:04:26 +080011184 /**
11185 * Remove UCE requests cannot be sent to the network status.
11186 */
11187 // Used for SHELL command only right now.
11188 @Override
11189 public boolean removeUceRequestDisallowedStatus(int subId) {
11190 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11191 final long identity = Binder.clearCallingIdentity();
11192 try {
11193 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11194 } catch (ImsException e) {
11195 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
11200
James.cf Lin18bb9002021-05-25 01:37:38 +080011201 /**
11202 * Remove UCE requests cannot be sent to the network status.
11203 */
11204 // Used for SHELL command only.
11205 @Override
11206 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11208 final long identity = Binder.clearCallingIdentity();
11209 try {
11210 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11211 } catch (ImsException e) {
11212 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11213 } finally {
11214 Binder.restoreCallingIdentity(identity);
11215 }
11216 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011217
James.cf Lin4b784aa2021-01-31 03:25:15 +080011218 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011219 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11220 String callingPackage) {
11221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11222 mApp, subId, "setSignalStrengthUpdateRequest");
11223
11224 final int callingUid = Binder.getCallingUid();
11225 // Verify that tha callingPackage belongs to the calling UID
11226 mApp.getSystemService(AppOpsManager.class)
11227 .checkPackage(callingUid, callingPackage);
11228
Rambo Wang3607f502021-02-01 21:51:40 -080011229 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011230
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11234 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11235
11236 if (result instanceof IllegalStateException) {
11237 throw (IllegalStateException) result;
11238 }
11239 } finally {
11240 Binder.restoreCallingIdentity(identity);
11241 }
11242 }
11243
11244 @Override
11245 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11246 String callingPackage) {
11247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11248 mApp, subId, "clearSignalStrengthUpdateRequest");
11249
11250 final int callingUid = Binder.getCallingUid();
11251 // Verify that tha callingPackage belongs to the calling UID
11252 mApp.getSystemService(AppOpsManager.class)
11253 .checkPackage(callingUid, callingPackage);
11254
11255 final long identity = Binder.clearCallingIdentity();
11256 try {
11257 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11258 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11259
11260 if (result instanceof IllegalStateException) {
11261 throw (IllegalStateException) result;
11262 }
11263 } finally {
11264 Binder.restoreCallingIdentity(identity);
11265 }
11266 }
11267
Rambo Wang3607f502021-02-01 21:51:40 -080011268 private static void validateSignalStrengthUpdateRequest(Context context,
11269 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011270 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11271 // phone/system process do not have further restriction on request
11272 return;
11273 }
11274
11275 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011276 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011277 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011278 context.enforceCallingOrSelfPermission(
11279 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11280 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011281 }
11282
11283 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11284 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11285 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11286 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11287 || info.isEnabled()) {
11288 throw new IllegalArgumentException(
11289 "Only system can set hide fields in SignalThresholdInfo");
11290 }
11291
11292 // Thresholds length for each RAN need in range. This has been validated in
11293 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11294 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11295 final int[] thresholds = info.getThresholds();
11296 Objects.requireNonNull(thresholds);
11297 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11298 || thresholds.length
11299 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11300 throw new IllegalArgumentException(
11301 "thresholds length is out of range: " + thresholds.length);
11302 }
11303 }
11304 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011305
11306 /**
11307 * Gets the current phone capability.
11308 *
11309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11310 * @return the PhoneCapability which describes the data connection capability of modem.
11311 * It's used to evaluate possible phone config change, for example from single
11312 * SIM device to multi-SIM device.
11313 */
11314 @Override
11315 public PhoneCapability getPhoneCapability() {
11316 enforceReadPrivilegedPermission("getPhoneCapability");
11317 final long identity = Binder.clearCallingIdentity();
11318 try {
11319 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11320 } finally {
11321 Binder.restoreCallingIdentity(identity);
11322 }
11323 }
Michele Berionne5e411512020-11-13 02:36:59 +000011324
11325 /**
11326 * Prepare TelephonyManager for an unattended reboot. The reboot is
11327 * required to be done shortly after the API is invoked.
11328 */
11329 @Override
11330 @TelephonyManager.PrepareUnattendedRebootResult
11331 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011333 enforceRebootPermission();
11334
11335 final long identity = Binder.clearCallingIdentity();
11336 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011337 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011338 } finally {
11339 Binder.restoreCallingIdentity(identity);
11340 }
11341 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011342
11343 /**
11344 * Request to get the current slicing configuration including URSP rules and
11345 * NSSAIs (configured, allowed and rejected).
11346 *
11347 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11348 */
11349 @Override
11350 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011351 TelephonyPermissions
11352 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11353 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011354
11355 final long identity = Binder.clearCallingIdentity();
11356 try {
11357 Phone phone = getDefaultPhone();
11358 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11359 } finally {
11360 Binder.restoreCallingIdentity(identity);
11361 }
11362 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011363
11364 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011365 * Check whether the given premium capability is available for purchase from the carrier.
11366 *
11367 * @param capability The premium capability to check.
11368 * @param subId The subId to check the premium capability for.
11369 *
11370 * @return Whether the given premium capability is available to purchase.
11371 */
11372 @Override
11373 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11374 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11375 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11376 log("Premium capability "
11377 + TelephonyManager.convertPremiumCapabilityToString(capability)
11378 + " is not available for purchase due to missing permissions.");
11379 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11380 + "permission READ_BASIC_PHONE_STATE.");
11381 }
11382
11383 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011384 if (phone == null) {
11385 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11386 return false;
11387 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011388 final long identity = Binder.clearCallingIdentity();
11389 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011390 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011391 .isPremiumCapabilityAvailableForPurchase(capability);
11392 } finally {
11393 Binder.restoreCallingIdentity(identity);
11394 }
11395 }
11396
11397 /**
11398 * Purchase the given premium capability from the carrier.
11399 *
11400 * @param capability The premium capability to purchase.
11401 * @param callback The result of the purchase request.
11402 * @param subId The subId to purchase the premium capability for.
11403 */
11404 @Override
11405 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11406 log("purchasePremiumCapability: capability="
11407 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11408 + getCurrentPackageName());
11409
11410 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11411 mApp, "purchasePremiumCapability")) {
11412 log("purchasePremiumCapability "
11413 + TelephonyManager.convertPremiumCapabilityToString(capability)
11414 + " failed due to missing permissions.");
11415 throw new SecurityException("purchasePremiumCapability requires permission "
11416 + "READ_BASIC_PHONE_STATE.");
11417 }
11418
11419 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011420 if (phone == null) {
11421 try {
11422 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11423 callback.accept(result);
11424 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11425 } catch (RemoteException e) {
11426 String logStr = "Purchase premium capability "
11427 + TelephonyManager.convertPremiumCapabilityToString(capability)
11428 + " failed due to RemoteException handling null phone: " + e;
11429 if (DBG) log(logStr);
11430 AnomalyReporter.reportAnomaly(
11431 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11432 }
11433 return;
11434 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011435 String appName;
11436 try {
11437 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11438 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11439 } catch (PackageManager.NameNotFoundException e) {
11440 appName = "An application";
11441 }
11442 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11443 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011444 }
11445
11446 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011447 * Register an IMS connection state callback
11448 */
11449 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011450 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11451 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011452 if (feature == ImsFeature.FEATURE_MMTEL) {
11453 // ImsMmTelManager
11454 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11455 TelephonyPermissions
11456 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11457 mApp, subId, "registerImsStateCallback");
11458 } else if (feature == ImsFeature.FEATURE_RCS) {
11459 // ImsRcsManager or SipDelegateManager
11460 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11461 Binder.getCallingUid(), "registerImsStateCallback",
11462 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11463 Manifest.permission.READ_PRECISE_PHONE_STATE,
11464 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11465 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11466 }
11467
11468 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11469 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11470 "IMS not available on device.");
11471 }
11472
11473 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11474 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11475 }
11476
11477 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11478 if (controller == null) {
11479 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11480 "IMS not available on device.");
11481 }
11482
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011483 if (callingPackage == null) {
11484 callingPackage = getCurrentPackageName();
11485 }
11486
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011487 final long token = Binder.clearCallingIdentity();
11488 try {
11489 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011490 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011491 } catch (ImsException e) {
11492 throw new ServiceSpecificException(e.getCode());
11493 } finally {
11494 Binder.restoreCallingIdentity(token);
11495 }
11496 }
11497
11498 /**
11499 * Unregister an IMS connection state callback
11500 */
11501 @Override
11502 public void unregisterImsStateCallback(IImsStateCallback cb) {
11503 final long token = Binder.clearCallingIdentity();
11504 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11505 if (controller == null) {
11506 return;
11507 }
11508 try {
11509 controller.unregisterImsStateCallback(cb);
11510 } finally {
11511 Binder.restoreCallingIdentity(token);
11512 }
11513 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011514
11515 /**
11516 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11517 *
11518 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11519 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11520 * SecurityException.
11521 * If there is current registered network this value will be same as the registered cell
11522 * identity. If the device goes out of service the previous cell identity is cached and
11523 * will be returned. If the cache age of the Cell identity is more than 24 hours
11524 * it will be cleared and null will be returned.
11525 *
11526 */
11527 @Override
11528 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11529 String callingFeatureId) {
11530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11531 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11532 LocationAccessPolicy.checkLocationPermission(mApp,
11533 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11534 .setCallingPackage(callingPackage)
11535 .setCallingFeatureId(callingFeatureId)
11536 .setCallingPid(Binder.getCallingPid())
11537 .setCallingUid(Binder.getCallingUid())
11538 .setMethod("getLastKnownCellIdentity")
11539 .setLogAsInfo(true)
11540 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11541 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11542 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11543 .build());
11544
11545 boolean hasFinePermission =
11546 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11547 if (!hasFinePermission
11548 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11549 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011550 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011551 }
11552
11553 final long identity = Binder.clearCallingIdentity();
11554 try {
11555 Phone phone = getPhone(subId);
11556 if (phone == null) return null;
11557 ServiceStateTracker sst = phone.getServiceStateTracker();
11558 if (sst == null) return null;
11559 return sst.getLastKnownCellIdentity();
11560 } finally {
11561 Binder.restoreCallingIdentity(identity);
11562 }
11563 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011564
jimsun3b9ccac2021-10-26 15:01:23 +080011565 /**
11566 * Sets the modem service class Name that Telephony will bind to.
11567 *
11568 * @param serviceName The class name of the modem service.
11569 * @return true if the operation is succeed, otherwise false.
11570 */
11571 public boolean setModemService(String serviceName) {
11572 Log.d(LOG_TAG, "setModemService - " + serviceName);
11573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11575 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11576 "setModemService");
11577 return mPhoneConfigurationManager.setModemService(serviceName);
11578 }
11579
11580 /**
11581 * Return the class name of the currently bounded modem service.
11582 *
11583 * @return the class name of the modem service.
11584 */
11585 public String getModemService() {
11586 String result;
11587 Log.d(LOG_TAG, "getModemService");
11588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11589 TelephonyPermissions
11590 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11591 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11592 "getModemService");
11593 result = mPhoneConfigurationManager.getModemService();
11594 Log.d(LOG_TAG, "result = " + result);
11595 return result;
11596 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011597
11598 @Override
11599 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11600 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11601 mApp.enforceCallingOrSelfPermission(
11602 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11604
11605 final long identity = Binder.clearCallingIdentity();
11606 try {
11607 Phone phone = getPhone(subId);
11608 if (phone == null) return;
11609 phone.setVoiceServiceStateOverride(hasService);
11610 } finally {
11611 Binder.restoreCallingIdentity(identity);
11612 }
11613 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011614
11615 /**
11616 * set removable eSIM as default eUICC.
11617 *
11618 * @hide
11619 */
11620 @Override
11621 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11622 enforceModifyPermission();
11623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11624
11625 final long identity = Binder.clearCallingIdentity();
11626 try {
11627 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11628 } finally {
11629 Binder.restoreCallingIdentity(identity);
11630 }
11631 }
11632
11633 /**
11634 * Returns whether the removable eSIM is default eUICC or not.
11635 *
11636 * @hide
11637 */
11638 @Override
11639 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11640 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11642
11643 final long identity = Binder.clearCallingIdentity();
11644 try {
11645 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11646 } finally {
11647 Binder.restoreCallingIdentity(identity);
11648 }
11649 }
11650
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011651 /**
11652 * Get the component name of the default app to direct respond-via-message intent for the
11653 * user associated with this subscription, update the cache if there is no respond-via-message
11654 * application currently configured for this user.
11655 * @return component name of the app and class to direct Respond Via Message intent to, or
11656 * {@code null} if the functionality is not supported.
11657 * @hide
11658 */
11659 @Override
11660 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11661 boolean updateIfNeeded) {
11662 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011663
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011664 Context context = getPhone(subId).getContext();
11665 UserHandle userHandle = null;
11666 final long identity = Binder.clearCallingIdentity();
11667 try {
11668 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11669 } finally {
11670 Binder.restoreCallingIdentity(identity);
11671 }
11672 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11673 updateIfNeeded, userHandle);
11674 }
Jack Yuf5badd92022-12-08 00:50:53 -080011675
11676 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011677 * Set whether the device is able to connect with null ciphering or integrity
11678 * algorithms. This is a global setting and will apply to all active subscriptions
11679 * and all new subscriptions after this.
11680 *
11681 * @param enabled when true, null cipher and integrity algorithms are allowed.
11682 * @hide
11683 */
11684 @Override
11685 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11686 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11687 enforceModifyPermission();
11688 checkForNullCipherAndIntegritySupport();
11689
11690 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11691 // for listening to these preference changes and applying them immediately.
11692 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11693 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11694 editor.apply();
11695
11696 for (Phone phone: PhoneFactory.getPhones()) {
11697 phone.handleNullCipherEnabledChange();
11698 }
11699 }
11700
11701
11702 /**
11703 * Get whether the device is able to connect with null ciphering or integrity
11704 * algorithms. Note that this retrieves the phone-global preference and not
11705 * the state of the radio.
11706 *
11707 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11708 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11709 * version for this feature.
11710 * @hide
11711 */
11712 @Override
11713 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11714 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11715 enforceReadPermission();
11716 checkForNullCipherAndIntegritySupport();
11717 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11718 }
11719
11720 private void checkForNullCipherAndIntegritySupport() {
11721 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11722 throw new UnsupportedOperationException(
11723 "Null cipher and integrity operations require HAL 2.1 or above");
11724 }
11725 }
11726
11727 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011728 * Get the SIM state for the slot index.
11729 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11730 *
11731 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11732 */
11733 @Override
11734 @SimState
11735 public int getSimStateForSlotIndex(int slotIndex) {
11736 IccCardConstants.State simState;
11737 if (slotIndex < 0) {
11738 simState = IccCardConstants.State.UNKNOWN;
11739 } else {
11740 Phone phone = null;
11741 try {
11742 phone = PhoneFactory.getPhone(slotIndex);
11743 } catch (IllegalStateException e) {
11744 // ignore
11745 }
11746 if (phone == null) {
11747 simState = IccCardConstants.State.UNKNOWN;
11748 } else {
11749 IccCard icc = phone.getIccCard();
11750 if (icc == null) {
11751 simState = IccCardConstants.State.UNKNOWN;
11752 } else {
11753 simState = icc.getState();
11754 }
11755 }
11756 }
11757 return simState.ordinal();
11758 }
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011759}