blob: f3028cfb3b99633ed7f808c2107520eeb7d732fd [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
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
28import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080029
Shuo Qianccbaf742021-02-22 18:32:21 -080030import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
31import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070032import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070033import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000034import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070035
Brad Ebinger34c09a52021-02-17 23:23:21 +000036import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080037import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080038import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070039import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080041import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080043import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070044import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000045import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080046import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000047import android.compat.annotation.ChangeId;
48import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000049import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070050import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070051import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.content.Context;
53import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070055import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070056import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.net.Uri;
58import android.os.AsyncResult;
59import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080060import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080062import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070064import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080065import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080066import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.Looper;
68import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070069import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080070import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070071import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080073import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080074import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070075import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070076import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080077import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000078import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000159import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteDatagramCallback;
Duke Lee8852e512024-10-06 12:55:43 +0900161import android.telephony.satellite.ISatelliteDisallowedReasonsCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000162import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000164import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800165import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000166import android.telephony.satellite.NtnSignalStrength;
167import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800168import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000169import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800171import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800172import android.telephony.satellite.SatelliteProvisionStateCallback;
Hyosun Kimb11f3ea2024-08-07 23:35:59 +0000173import android.telephony.satellite.SatelliteSubscriberInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700176import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800178import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Andrew Lee312e8172014-10-23 17:01:36 -0700180import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800181import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800182import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800183import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800184import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700186import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700187import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800188import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800189import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800192import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700193import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800194import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800195import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800196import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000198import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800200import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800202import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800203import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800204import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700205import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700206import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700207import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700209import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800210import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700211import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700212import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700213import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700214import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800215import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800216import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700217import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000218import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700219import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700220import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800221import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800222import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800223import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700224import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000225import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700227import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700228import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800229import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700230import com.android.internal.telephony.imsphone.ImsPhone;
231import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000232import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800233import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000234import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800235import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
236import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700237import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238import com.android.internal.telephony.uicc.IccIoResult;
239import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700241import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000244import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800245import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800247import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000248import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700249import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700250import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800251import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800252import com.android.phone.callcomposer.CallComposerPictureManager;
253import com.android.phone.callcomposer.CallComposerPictureTransfer;
254import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800255import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000256import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700257import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700258import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000259import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800261import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700262import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700263import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800264import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800265import com.android.services.telephony.TelecomAccountRegistry;
266import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000267import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800268import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800269
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700271import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800272import java.io.IOException;
273import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700274import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000277import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800278import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800279import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800280import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800281import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100282import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700284import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800285import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800286import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700287import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800288import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800289import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800290import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
292/**
293 * Implementation of the ITelephony interface.
294 */
Santos Cordon117fee72014-05-16 17:56:12 -0700295public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 private static final String LOG_TAG = "PhoneInterfaceManager";
297 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
298 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800299 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
301 // Message codes used with mMainThreadHandler
302 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700303 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
304 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 private static final int CMD_OPEN_CHANNEL = 9;
306 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
307 private static final int CMD_CLOSE_CHANNEL = 11;
308 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800309 private static final int CMD_NV_READ_ITEM = 13;
310 private static final int EVENT_NV_READ_ITEM_DONE = 14;
311 private static final int CMD_NV_WRITE_ITEM = 15;
312 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
313 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
314 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700315 private static final int CMD_RESET_MODEM_CONFIG = 19;
316 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800317 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
318 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800319 private static final int CMD_SEND_ENVELOPE = 25;
320 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700321 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
322 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
323 private static final int CMD_EXCHANGE_SIM_IO = 31;
324 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
326 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700327 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
328 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700329 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
330 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700331 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
332 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
333 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
334 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700335 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
336 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
337 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
338 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700339 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800340 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
341 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000342 private static final int CMD_SWITCH_SLOTS = 50;
343 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
345 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
346 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
347 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
348 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
349 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
350 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
351 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700352 private static final int CMD_GET_ALL_CELL_INFO = 60;
353 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
354 private static final int CMD_GET_CELL_LOCATION = 62;
355 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700356 private static final int CMD_MODEM_REBOOT = 64;
357 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700358 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
359 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800360 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
361 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700362 private static final int CMD_GET_MODEM_STATUS = 70;
363 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700364 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
365 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700366 private static final int CMD_ERASE_MODEM_CONFIG = 74;
367 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800368 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
369 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
370 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
371 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800372 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
373 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800375 private static final int CMD_GET_CALL_FORWARDING = 83;
376 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
377 private static final int CMD_SET_CALL_FORWARDING = 85;
378 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
379 private static final int CMD_GET_CALL_WAITING = 87;
380 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
381 private static final int CMD_SET_CALL_WAITING = 89;
382 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700383 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
384 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
385 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
386 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700387 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
388 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800389 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
390 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391 private static final int CMD_SET_DATA_THROTTLING = 99;
392 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800393 private static final int CMD_SET_SIM_POWER = 101;
394 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800395 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
396 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
397 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
398 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800399 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
400 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000401 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800402 private static final int CMD_GET_SLICING_CONFIG = 110;
403 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800404 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700405 private static final int CMD_ENABLE_VONR = 113;
406 private static final int EVENT_ENABLE_VONR_DONE = 114;
407 private static final int CMD_IS_VONR_ENABLED = 115;
408 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700409 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
410 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000411
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800412 // Parameters of select command.
413 private static final int SELECT_COMMAND = 0xA4;
414 private static final int SELECT_P1 = 0x04;
415 private static final int SELECT_P2 = 0;
416 private static final int SELECT_P3 = 0x10;
417
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000418 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
419 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000420 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
421 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600422 // Null cipher notification support was added in IRadioNetwork 2.2
423 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 /** The singleton instance. */
426 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800427 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000430 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800431 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final CallManager mCM;
433 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000434
435 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800436 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800439 private final SharedPreferences mTelephonySharedPreferences;
440 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800441 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700442 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000443 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000444 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Jack Yu26735292024-09-25 14:33:49 -0700446 @Nullable
447 private ComponentName mTestEuiccUiComponent;
448
Peter Wangdafb9ac2020-01-15 14:13:38 -0800449 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800450 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800451 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800452 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800453
Derek Tan97ebb422014-09-05 16:55:38 -0700454 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
455 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800456 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800457 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700458
Michelecea4cf22018-12-21 15:00:11 -0800459 // String to store multi SIM allowed
460 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
461
Derek Tan740e1672017-06-27 14:56:27 -0700462 // The AID of ISD-R.
463 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
464
yinxub1bed742017-04-17 11:45:04 -0700465 private NetworkScanRequestTracker mNetworkScanRequestTracker;
466
David Kelly5e06a7f2018-03-12 14:10:59 +0000467 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
468 private static final int MANUFACTURER_CODE_LENGTH = 8;
469
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800470 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800471 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800472
Sarah Chin2ec39f62022-08-31 17:03:26 -0700473 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
474 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
475
Derek Tan89e89d42014-07-08 17:00:10 -0700476 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700477 * Experiment flag to enable erase modem config on reset network, default value is false
478 */
479 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
480 "reset_network_erase_modem_config_enabled";
481
Nathan Harolddc3bcec2024-05-16 14:06:40 -0700482 private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800483
Gary Jian76280a42022-12-07 16:18:33 +0800484 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
485
arunvoddub1365e62024-07-31 09:42:31 +0000486 private static final int LINE1_NUMBER_MAX_LEN = 50;
487
sandeepjsb6c87872021-09-27 15:34:44 +0000488 /**
489 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
490 * one ICCID active at the same time.
491 * Apps should use below API signatures if targeting SDK is T and beyond.
492 *
493 * @hide
494 */
495 @ChangeId
496 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
497 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800498
Naina Nallurid63128d2019-09-17 14:10:30 -0700499 /**
Chen Xu540470b2021-12-14 17:15:47 -0800500 * Apps targeting on Android T and beyond will get exception whenever icc close channel
501 * operation fails.
502 */
503 @ChangeId
504 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
505 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
506
507 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 * A request object to use for transmitting data to an ICC.
509 */
510 private static final class IccAPDUArgument {
511 public int channel, cla, command, p1, p2, p3;
512 public String data;
513
514 public IccAPDUArgument(int channel, int cla, int command,
515 int p1, int p2, int p3, String data) {
516 this.channel = channel;
517 this.cla = cla;
518 this.command = command;
519 this.p1 = p1;
520 this.p2 = p2;
521 this.p3 = p3;
522 this.data = data;
523 }
524 }
525
526 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700527 * A request object to use for transmitting data to an ICC.
528 */
529 private static final class ManualNetworkSelectionArgument {
530 public OperatorInfo operatorInfo;
531 public boolean persistSelection;
532
533 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
534 this.operatorInfo = operatorInfo;
535 this.persistSelection = persistSelection;
536 }
537 }
538
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 private static final class PurchasePremiumCapabilityArgument {
540 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 public @NonNull IIntegerConsumer callback;
542
543 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800544 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700545 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700546 this.callback = callback;
547 }
548 }
549
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700550 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
552 * request after sending. The main thread will notify the request when it is complete.
553 */
554 private static final class MainThreadRequest {
555 /** The argument to use for the request */
556 public Object argument;
557 /** The result of the request that is run on the main thread */
558 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800559 // The subscriber id that this request applies to. Defaults to
560 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
561 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562
Nathan Harold92bed182018-10-12 18:16:49 -0700563 // In cases where subId is unavailable, the caller needs to specify the phone.
564 public Phone phone;
565
vagdeviaf9a5b92018-08-15 16:01:53 -0700566 public WorkSource workSource;
567
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 public MainThreadRequest(Object argument) {
569 this.argument = argument;
570 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800571
Nathan Harold92bed182018-10-12 18:16:49 -0700572 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
573 this.argument = argument;
574 if (phone != null) {
575 this.phone = phone;
576 }
577 this.workSource = workSource;
578 }
579
vagdeviaf9a5b92018-08-15 16:01:53 -0700580 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800581 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800582 if (subId != null) {
583 this.subId = subId;
584 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700585 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587 }
588
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800589 private static final class IncomingThirdPartyCallArgs {
590 public final ComponentName component;
591 public final String callId;
592 public final String callerDisplayName;
593
594 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
595 String callerDisplayName) {
596 this.component = component;
597 this.callId = callId;
598 this.callerDisplayName = callerDisplayName;
599 }
600 }
601
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602 /**
603 * A handler that processes messages on the main thread in the phone process. Since many
604 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
605 * inbound binder threads to the main thread in the phone process. The Binder thread
606 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
607 * on, which will be notified when the operation completes and will contain the result of the
608 * request.
609 *
610 * <p>If a MainThreadRequest object is provided in the msg.obj field,
611 * note that request.result must be set to something non-null for the calling thread to
612 * unblock.
613 */
614 private final class MainThreadHandler extends Handler {
615 @Override
616 public void handleMessage(Message msg) {
617 MainThreadRequest request;
618 Message onCompleted;
619 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000620 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800622 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700623
624 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 case CMD_HANDLE_USSD_REQUEST: {
626 request = (MainThreadRequest) msg.obj;
627 final Phone phone = getPhoneFromRequest(request);
628 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800629 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700631
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 if (!isUssdApiAllowed(request.subId)) {
633 // Carrier does not support use of this API, return failure.
634 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
635 UssdResponse response = new UssdResponse(ussdRequest, null);
636 Bundle returnData = new Bundle();
637 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
638 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700639
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 request.result = true;
641 notifyRequester(request);
642 return;
643 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700644
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 try {
646 request.result = phone != null
647 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
648 } catch (CallStateException cse) {
649 request.result = false;
650 }
651 // Wake up the requesting thread
652 notifyRequester(request);
653 break;
pkanwar32d516d2016-10-14 19:37:38 -0700654 }
655
Yorke Lee716f67e2015-06-17 15:39:16 -0700656 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700658 final Phone phone = getPhoneFromRequest(request);
659 request.result = phone != null ?
660 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
661 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700664 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700666
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort = getUiccPortFromRequest(request);
671 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800673 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800677 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000678 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800679 iccArgument.channel, iccArgument.cla, iccArgument.command,
680 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
681 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 ar = (AsyncResult) msg.obj;
687 request = (MainThreadRequest) ar.userObj;
688 if (ar.exception == null && ar.result != null) {
689 request.result = ar.result;
690 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800691 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.result == null) {
693 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800694 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800696 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 } else {
698 loge("iccTransmitApduLogicalChannel: Unknown exception");
699 }
700 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
705 request = (MainThreadRequest) msg.obj;
706 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000707 uiccPort = getUiccPortFromRequest(request);
708 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800710 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 } else {
713 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000715 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800716 iccArgument.cla, iccArgument.command, iccArgument.p1,
717 iccArgument.p2,
718 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 }
720 break;
721
722 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
725 if (ar.exception == null && ar.result != null) {
726 request.result = ar.result;
727 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800728 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 if (ar.result == null) {
730 loge("iccTransmitApduBasicChannel: Empty response");
731 } else if (ar.exception instanceof CommandException) {
732 loge("iccTransmitApduBasicChannel: CommandException: " +
733 ar.exception);
734 } else {
735 loge("iccTransmitApduBasicChannel: Unknown exception");
736 }
737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 break;
740
741 case CMD_EXCHANGE_SIM_IO:
742 request = (MainThreadRequest) msg.obj;
743 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000744 uiccPort = getUiccPortFromRequest(request);
745 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800747 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700749 } else {
750 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
751 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000752 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
754 iccArgument.data, onCompleted);
755 }
756 break;
757
758 case EVENT_EXCHANGE_SIM_IO_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result;
763 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800764 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700767 break;
768
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 case CMD_SEND_ENVELOPE:
770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000771 uiccPort = getUiccPortFromRequest(request);
772 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800774 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700776 } else {
777 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800778 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800780 break;
781
782 case EVENT_SEND_ENVELOPE_DONE:
783 ar = (AsyncResult) msg.obj;
784 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700785 if (ar.exception == null && ar.result != null) {
786 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800787 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800788 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700789 if (ar.result == null) {
790 loge("sendEnvelopeWithStatus: Empty response");
791 } else if (ar.exception instanceof CommandException) {
792 loge("sendEnvelopeWithStatus: CommandException: " +
793 ar.exception);
794 } else {
795 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
796 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800797 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800799 break;
800
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 case CMD_OPEN_CHANNEL:
802 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000803 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800804 IccLogicalChannelRequest openChannelRequest =
805 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000806 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700807 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800808 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800809 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700810 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700811 } else {
812 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800813 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
814 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 break;
817
818 case EVENT_OPEN_CHANNEL_DONE:
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700821 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700822 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700823 int[] result = (int[]) ar.result;
824 int channelId = result[0];
825 byte[] selectResponse = null;
826 if (result.length > 1) {
827 selectResponse = new byte[result.length - 1];
828 for (int i = 1; i < result.length; ++i) {
829 selectResponse[i - 1] = (byte) result[i];
830 }
831 }
832 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800833 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800834
835 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700836 if (uiccPort == null) {
837 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
838 } else {
839 IccLogicalChannelRequest channelRequest =
840 (IccLogicalChannelRequest) request.argument;
841 channelRequest.channel = channelId;
842 uiccPort.onLogicalChannelOpened(channelRequest);
843 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700845 if (ar.result == null) {
846 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700848 if (ar.exception != null) {
849 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
850 }
851
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700852 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700853 if (ar.exception instanceof CommandException) {
854 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800855 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700856 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700857 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700858 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700859 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700860 }
861 }
862 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800863 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700865 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700867 break;
868
869 case CMD_CLOSE_CHANNEL:
870 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000871 uiccPort = getUiccPortFromRequest(request);
872 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700873 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800874 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800875 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800876 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700877 } else {
878 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000879 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700880 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 break;
882
883 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null) {
887 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800888 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700889 if (uiccPort == null) {
890 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
891 } else {
892 final int channelId = (Integer) request.argument;
893 uiccPort.onLogicalChannelClosed(channelId);
894 }
Chen Xu540470b2021-12-14 17:15:47 -0800895 } else {
896 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800897 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800898 if (ar.exception instanceof CommandException) {
899 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
900 CommandException.Error error =
901 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800902 if (error == CommandException.Error.INVALID_ARGUMENTS) {
903 // should only throw exceptions from the binder threads.
904 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800905 "iccCloseLogicalChannel: invalid argument ");
906 }
907 } else {
908 loge("iccCloseLogicalChannel: Unknown exception");
909 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800910 request.result = (exception != null) ? exception :
911 new IllegalStateException(
912 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800913 }
914 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800915 break;
916
917 case CMD_NV_READ_ITEM:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
921 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800922 break;
923
924 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 ar = (AsyncResult) msg.obj;
926 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800927 if (ar.exception == null && ar.result != null) {
928 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700929 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800930 request.result = "";
931 if (ar.result == null) {
932 loge("nvReadItem: Empty response");
933 } else if (ar.exception instanceof CommandException) {
934 loge("nvReadItem: CommandException: " +
935 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700936 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800937 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700938 }
939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700941 break;
942
Jake Hambye994d462014-02-03 13:10:13 -0800943 case CMD_NV_WRITE_ITEM:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
946 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800947 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700948 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800949 break;
950
951 case EVENT_NV_WRITE_ITEM_DONE:
952 handleNullReturnEvent(msg, "nvWriteItem");
953 break;
954
955 case CMD_NV_WRITE_CDMA_PRL:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800958 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800959 break;
960
961 case EVENT_NV_WRITE_CDMA_PRL_DONE:
962 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
963 break;
964
chen xu6dac5ab2018-10-26 17:39:23 -0700965 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800966 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700967 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800968 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800969 break;
970
chen xu6dac5ab2018-10-26 17:39:23 -0700971 case EVENT_RESET_MODEM_CONFIG_DONE:
972 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800973 break;
974
Sooraj Sasindran37444802020-08-11 10:40:43 -0700975 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
978 request);
979 Phone phone = getPhoneFromRequest(request);
980 if (phone != null) {
981 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
982 } else {
983 loge("isNRDualConnectivityEnabled: No phone object");
984 request.result = false;
985 notifyRequester(request);
986 }
987 break;
988 }
989
990 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 if (ar.exception == null && ar.result != null) {
994 request.result = ar.result;
995 } else {
996 // request.result must be set to something non-null
997 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700998 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700999 request.result = ar.result;
1000 } else {
1001 request.result = false;
1002 }
1003 if (ar.result == null) {
1004 loge("isNRDualConnectivityEnabled: Empty response");
1005 } else if (ar.exception instanceof CommandException) {
1006 loge("isNRDualConnectivityEnabled: CommandException: "
1007 + ar.exception);
1008 } else {
1009 loge("isNRDualConnectivityEnabled: Unknown exception");
1010 }
1011 }
1012 notifyRequester(request);
1013 break;
1014
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001015 case CMD_IS_VONR_ENABLED: {
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1018 request);
1019 Phone phone = getPhoneFromRequest(request);
1020 if (phone != null) {
1021 phone.isVoNrEnabled(onCompleted, request.workSource);
1022 } else {
1023 loge("isVoNrEnabled: No phone object");
1024 request.result = false;
1025 notifyRequester(request);
1026 }
1027 break;
1028 }
1029
1030 case EVENT_IS_VONR_ENABLED_DONE:
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 if (ar.exception == null && ar.result != null) {
1034 request.result = ar.result;
1035 } else {
1036 // request.result must be set to something non-null
1037 // for the calling thread to unblock
1038 if (ar.result != null) {
1039 request.result = ar.result;
1040 } else {
1041 request.result = false;
1042 }
1043 if (ar.result == null) {
1044 loge("isVoNrEnabled: Empty response");
1045 } else if (ar.exception instanceof CommandException) {
1046 loge("isVoNrEnabled: CommandException: "
1047 + ar.exception);
1048 } else {
1049 loge("isVoNrEnabled: Unknown exception");
1050 }
1051 }
1052 notifyRequester(request);
1053 break;
1054
Sooraj Sasindran37444802020-08-11 10:40:43 -07001055 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1056 request = (MainThreadRequest) msg.obj;
1057 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1058 Phone phone = getPhoneFromRequest(request);
1059 if (phone != null) {
1060 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1061 request.workSource);
1062 } else {
1063 loge("enableNrDualConnectivity: No phone object");
1064 request.result =
1065 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1066 notifyRequester(request);
1067 }
1068 break;
1069 }
1070
1071 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 if (ar.exception == null) {
1075 request.result =
1076 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1077 } else {
1078 request.result =
1079 TelephonyManager
1080 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1081 if (ar.exception instanceof CommandException) {
1082 CommandException.Error error =
1083 ((CommandException) (ar.exception)).getCommandError();
1084 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1085 request.result =
1086 TelephonyManager
1087 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001088 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1089 request.result =
1090 TelephonyManager
1091 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001092 }
1093 loge("enableNrDualConnectivity" + ": CommandException: "
1094 + ar.exception);
1095 } else {
1096 loge("enableNrDualConnectivity" + ": Unknown exception");
1097 }
1098 }
1099 notifyRequester(request);
1100 break;
1101 }
1102
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001103 case CMD_ENABLE_VONR: {
1104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1106 Phone phone = getPhoneFromRequest(request);
1107 if (phone != null) {
1108 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1109 request.workSource);
1110 } else {
1111 loge("setVoNrEnabled: No phone object");
1112 request.result =
1113 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1114 notifyRequester(request);
1115 }
1116 break;
1117 }
1118
1119 case EVENT_ENABLE_VONR_DONE: {
1120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
1122 if (ar.exception == null) {
1123 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1124 } else {
1125 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1126 if (ar.exception instanceof CommandException) {
1127 CommandException.Error error =
1128 ((CommandException) (ar.exception)).getCommandError();
1129 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1130 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1131 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1132 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1133 } else {
1134 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1135 }
1136 loge("setVoNrEnabled" + ": CommandException: "
1137 + ar.exception);
1138 } else {
1139 loge("setVoNrEnabled" + ": Unknown exception");
1140 }
1141 }
1142 notifyRequester(request);
1143 break;
1144 }
1145
SongFerngWang3ef3e072020-12-21 16:41:52 +08001146 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1149 request);
1150 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 break;
1152
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 if (ar.exception == null && ar.result != null) {
1157 request.result = ar.result; // Integer
1158 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301159 // request.result must be set to something non-null
1160 // for the calling thread to unblock
1161 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001165 loge("getAllowedNetworkTypesBitmask: CommandException: "
1166 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 }
1170 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001172 break;
1173
SongFerngWang3ef3e072020-12-21 16:41:52 +08001174 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001175 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001176 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1177 request);
1178 Pair<Integer, Long> reasonWithNetworkTypes =
1179 (Pair<Integer, Long>) request.argument;
1180 getPhoneFromRequest(request).setAllowedNetworkTypes(
1181 reasonWithNetworkTypes.first,
1182 reasonWithNetworkTypes.second,
1183 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001184 break;
1185
SongFerngWang3ef3e072020-12-21 16:41:52 +08001186 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1187 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001188 break;
1189
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001190 case CMD_SET_VOICEMAIL_NUMBER:
1191 request = (MainThreadRequest) msg.obj;
1192 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1193 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001194 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1195 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001196 break;
1197
1198 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1199 handleNullReturnEvent(msg, "setVoicemailNumber");
1200 break;
1201
Stuart Scott54788802015-03-30 13:18:01 -07001202 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1205 request);
1206 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1207 break;
1208
1209 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1210 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1211 break;
1212
Shishir Agrawal302c8692015-06-19 13:49:39 -07001213 case CMD_PERFORM_NETWORK_SCAN:
1214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1216 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1217 break;
1218
Hall Liu27d24262020-09-18 19:04:59 -07001219 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001222 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1223 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1224 request.argument;
1225 int callForwardingReason = args.first;
1226 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001227 break;
Hall Liu27d24262020-09-18 19:04:59 -07001228 }
1229 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001232 TelephonyManager.CallForwardingInfoCallback callback =
1233 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1234 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001235 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001236 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001237 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1238 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1239 // Service Class is a bit mask per 3gpp 27.007. Search for
1240 // any service for voice call.
1241 if ((callForwardInfo.serviceClass
1242 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001243 callForwardingInfo = new CallForwardingInfo(
1244 callForwardInfo.status
1245 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001246 callForwardInfo.reason,
1247 callForwardInfo.number,
1248 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001249 break;
1250 }
1251 }
1252 // Didn't find a call forward info for voice call.
1253 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001254 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1255 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 }
Hall Liu27d24262020-09-18 19:04:59 -07001257 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 } else {
1259 if (ar.result == null) {
1260 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1261 }
1262 if (ar.exception != null) {
1263 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1264 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 int errorCode = TelephonyManager
1266 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 if (ar.exception instanceof CommandException) {
1268 CommandException.Error error =
1269 ((CommandException) (ar.exception)).getCommandError();
1270 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001271 errorCode = TelephonyManager
1272 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001274 errorCode = TelephonyManager
1275 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 }
1277 }
Hall Liu27d24262020-09-18 19:04:59 -07001278 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280 break;
Hall Liu27d24262020-09-18 19:04:59 -07001281 }
Shuo Qian4a594052020-01-23 11:59:30 -08001282
Hall Liu27d24262020-09-18 19:04:59 -07001283 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001284 request = (MainThreadRequest) msg.obj;
1285 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001286 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001287 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001288 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1289 request.argument).first;
1290 request.phone.setCallForwardingOption(
1291 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001292 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001293 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001294 callForwardingInfoToSet.getReason(),
1295 callForwardingInfoToSet.getNumber(),
1296 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1297 break;
Hall Liu27d24262020-09-18 19:04:59 -07001298 }
Shuo Qian4a594052020-01-23 11:59:30 -08001299
Hall Liu27d24262020-09-18 19:04:59 -07001300 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 ar = (AsyncResult) msg.obj;
1302 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001303 Consumer<Integer> callback =
1304 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1305 request.argument).second;
1306 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001307 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 int errorCode = TelephonyManager.CallForwardingInfoCallback
1309 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001310 if (ar.exception instanceof CommandException) {
1311 CommandException.Error error =
1312 ((CommandException) (ar.exception)).getCommandError();
1313 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001314 errorCode = TelephonyManager.CallForwardingInfoCallback
1315 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001316 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001317 errorCode = TelephonyManager.CallForwardingInfoCallback
1318 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001319 }
1320 }
1321 callback.accept(errorCode);
1322 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001323 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001324 }
Shuo Qian4a594052020-01-23 11:59:30 -08001325 break;
Hall Liu27d24262020-09-18 19:04:59 -07001326 }
Shuo Qian4a594052020-01-23 11:59:30 -08001327
Hall Liu27d24262020-09-18 19:04:59 -07001328 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001329 request = (MainThreadRequest) msg.obj;
1330 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1331 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1332 break;
Hall Liu27d24262020-09-18 19:04:59 -07001333 }
Shuo Qian4a594052020-01-23 11:59:30 -08001334
Hall Liu27d24262020-09-18 19:04:59 -07001335 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001338 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001339 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001340 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001341 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001342 // Service Class is a bit mask per 3gpp 27.007.
1343 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001344 if (callForwardResults.length > 1
1345 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001346 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001348 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1349 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001350 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001351 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001352 }
1353 } else {
1354 if (ar.result == null) {
1355 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1356 }
1357 if (ar.exception != null) {
1358 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1359 }
1360 if (ar.exception instanceof CommandException) {
1361 CommandException.Error error =
1362 ((CommandException) (ar.exception)).getCommandError();
1363 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001364 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001365 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1367 callWaitingStatus =
1368 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001369 }
1370 }
1371 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001372 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001373 break;
Hall Liu27d24262020-09-18 19:04:59 -07001374 }
Shuo Qian4a594052020-01-23 11:59:30 -08001375
Hall Liu27d24262020-09-18 19:04:59 -07001376 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001379 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1380 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001381 break;
Hall Liu27d24262020-09-18 19:04:59 -07001382 }
Shuo Qian4a594052020-01-23 11:59:30 -08001383
Hall Liu27d24262020-09-18 19:04:59 -07001384 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001387 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1388 Consumer<Integer> callback =
1389 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1390 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001391 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001392 if (ar.exception instanceof CommandException) {
1393 CommandException.Error error =
1394 ((CommandException) (ar.exception)).getCommandError();
1395 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1396 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001397 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1398 callback.accept(
1399 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001400 } else {
1401 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1402 }
1403 } else {
1404 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1405 }
1406 } else {
1407 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1408 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001409 }
Shuo Qian4a594052020-01-23 11:59:30 -08001410 break;
Hall Liu27d24262020-09-18 19:04:59 -07001411 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 CellNetworkScanResult cellScanResult;
1416 if (ar.exception == null && ar.result != null) {
1417 cellScanResult = new CellNetworkScanResult(
1418 CellNetworkScanResult.STATUS_SUCCESS,
1419 (List<OperatorInfo>) ar.result);
1420 } else {
1421 if (ar.result == null) {
1422 loge("getCellNetworkScanResults: Empty response");
1423 }
1424 if (ar.exception != null) {
1425 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1426 }
1427 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1428 if (ar.exception instanceof CommandException) {
1429 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001430 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1432 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1433 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1434 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1435 }
1436 }
1437 cellScanResult = new CellNetworkScanResult(errorCode, null);
1438 }
1439 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001440 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 break;
1442
1443 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1444 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001445 ManualNetworkSelectionArgument selArg =
1446 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001447 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1448 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001449 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1450 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001451 break;
1452
1453 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 if (ar.exception == null) {
1457 request.result = true;
1458 } else {
1459 request.result = false;
1460 loge("setNetworkSelectionModeManual " + ar.exception);
1461 }
1462 notifyRequester(request);
1463 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001464 break;
1465
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 case CMD_GET_MODEM_ACTIVITY_INFO:
1467 request = (MainThreadRequest) msg.obj;
1468 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001469 if (defaultPhone != null) {
1470 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 } else {
1472 ResultReceiver result = (ResultReceiver) request.argument;
1473 Bundle bundle = new Bundle();
1474 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001475 new ModemActivityInfo(0, 0, 0,
1476 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001477 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001478 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 break;
1480
Hall Liud0f208c2020-10-14 16:54:44 -07001481 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001484 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001485 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001486 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001487 if (mLastModemActivityInfo == null) {
1488 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1489 mLastModemActivitySpecificInfo[0] =
1490 new ActivityStatsTechSpecificInfo(
1491 0,
1492 0,
1493 new int[ModemActivityInfo.getNumTxPowerLevels()],
1494 0);
1495 mLastModemActivityInfo =
1496 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1497 }
1498
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 // Update the last modem activity info and the result of the request.
1501 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1502 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001503 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001504 } else {
1505 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001506 }
Kai Shi917fdc62022-11-28 14:01:02 -08001507 // This is needed to decouple ret from mLastModemActivityInfo
1508 // We don't want to return mLastModemActivityInfo which is updated
1509 // inside mergeModemActivityInfo()
1510 ret = new ModemActivityInfo(
1511 mLastModemActivityInfo.getTimestampMillis(),
1512 mLastModemActivityInfo.getSleepTimeMillis(),
1513 mLastModemActivityInfo.getIdleTimeMillis(),
1514 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001515
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001516 } else {
1517 if (ar.result == null) {
1518 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001519 error = TelephonyManager.ModemActivityInfoException
1520 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001521 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001522 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001523 error = TelephonyManager.ModemActivityInfoException
1524 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001525 } else {
1526 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001527 error = TelephonyManager.ModemActivityInfoException
1528 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001529 }
1530 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001531 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001532 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001533 bundle.putParcelable(
1534 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001535 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001536 } else {
1537 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1538 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001539 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001541 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001542 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001543
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001544 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001546 CarrierRestrictionRules argument =
1547 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001548 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001549 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001550 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001551 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001552
1553 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1554 ar = (AsyncResult) msg.obj;
1555 request = (MainThreadRequest) ar.userObj;
1556 if (ar.exception == null && ar.result != null) {
1557 request.result = ar.result;
1558 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001559 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1560 if (ar.exception instanceof CommandException) {
1561 loge("setAllowedCarriers: CommandException: " + ar.exception);
1562 CommandException.Error error =
1563 ((CommandException) (ar.exception)).getCommandError();
1564 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1565 request.result =
1566 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1567 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 } else {
1569 loge("setAllowedCarriers: Unknown exception");
1570 }
1571 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001573 break;
1574
1575 case CMD_GET_ALLOWED_CARRIERS:
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001578 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001579 break;
1580
1581 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 if (ar.exception == null && ar.result != null) {
1585 request.result = ar.result;
1586 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001587 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001588 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001589 if (ar.result == null) {
1590 loge("getAllowedCarriers: Empty response");
1591 } else if (ar.exception instanceof CommandException) {
1592 loge("getAllowedCarriers: CommandException: " +
1593 ar.exception);
1594 } else {
1595 loge("getAllowedCarriers: Unknown exception");
1596 }
1597 }
arunvoddud7401012022-12-15 16:08:12 +00001598 if (request.argument != null) {
1599 // This is for the implementation of carrierRestrictionStatus.
1600 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1601 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001602 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001603 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1604 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1605 CarrierRestrictionRules carrierRestrictionRules =
1606 (CarrierRestrictionRules) ar.result;
1607 int carrierId = -1;
1608 try {
1609 CarrierIdentifier carrierIdentifier =
1610 carrierRestrictionRules.getAllowedCarriers().get(0);
1611 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1612 carrierIdentifier);
1613 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1614 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1615 }
1616 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001617 int restrictedStatus =
1618 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1619 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1620 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001621 lockStatus = TelephonyManager
1622 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001623 }
1624 } else {
1625 Rlog.e(LOG_TAG,
1626 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1627 }
1628 callback.accept(lockStatus);
1629 } else {
1630 // This is for the implementation of getAllowedCarriers.
1631 notifyRequester(request);
1632 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001633 break;
1634
Nathan Haroldb3014052017-01-25 15:57:32 -08001635 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception == null && ar.result != null) {
1639 request.result = ar.result;
1640 } else {
1641 request.result = new IllegalArgumentException(
1642 "Failed to retrieve Forbidden Plmns");
1643 if (ar.result == null) {
1644 loge("getForbiddenPlmns: Empty response");
1645 } else {
1646 loge("getForbiddenPlmns: Unknown exception");
1647 }
1648 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001649 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001650 break;
1651
1652 case CMD_GET_FORBIDDEN_PLMNS:
1653 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001654 uiccPort = getUiccPortFromRequest(request);
1655 if (uiccPort == null) {
1656 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001657 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001658 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001659 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001660 break;
1661 }
1662 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001663 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 if (uiccApp == null) {
1665 loge("getForbiddenPlmns() no app with specified type -- "
1666 + appType);
1667 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001668 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001669 break;
1670 } else {
1671 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1672 + " specified type -- " + appType);
1673 }
1674 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1675 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001676 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001677 break;
1678
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 case CMD_SWITCH_SLOTS:
1680 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001681 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001682 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001683 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001684 break;
1685
1686 case EVENT_SWITCH_SLOTS_DONE:
1687 ar = (AsyncResult) msg.obj;
1688 request = (MainThreadRequest) ar.userObj;
1689 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001690 notifyRequester(request);
1691 break;
1692 case CMD_GET_NETWORK_SELECTION_MODE:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1695 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1696 break;
1697
1698 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 if (ar.exception != null) {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1703 } else {
1704 int mode = ((int[]) ar.result)[0];
1705 if (mode == 0) {
1706 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1707 } else {
1708 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1709 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001710 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001711 notifyRequester(request);
1712 break;
1713 case CMD_GET_CDMA_ROAMING_MODE:
1714 request = (MainThreadRequest) msg.obj;
1715 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1716 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1717 break;
1718 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1719 ar = (AsyncResult) msg.obj;
1720 request = (MainThreadRequest) ar.userObj;
1721 if (ar.exception != null) {
1722 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1723 } else {
1724 request.result = ((int[]) ar.result)[0];
1725 }
1726 notifyRequester(request);
1727 break;
1728 case CMD_SET_CDMA_ROAMING_MODE:
1729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1731 int mode = (int) request.argument;
1732 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1733 break;
1734 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 request.result = ar.exception == null;
1738 notifyRequester(request);
1739 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001740 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1743 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1744 break;
1745 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1746 ar = (AsyncResult) msg.obj;
1747 request = (MainThreadRequest) ar.userObj;
1748 if (ar.exception != null) {
1749 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1750 } else {
1751 request.result = ((int[]) ar.result)[0];
1752 }
1753 notifyRequester(request);
1754 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001755 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1756 request = (MainThreadRequest) msg.obj;
1757 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1758 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001759 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1760 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001761 break;
1762 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 request.result = ar.exception == null;
1766 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001767 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 case CMD_GET_ALL_CELL_INFO:
1769 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001770 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001771 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001772 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001773 case EVENT_GET_ALL_CELL_INFO_DONE:
1774 ar = (AsyncResult) msg.obj;
1775 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001776 // If a timeout occurs, the response will be null
1777 request.result = (ar.exception == null && ar.result != null)
1778 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001779 synchronized (request) {
1780 request.notifyAll();
1781 }
1782 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001783 case CMD_REQUEST_CELL_INFO_UPDATE:
1784 request = (MainThreadRequest) msg.obj;
1785 request.phone.requestCellInfoUpdate(request.workSource,
1786 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1787 break;
1788 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1789 ar = (AsyncResult) msg.obj;
1790 request = (MainThreadRequest) ar.userObj;
1791 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1792 try {
1793 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001795 cb.onError(
1796 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1797 ar.exception.getClass().getName(),
1798 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001799 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001800 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001801 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001802 } else {
1803 // use the result as returned
1804 cb.onCellInfo((List<CellInfo>) ar.result);
1805 }
1806 } catch (RemoteException re) {
1807 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1808 }
1809 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 request = (MainThreadRequest) msg.obj;
1812 WorkSource ws = (WorkSource) request.argument;
1813 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001814 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001815 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001816 }
1817 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null) {
1821 request.result = ar.result;
1822 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001823 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001824 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001825 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001826 }
1827
1828 synchronized (request) {
1829 request.notifyAll();
1830 }
1831 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001832 }
chen xu6dac5ab2018-10-26 17:39:23 -07001833 case CMD_MODEM_REBOOT:
1834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001836 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001837 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001838 case EVENT_CMD_MODEM_REBOOT_DONE:
1839 handleNullReturnEvent(msg, "rebootModem");
1840 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001841 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001842 request = (MainThreadRequest) msg.obj;
1843 boolean enable = (boolean) request.argument;
1844 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001845 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001846 PhoneConfigurationManager.getInstance()
1847 .enablePhone(request.phone, enable, onCompleted);
1848 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001849 }
Michele Berionne5e411512020-11-13 02:36:59 +00001850 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001854 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001855 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001856 if ((boolean) request.result) {
1857 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1858 updateModemStateMetrics();
1859 } else {
1860 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1861 + ar.exception);
1862 }
1863 notifyRequester(request);
1864 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001865 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001866 case CMD_GET_MODEM_STATUS:
1867 request = (MainThreadRequest) msg.obj;
1868 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1869 PhoneConfigurationManager.getInstance()
1870 .getPhoneStatusFromModem(request.phone, onCompleted);
1871 break;
1872 case EVENT_GET_MODEM_STATUS_DONE:
1873 ar = (AsyncResult) msg.obj;
1874 request = (MainThreadRequest) ar.userObj;
1875 int id = request.phone.getPhoneId();
1876 if (ar.exception == null && ar.result != null) {
1877 request.result = ar.result;
1878 //update the cache as modem status has changed
1879 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1880 (boolean) request.result);
1881 } else {
1882 // Return true if modem status cannot be retrieved. For most cases,
1883 // modem status is on. And for older version modems, GET_MODEM_STATUS
1884 // and disable modem are not supported. Modem is always on.
1885 // TODO: this should be fixed in R to support a third
1886 // status UNKNOWN b/131631629
1887 request.result = true;
1888 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1889 + ar.exception);
1890 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001891 notifyRequester(request);
1892 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001893 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1894 request = (MainThreadRequest) msg.obj;
1895 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1896 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1897 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1898 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1899 break;
1900 }
1901 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1902 ar = (AsyncResult) msg.obj;
1903 request = (MainThreadRequest) ar.userObj;
1904 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1905 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1906 args.second.accept(ar.exception == null);
1907 notifyRequester(request);
1908 break;
1909 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001910 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1911 request = (MainThreadRequest) msg.obj;
1912 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1913 Phone phone = getPhoneFromRequest(request);
1914 if (phone != null) {
1915 phone.getSystemSelectionChannels(onCompleted);
1916 } else {
1917 loge("getSystemSelectionChannels: No phone object");
1918 request.result = new ArrayList<RadioAccessSpecifier>();
1919 notifyRequester(request);
1920 }
1921 break;
1922 }
1923 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1924 ar = (AsyncResult) msg.obj;
1925 request = (MainThreadRequest) ar.userObj;
1926 if (ar.exception == null && ar.result != null) {
1927 request.result = ar.result;
1928 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001929 request.result = new IllegalStateException(
1930 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001931 if (ar.result == null) {
1932 loge("getSystemSelectionChannels: Empty response");
1933 } else {
1934 loge("getSystemSelectionChannels: Unknown exception");
1935 }
1936 }
1937 notifyRequester(request);
1938 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001939 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1940 ar = (AsyncResult) msg.obj;
1941 request = (MainThreadRequest) ar.userObj;
1942 if (ar.exception == null && ar.result != null) {
1943 request.result = ar.result;
1944 } else {
1945 request.result = -1;
1946 loge("Failed to set Forbidden Plmns");
1947 if (ar.result == null) {
1948 loge("setForbidenPlmns: Empty response");
1949 } else if (ar.exception != null) {
1950 loge("setForbiddenPlmns: Exception: " + ar.exception);
1951 request.result = -1;
1952 } else {
1953 loge("setForbiddenPlmns: Unknown exception");
1954 }
1955 }
1956 notifyRequester(request);
1957 break;
1958 case CMD_SET_FORBIDDEN_PLMNS:
1959 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001960 uiccPort = getUiccPortFromRequest(request);
1961 if (uiccPort == null) {
1962 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001963 request.result = -1;
1964 notifyRequester(request);
1965 break;
1966 }
1967 Pair<Integer, List<String>> setFplmnsArgs =
1968 (Pair<Integer, List<String>>) request.argument;
1969 appType = setFplmnsArgs.first;
1970 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001971 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001972 if (uiccApp == null) {
1973 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1974 request.result = -1;
1975 loge("Failed to get UICC App");
1976 notifyRequester(request);
1977 } else {
1978 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1979 ((SIMRecords) uiccApp.getIccRecords())
1980 .setForbiddenPlmns(onCompleted, fplmns);
1981 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001982 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001983 case CMD_ERASE_MODEM_CONFIG:
1984 request = (MainThreadRequest) msg.obj;
1985 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1986 defaultPhone.eraseModemConfig(onCompleted);
1987 break;
1988 case EVENT_ERASE_MODEM_CONFIG_DONE:
1989 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001990 break;
zoey chene02881a2019-12-30 16:11:23 +08001991
Kai Shif70f46f2021-03-03 13:59:46 -08001992 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1993 request = (MainThreadRequest) msg.obj;
1994 request.result = defaultPhone.eraseDataInSharedPreferences();
1995 notifyRequester(request);
1996 break;
1997
zoey chene02881a2019-12-30 16:11:23 +08001998 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1999 request = (MainThreadRequest) msg.obj;
2000 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2001 Pair<String, String> changed = (Pair<String, String>) request.argument;
2002 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2003 changed.first, changed.second, onCompleted);
2004 break;
2005 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2006 ar = (AsyncResult) msg.obj;
2007 request = (MainThreadRequest) ar.userObj;
2008 if (ar.exception == null) {
2009 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002010 // If the operation is successful, update the PIN storage
2011 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2012 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002013 UiccController.getInstance().getPinStorage()
2014 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002015 } else {
2016 request.result = msg.arg1;
2017 }
2018 notifyRequester(request);
2019 break;
2020
Michele Berionne5e411512020-11-13 02:36:59 +00002021 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002022 request = (MainThreadRequest) msg.obj;
2023 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2024 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2025 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2026 enabled.first, enabled.second, onCompleted);
2027 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002028 }
zoey chene02881a2019-12-30 16:11:23 +08002029 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 if (ar.exception == null) {
2033 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002034 // If the operation is successful, update the PIN storage
2035 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2036 int phoneId = getPhoneFromRequest(request).getPhoneId();
2037 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002038 UiccController.getInstance().getPinStorage()
2039 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002040 } else {
2041 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2042 }
zoey chene02881a2019-12-30 16:11:23 +08002043 } else {
2044 request.result = msg.arg1;
2045 }
Michele Berionne5e411512020-11-13 02:36:59 +00002046
2047
zoey chene02881a2019-12-30 16:11:23 +08002048 notifyRequester(request);
2049 break;
2050
Peter Wangdafb9ac2020-01-15 14:13:38 -08002051 case MSG_NOTIFY_USER_ACTIVITY:
2052 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002053 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002054 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2055 getDefaultPhone().getContext().sendBroadcastAsUser(
2056 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2057 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002058
2059 case CMD_SET_DATA_THROTTLING: {
2060 request = (MainThreadRequest) msg.obj;
2061 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2062 DataThrottlingRequest dataThrottlingRequest =
2063 (DataThrottlingRequest) request.argument;
2064 Phone phone = getPhoneFromRequest(request);
2065 if (phone != null) {
2066 phone.setDataThrottling(onCompleted,
2067 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2068 dataThrottlingRequest.getCompletionDurationMillis());
2069 } else {
2070 loge("setDataThrottling: No phone object");
2071 request.result =
2072 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2073 notifyRequester(request);
2074 }
2075
2076 break;
2077 }
2078 case EVENT_SET_DATA_THROTTLING_DONE:
2079 ar = (AsyncResult) msg.obj;
2080 request = (MainThreadRequest) ar.userObj;
2081
2082 if (ar.exception == null) {
2083 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2084 } else if (ar.exception instanceof CommandException) {
2085 loge("setDataThrottling: CommandException: " + ar.exception);
2086 CommandException.Error error =
2087 ((CommandException) (ar.exception)).getCommandError();
2088
2089 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2090 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002091 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002092 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2093 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002094 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2095 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002096 } else {
2097 request.result =
2098 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2099 }
2100 } else {
2101 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2102 }
2103 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2104 notifyRequester(request);
2105 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002106
2107 case CMD_SET_SIM_POWER: {
2108 request = (MainThreadRequest) msg.obj;
2109 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2110 request = (MainThreadRequest) msg.obj;
2111 int stateToSet =
2112 ((Pair<Integer, IIntegerConsumer>)
2113 request.argument).first;
2114 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2115 break;
2116 }
2117 case EVENT_SET_SIM_POWER_DONE: {
2118 ar = (AsyncResult) msg.obj;
2119 request = (MainThreadRequest) ar.userObj;
2120 IIntegerConsumer callback =
2121 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2122 if (ar.exception != null) {
2123 loge("setSimPower exception: " + ar.exception);
2124 int errorCode = TelephonyManager.CallForwardingInfoCallback
2125 .RESULT_ERROR_UNKNOWN;
2126 if (ar.exception instanceof CommandException) {
2127 CommandException.Error error =
2128 ((CommandException) (ar.exception)).getCommandError();
2129 if (error == CommandException.Error.SIM_ERR) {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2131 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2132 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2133 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2134 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2135 } else {
2136 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2137 }
2138 }
2139 try {
2140 callback.accept(errorCode);
2141 } catch (RemoteException e) {
2142 // Ignore if the remote process is no longer available to call back.
2143 Log.w(LOG_TAG, "setSimPower: callback not available.");
2144 }
2145 } else {
2146 try {
2147 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2148 } catch (RemoteException e) {
2149 // Ignore if the remote process is no longer available to call back.
2150 Log.w(LOG_TAG, "setSimPower: callback not available.");
2151 }
2152 }
2153 break;
2154 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002155 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2156 request = (MainThreadRequest) msg.obj;
2157
2158 final Phone phone = getPhoneFromRequest(request);
2159 if (phone == null || phone.getServiceStateTracker() == null) {
2160 request.result = new IllegalStateException("Phone or SST is null");
2161 notifyRequester(request);
2162 break;
2163 }
2164
2165 Pair<Integer, SignalStrengthUpdateRequest> pair =
2166 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2167 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2168 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002169 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002170 request.subId, pair.first /*callingUid*/,
2171 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002172 break;
2173 }
2174 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2175 ar = (AsyncResult) msg.obj;
2176 request = (MainThreadRequest) ar.userObj;
2177 // request.result will be the exception of ar if present, true otherwise.
2178 // Be cautious not to leave result null which will wait() forever
2179 request.result = ar.exception != null ? ar.exception : true;
2180 notifyRequester(request);
2181 break;
2182 }
2183 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2184 request = (MainThreadRequest) msg.obj;
2185
2186 Phone phone = getPhoneFromRequest(request);
2187 if (phone == null || phone.getServiceStateTracker() == null) {
2188 request.result = new IllegalStateException("Phone or SST is null");
2189 notifyRequester(request);
2190 break;
2191 }
2192
2193 Pair<Integer, SignalStrengthUpdateRequest> pair =
2194 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2195 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2196 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002197 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002198 request.subId, pair.first /*callingUid*/,
2199 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002200 break;
2201 }
2202 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2203 ar = (AsyncResult) msg.obj;
2204 request = (MainThreadRequest) ar.userObj;
2205 request.result = ar.exception != null ? ar.exception : true;
2206 notifyRequester(request);
2207 break;
2208 }
Jordan Liu109698e2020-11-24 14:50:34 -08002209
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002210 case CMD_GET_SLICING_CONFIG: {
2211 request = (MainThreadRequest) msg.obj;
2212 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2213 request.phone.getSlicingConfig(onCompleted);
2214 break;
2215 }
2216 case EVENT_GET_SLICING_CONFIG_DONE: {
2217 ar = (AsyncResult) msg.obj;
2218 request = (MainThreadRequest) ar.userObj;
2219 ResultReceiver result = (ResultReceiver) request.argument;
2220
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 Bundle bundle = new Bundle();
2223 int resultCode = 0;
2224 if (ar.exception != null) {
2225 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2226 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002228 } else if (ar.result == null) {
2229 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002230 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002231 } else {
2232 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002233 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2234 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002235 }
2236
2237 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002238 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002239 }
2240 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2241 result.send(resultCode, bundle);
2242 notifyRequester(request);
2243 break;
2244 }
2245
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 request = (MainThreadRequest) msg.obj;
2248 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 PurchasePremiumCapabilityArgument arg =
2250 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002251 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2252 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 ar = (AsyncResult) msg.obj;
2258 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 PurchasePremiumCapabilityArgument arg =
2260 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 try {
2262 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002263 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002264 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002265 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002266 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002267 + TelephonyManager.convertPurchaseResultToString(result));
2268 } catch (RemoteException e) {
2269 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002270 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002271 + " failed: " + e;
2272 if (DBG) log(logStr);
2273 AnomalyReporter.reportAnomaly(
2274 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2275 }
2276 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002277 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002278
Michele Berionne5e411512020-11-13 02:36:59 +00002279 case CMD_PREPARE_UNATTENDED_REBOOT:
2280 request = (MainThreadRequest) msg.obj;
2281 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002282 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002283 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002284 notifyRequester(request);
2285 break;
2286
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 default:
2288 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2289 break;
2290 }
2291 }
Jake Hambye994d462014-02-03 13:10:13 -08002292
Pengquan Menga1bb6272018-09-06 09:59:22 -07002293 private void notifyRequester(MainThreadRequest request) {
2294 synchronized (request) {
2295 request.notifyAll();
2296 }
2297 }
2298
Jake Hambye994d462014-02-03 13:10:13 -08002299 private void handleNullReturnEvent(Message msg, String command) {
2300 AsyncResult ar = (AsyncResult) msg.obj;
2301 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2302 if (ar.exception == null) {
2303 request.result = true;
2304 } else {
2305 request.result = false;
2306 if (ar.exception instanceof CommandException) {
2307 loge(command + ": CommandException: " + ar.exception);
2308 } else {
2309 loge(command + ": Unknown exception");
2310 }
2311 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002312 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
2316 /**
2317 * Posts the specified command to be executed on the main thread,
2318 * waits for the request to complete, and returns the result.
2319 * @see #sendRequestAsync
2320 */
2321 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002322 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2323 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002324 }
2325
2326 /**
2327 * Posts the specified command to be executed on the main thread,
2328 * waits for the request to complete, and returns the result.
2329 * @see #sendRequestAsync
2330 */
2331 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2332 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002333 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
2336 /**
2337 * Posts the specified command to be executed on the main thread,
2338 * waits for the request to complete, and returns the result.
2339 * @see #sendRequestAsync
2340 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002341 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002342 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2343 }
2344
2345 /**
2346 * Posts the specified command to be executed on the main thread,
2347 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2348 * if not timeout or null otherwise.
2349 * @see #sendRequestAsync
2350 */
2351 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2352 long timeoutInMs) {
2353 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002354 }
2355
2356 /**
2357 * Posts the specified command to be executed on the main thread,
2358 * waits for the request to complete, and returns the result.
2359 * @see #sendRequestAsync
2360 */
Nathan Harold92bed182018-10-12 18:16:49 -07002361 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002362 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002363 }
2364
2365 /**
2366 * Posts the specified command to be executed on the main thread,
2367 * waits for the request to complete, and returns the result.
2368 * @see #sendRequestAsync
2369 */
2370 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2372 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002373 }
2374
2375 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2377 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2378 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002379 * @see #sendRequestAsync
2380 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002381 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2382 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2384 throw new RuntimeException("This method will deadlock if called from the main thread.");
2385 }
2386
Nathan Harold92bed182018-10-12 18:16:49 -07002387 MainThreadRequest request = null;
2388 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2389 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2390 } else if (phone != null) {
2391 request = new MainThreadRequest(argument, phone, workSource);
2392 } else {
2393 request = new MainThreadRequest(argument, subId, workSource);
2394 }
2395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 Message msg = mMainThreadHandler.obtainMessage(command, request);
2397 msg.sendToTarget();
2398
Rambo Wang0f050d82021-02-12 11:43:36 -08002399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002401 if (timeoutInMs >= 0) {
2402 // Wait for at least timeoutInMs before returning null request result
2403 long now = SystemClock.elapsedRealtime();
2404 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002405 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002406 try {
2407 request.wait(deadline - now);
2408 } catch (InterruptedException e) {
2409 // Do nothing, go back and check if request is completed or timeout
2410 } finally {
2411 now = SystemClock.elapsedRealtime();
2412 }
2413 }
2414 } else {
2415 // Wait for the request to complete
2416 while (request.result == null) {
2417 try {
2418 request.wait();
2419 } catch (InterruptedException e) {
2420 // Do nothing, go back and wait until the request is complete
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423 }
2424 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002425 if (request.result == null) {
2426 Log.wtf(LOG_TAG,
2427 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 return request.result;
2430 }
2431
2432 /**
2433 * Asynchronous ("fire and forget") version of sendRequest():
2434 * Posts the specified command to be executed on the main thread, and
2435 * returns immediately.
2436 * @see #sendRequest
2437 */
2438 private void sendRequestAsync(int command) {
2439 mMainThreadHandler.sendEmptyMessage(command);
2440 }
2441
2442 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002443 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002444 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002445 */
2446 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002447 sendRequestAsync(command, argument, null, null);
2448 }
2449
2450 /**
2451 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2452 * @see {@link #sendRequest(int,Object)}
2453 */
2454 private void sendRequestAsync(
2455 int command, Object argument, Phone phone, WorkSource workSource) {
2456 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002457 Message msg = mMainThreadHandler.obtainMessage(command, request);
2458 msg.sendToTarget();
2459 }
2460
2461 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 * Initialize the singleton PhoneInterfaceManager instance.
2463 * This is only done once, at startup, from PhoneApp.onCreate().
2464 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002465 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 synchronized (PhoneInterfaceManager.class) {
2467 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002468 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 } else {
2470 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2471 }
2472 return sInstance;
2473 }
2474 }
2475
2476 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002477 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002479 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002480 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002482 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002483 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002484 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2486 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002487 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002488 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002489 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002490 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002491 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002492 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002493 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2494 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002495 mVendorApiLevel = SystemProperties.getInt(
2496 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2497
Tyler Gunn64144d92022-03-17 14:16:41 -07002498 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 publish();
arunvoddud7401012022-12-15 16:08:12 +00002500 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002501
2502 // Create the SatelliteEntitlementController singleton, for using the get the
2503 // entitlementStatus for satellite service.
2504 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
2506
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002507 @VisibleForTesting
2508 public SharedPreferences getSharedPreferences() {
2509 return mTelephonySharedPreferences;
2510 }
2511
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002512 /**
2513 * Get the default phone for this device.
2514 */
2515 @VisibleForTesting
2516 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002517 Phone thePhone = getPhone(getDefaultSubscription());
2518 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2519 }
2520
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 private void publish() {
2522 if (DBG) log("publish: " + this);
2523
Peter Wangc035ce42020-01-08 21:00:22 -08002524 TelephonyFrameworkInitializer
2525 .getTelephonyServiceManager()
2526 .getTelephonyServiceRegisterer()
2527 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 }
2529
Stuart Scott584921c2015-01-15 17:10:34 -08002530 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002531 if (request.phone != null) {
2532 return request.phone;
2533 } else {
2534 return getPhoneFromSubId(request.subId);
2535 }
2536 }
2537
2538 private Phone getPhoneFromSubId(int subId) {
2539 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2540 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002541 }
2542
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002543 /**
2544 * Get phone object associated with a subscription.
2545 * Return default phone if phone object associated with subscription is null
2546 * @param subId - subscriptionId
2547 * @return phone object associated with a subscription or default phone if null.
2548 */
Ling Mac28f0212023-03-24 16:07:15 -07002549 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002550 Phone phone = getPhoneFromSubId(subId);
2551 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002552 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002553 phone = getDefaultPhone();
2554 }
2555 return phone;
2556 }
2557
Rambo Wange53e07d2022-05-10 13:01:13 -07002558 @Nullable
2559 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002560 Phone phone = getPhoneFromRequest(request);
2561 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002562 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002563 }
2564
Ling Mac28f0212023-03-24 16:07:15 -07002565 /**
2566 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2567 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2568 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2569 * @return The Phone associated the sub Id
2570 */
2571 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002572 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574
Kai Shif70f46f2021-03-03 13:59:46 -08002575 private void sendEraseModemConfig(@NonNull Phone phone) {
2576 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2577 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2578 }
2579
2580 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2581 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2582 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002583 }
2584
Peter Wang44b186e2020-01-13 23:33:09 -08002585 private boolean isImsAvailableOnDevice() {
2586 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2587 if (pm == null) {
2588 // For some reason package manger is not available.. This will fail internally anyway,
2589 // so do not throw error and allow.
2590 return true;
2591 }
2592 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2593 }
2594
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002596 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2597 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2598
Wink Savilleadd7cc52014-09-08 14:23:09 -07002599 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002600 }
2601
Wink Savilleb564aae2014-10-23 10:18:09 -07002602 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 if (DBG) log("dial: " + number);
2604 // No permission check needed here: This is just a wrapper around the
2605 // ACTION_DIAL intent, which is available to any app since it puts up
2606 // the UI before it does anything.
2607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 String url = createTelUrl(number);
2611 if (url == null) {
2612 return;
2613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 // PENDING: should we just silently fail if phone is offhook or ringing?
2616 PhoneConstants.State state = mCM.getState(subId);
2617 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2618 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2619 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002620 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625 }
2626
2627 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002628 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002629 }
2630
Wink Savilleb564aae2014-10-23 10:18:09 -07002631 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 if (DBG) log("call: " + number);
2633
2634 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002635 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 // from the context of the phone app.
2637 enforceCallPermission();
2638
Jordan Liu1617b712019-07-10 15:06:26 -07002639 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 != AppOpsManager.MODE_ALLOWED) {
2641 return;
2642 }
2643
joonhunshin4ac60942023-11-15 15:23:39 +00002644 enforceTelephonyFeatureWithException(callingPackage,
2645 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 String url = createTelUrl(number);
2650 if (url == null) {
2651 return;
2652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 boolean isValid = false;
2655 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2656 if (slist != null) {
2657 for (SubscriptionInfo subInfoRecord : slist) {
2658 if (subInfoRecord.getSubscriptionId() == subId) {
2659 isValid = true;
2660 break;
2661 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002662 }
Wink Saville08874612014-08-31 19:19:58 -07002663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 if (!isValid) {
2665 return;
2666 }
Wink Saville08874612014-08-31 19:19:58 -07002667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2669 intent.putExtra(SUBSCRIPTION_KEY, subId);
2670 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002671 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002679 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2680 }
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002683 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002684 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2685 }
2686
Wink Savilleb564aae2014-10-23 10:18:09 -07002687 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689
joonhunshin4ac60942023-11-15 15:23:39 +00002690 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2691 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2692 "supplyPinReportResultForSubscriber");
2693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 final long identity = Binder.clearCallingIdentity();
2695 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002696 Phone phone = getPhone(subId);
2697 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 checkSimPin.start();
2699 return checkSimPin.unlockSim(null, pin);
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
2702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Wink Savilleb564aae2014-10-23 10:18:09 -07002705 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
joonhunshin4ac60942023-11-15 15:23:39 +00002708 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2709 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711 final long identity = Binder.clearCallingIdentity();
2712 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002713 Phone phone = getPhone(subId);
2714 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 checkSimPuk.start();
2716 return checkSimPuk.unlockSim(puk, pin);
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
2719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 }
2721
2722 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002723 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 * a synchronous one.
2725 */
2726 private static class UnlockSim extends Thread {
2727
2728 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002729 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730
2731 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002732 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2733 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734
2735 // For replies from SimCard interface
2736 private Handler mHandler;
2737
2738 // For async handler to identify request type
2739 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002740 private static final int SUPPLY_PIN_DELAYED = 101;
2741 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2742 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2743 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744
Michele Berionne5e411512020-11-13 02:36:59 +00002745 UnlockSim(int phoneId, IccCard simCard) {
2746 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 mSimCard = simCard;
2748 }
2749
2750 @Override
2751 public void run() {
2752 Looper.prepare();
2753 synchronized (UnlockSim.this) {
2754 mHandler = new Handler() {
2755 @Override
2756 public void handleMessage(Message msg) {
2757 AsyncResult ar = (AsyncResult) msg.obj;
2758 switch (msg.what) {
2759 case SUPPLY_PIN_COMPLETE:
2760 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2761 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002762 mRetryCount = msg.arg1;
2763 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002764 CommandException.Error error = null;
2765 if (ar.exception instanceof CommandException) {
2766 error = ((CommandException) (ar.exception))
2767 .getCommandError();
2768 }
2769 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002770 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002771 } else if (error == CommandException.Error.ABORTED) {
2772 /* When UiccCardApp dispose, handle message and return
2773 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002774 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002775 } else {
2776 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2777 }
2778 } else {
2779 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002782 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 UnlockSim.this.notifyAll();
2784 }
2785 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002786 case SUPPLY_PIN_DELAYED:
2787 if(!mDone) {
2788 String logStr = "Delay in receiving SIM PIN response ";
2789 if (DBG) log(logStr);
2790 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2791 }
2792 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794 }
2795 };
2796 UnlockSim.this.notifyAll();
2797 }
2798 Looper.loop();
2799 }
2800
2801 /*
2802 * Use PIN or PUK to unlock SIM card
2803 *
2804 * If PUK is null, unlock SIM card with PIN
2805 *
2806 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302807 *
2808 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2809 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 */
Wink Saville9de0f752013-10-22 19:04:03 -07002811 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812
2813 while (mHandler == null) {
2814 try {
2815 wait();
2816 } catch (InterruptedException e) {
2817 Thread.currentThread().interrupt();
2818 }
2819 }
2820 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2821
2822 if (puk == null) {
2823 mSimCard.supplyPin(pin, callback);
2824 } else {
2825 mSimCard.supplyPuk(puk, pin, callback);
2826 }
2827
2828 while (!mDone) {
2829 try {
2830 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002831 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2832 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 wait();
2834 } catch (InterruptedException e) {
2835 // Restore the interrupted status
2836 Thread.currentThread().interrupt();
2837 }
2838 }
2839 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002840 int[] resultArray = new int[2];
2841 resultArray[0] = mResult;
2842 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002843
2844 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002845 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002846 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302847 // This instance is no longer reused, so quit its thread's looper.
2848 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002849
Wink Saville9de0f752013-10-22 19:04:03 -07002850 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852 }
2853
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002854 /**
2855 * This method has been removed due to privacy and stability concerns.
2856 */
2857 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002859 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2860 return;
Wink Saville36469e72014-06-11 15:17:00 -07002861 }
2862
Nathan Harold1f889d82020-06-04 17:05:26 -07002863 @Override
2864 public void updateServiceLocationWithPackageName(String callingPackage) {
2865 mApp.getSystemService(AppOpsManager.class)
2866 .checkPackage(Binder.getCallingUid(), callingPackage);
2867
Nathan Haroldf096d982020-11-18 17:18:06 -08002868 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002869 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2870 // Callers targeting S have no business invoking this method.
2871 return;
2872 }
2873
2874 LocationAccessPolicy.LocationPermissionResult locationResult =
2875 LocationAccessPolicy.checkLocationPermission(mApp,
2876 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2877 .setCallingPackage(callingPackage)
2878 .setCallingFeatureId(null)
2879 .setCallingPid(Binder.getCallingPid())
2880 .setCallingUid(Binder.getCallingUid())
2881 .setMethod("updateServiceLocation")
2882 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2883 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2884 .build());
2885 // Apps that lack location permission have no business calling this method;
2886 // however, because no permission was declared in the public API, denials must
2887 // all be "soft".
2888 switch (locationResult) {
2889 case DENIED_HARD: /* fall through */
2890 case DENIED_SOFT:
2891 return;
2892 }
2893
2894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 final long identity = Binder.clearCallingIdentity();
2896 try {
Ling Mac28f0212023-03-24 16:07:15 -07002897 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002904 @Override
2905 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 return isRadioOnWithFeature(callingPackage, null);
2907 }
2908
2909
2910 @Override
2911 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2912 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2913 callingFeatureId);
2914 }
2915
2916 @Deprecated
2917 @Override
2918 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2919 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002920 }
2921
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002923 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2924 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002926 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002927 return false;
2928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
joonhunshin4ac60942023-11-15 15:23:39 +00002930 enforceTelephonyFeatureWithException(callingPackage,
2931 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 return isRadioOnForSubscriber(subId);
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002939 }
2940
2941 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 final Phone phone = getPhone(subId);
2945 if (phone != null) {
2946 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2947 } else {
2948 return false;
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
2955 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002956 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
Wink Saville36469e72014-06-11 15:17:00 -07002958
Wink Savilleb564aae2014-10-23 10:18:09 -07002959 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961
joonhunshin4ac60942023-11-15 15:23:39 +00002962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2963 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 final Phone phone = getPhone(subId);
2968 if (phone != null) {
2969 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2970 }
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002973 }
Wink Saville36469e72014-06-11 15:17:00 -07002974 }
2975
2976 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002977 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002978 }
2979
Wink Savilleb564aae2014-10-23 10:18:09 -07002980 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 final Phone phone = getPhone(subId);
2986 if (phone == null) {
2987 return false;
2988 }
2989 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2990 toggleRadioOnOffForSubscriber(subId);
2991 }
2992 return true;
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 }
Wink Saville36469e72014-06-11 15:17:00 -07002997
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002998 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002999 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00003000
Tomasz Wasilczykef763582024-09-17 13:50:32 -07003001 if (!mApp.getResources().getBoolean(
3002 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3004 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3005 }
joonhunshin4ac60942023-11-15 15:23:39 +00003006
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003007 /*
3008 * If any of the Radios are available, it will need to be
3009 * shutdown. So return true if any Radio is available.
3010 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3014 Phone phone = PhoneFactory.getPhone(i);
3015 if (phone != null && phone.isRadioAvailable()) return true;
3016 }
3017 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3018 return false;
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003021 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003022 }
3023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003025 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 enforceModifyPermission();
3027
joonhunshin4ac60942023-11-15 15:23:39 +00003028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3029 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3034 logv("Shutting down Phone " + i);
3035 shutdownRadioUsingPhoneId(i);
3036 }
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003039 }
3040 }
3041
3042 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003043 Phone phone = PhoneFactory.getPhone(phoneId);
3044 if (phone != null && phone.isRadioAvailable()) {
3045 phone.shutdownRadio();
3046 }
3047 }
3048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003050 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
Ling Ma83dc5ea2023-01-12 15:06:04 -08003052 if (!turnOn) {
3053 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3054 }
3055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3059 if (defaultPhone != null) {
3060 defaultPhone.setRadioPower(turnOn);
3061 return true;
3062 } else {
3063 loge("There's no default phone.");
3064 return false;
3065 }
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003068 }
Wink Saville36469e72014-06-11 15:17:00 -07003069 }
3070
Wink Savilleb564aae2014-10-23 10:18:09 -07003071 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
Ling Ma83dc5ea2023-01-12 15:06:04 -08003074 if (!turnOn) {
3075 log("setRadioPowerForSubscriber off: subId=" + subId
3076 + ",callingPackage=" + getCurrentPackageName());
3077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 final Phone phone = getPhone(subId);
3081 if (phone != null) {
3082 phone.setRadioPower(turnOn);
3083 return true;
3084 } else {
3085 return false;
3086 }
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 }
3091
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 /**
3093 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3094 * no reason to power it off. When any of the voters want to power it off, it will be turned
3095 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3096 * powering it off, and these radio off votes will be cleared.
3097 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3098 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3099 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3100 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3101 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3102 * check its vote.
3103 *
3104 * @param subId The subscription ID.
3105 * @param reason The reason for powering off radio.
3106 * @return true on success and false on failure.
3107 */
3108 public boolean requestRadioPowerOffForReason(int subId,
3109 @TelephonyManager.RadioPowerReason int reason) {
3110 enforceModifyPermission();
3111
joonhunshin4ac60942023-11-15 15:23:39 +00003112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3113 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3114
Ling Ma83dc5ea2023-01-12 15:06:04 -08003115 log("requestRadioPowerOffForReason: subId=" + subId
3116 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003117 final long identity = Binder.clearCallingIdentity();
3118 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003119 boolean result = false;
3120 for (Phone phone : PhoneFactory.getPhones()) {
3121 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003122 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003124 if (!result) {
3125 loge("requestRadioPowerOffForReason: no phone exists");
3126 }
3127 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
3133 /**
3134 * Remove the vote on powering off the radio for a reason, as requested by
3135 * {@link requestRadioPowerOffForReason}.
3136 *
3137 * @param subId The subscription ID.
3138 * @param reason The reason for powering off radio.
3139 * @return true on success and false on failure.
3140 */
3141 public boolean clearRadioPowerOffForReason(int subId,
3142 @TelephonyManager.RadioPowerReason int reason) {
3143 enforceModifyPermission();
3144
joonhunshin4ac60942023-11-15 15:23:39 +00003145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3146 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3147
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003148 final long identity = Binder.clearCallingIdentity();
3149 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003150 boolean result = false;
3151 for (Phone phone : PhoneFactory.getPhones()) {
3152 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003154 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003155 if (!result) {
3156 loge("clearRadioPowerOffForReason: no phone exists");
3157 }
3158 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
3162 }
3163
3164 /**
3165 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3166 *
3167 * @param subId The subscription ID.
3168 * @param callingPackage The package making the call.
3169 * @param callingFeatureId The feature in the package.
3170 * @return List of reasons for powering off radio.
3171 */
3172 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3173 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3174
joonhunshin4ac60942023-11-15 15:23:39 +00003175 enforceTelephonyFeatureWithException(callingPackage,
3176 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3177
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003178 final long identity = Binder.clearCallingIdentity();
3179 List result = new ArrayList();
3180 try {
3181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3182 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3183 return result;
3184 }
3185
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003186 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003187 if (phone != null) {
3188 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003189 } else {
3190 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003191 }
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
3195 return result;
3196 }
3197
Wink Saville36469e72014-06-11 15:17:00 -07003198 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003199 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003200 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202
joonhunshin4ac60942023-11-15 15:23:39 +00003203 enforceTelephonyFeatureWithException(callingPackage,
3204 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
Jack Yu285100e2022-12-02 22:48:35 -08003208 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003210 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003211 phone.getDataSettingsManager().setDataEnabled(
3212 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 return true;
3214 } else {
3215 return false;
3216 }
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 }
3221
Wink Saville36469e72014-06-11 15:17:00 -07003222 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003224 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226
joonhunshin4ac60942023-11-15 15:23:39 +00003227 enforceTelephonyFeatureWithException(callingPackage,
3228 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 final long identity = Binder.clearCallingIdentity();
3231 try {
Jack Yu285100e2022-12-02 22:48:35 -08003232 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003234 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003235 phone.getDataSettingsManager().setDataEnabled(
3236 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237 return true;
3238 } else {
3239 return false;
3240 }
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003244 }
3245
Sanket Padawe356d7632015-06-22 14:03:32 -07003246 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003247 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003248 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3249 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 final Phone phone = getPhone(subId);
3254 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003255 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 } else {
3257 return false;
3258 }
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 }
3263
3264 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003265 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003266 }
3267
pkanwarae03a6b2016-11-06 20:37:09 -08003268 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 enforceCallPermission();
3270
joonhunshin4ac60942023-11-15 15:23:39 +00003271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3272 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3277 return;
3278 }
3279 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3280 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
pkanwar32d516d2016-10-14 19:37:38 -07003284 };
3285
Wink Savilleb564aae2014-10-23 10:18:09 -07003286 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
joonhunshin4ac60942023-11-15 15:23:39 +00003289 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3290 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3295 return false;
3296 }
3297 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 }
3302
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003303 /**
3304 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3305 * tag on getCallState Binder call.
3306 */
3307 @Deprecated
3308 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003309 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003310 if (CompatChanges.isChangeEnabled(
3311 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3312 Binder.getCallingUid())) {
3313 // Do not allow this API to be called on API version 31+, it should only be
3314 // called on old apps using this Binder call directly.
3315 throw new SecurityException("This method can only be used for applications "
3316 + "targeting API version 30 or less.");
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318 final long identity = Binder.clearCallingIdentity();
3319 try {
Ling Mac28f0212023-03-24 16:07:15 -07003320 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3321 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
3325 }
3326
3327 @Override
3328 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3329 if (CompatChanges.isChangeEnabled(
3330 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3331 Binder.getCallingUid())) {
3332 // Check READ_PHONE_STATE for API version 31+
3333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3334 featureId, "getCallStateForSubscription")) {
3335 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3336 + "targeting API level 31+.");
3337 }
3338 }
joonhunshin4ac60942023-11-15 15:23:39 +00003339
3340 enforceTelephonyFeatureWithException(callingPackage,
3341 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3342
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3347 PhoneConstantConversions.convertCallState(phone.getState());
3348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 }
3352
Sanket Padawe356d7632015-06-22 14:03:32 -07003353 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003354 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003355 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003356 }
3357
3358 @Override
3359 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3361 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 final long identity = Binder.clearCallingIdentity();
3364 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003365 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003366 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003367 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003368 } else {
3369 return PhoneConstantConversions.convertDataState(
3370 PhoneConstants.DataState.DISCONNECTED);
3371 }
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375 }
3376
Sanket Padawe356d7632015-06-22 14:03:32 -07003377 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003378 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003379 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003380 }
3381
3382 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003383 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003384 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3385 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 final long identity = Binder.clearCallingIdentity();
3388 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003389 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003391 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 } else {
3393 return TelephonyManager.DATA_ACTIVITY_NONE;
3394 }
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003398 }
3399
3400 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003401 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003402 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003403 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003404
3405 LocationAccessPolicy.LocationPermissionResult locationResult =
3406 LocationAccessPolicy.checkLocationPermission(mApp,
3407 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3408 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003409 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003410 .setCallingPid(Binder.getCallingPid())
3411 .setCallingUid(Binder.getCallingUid())
3412 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003413 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003414 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3415 .build());
3416 switch (locationResult) {
3417 case DENIED_HARD:
3418 throw new SecurityException("Not allowed to access cell location");
3419 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003420 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3421 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 }
3423
joonhunshin4ac60942023-11-15 15:23:39 +00003424 enforceTelephonyFeatureWithException(callingPackage,
3425 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3426
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003427 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003431 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003432 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
Svetoslav64fad262015-04-14 14:35:21 -07003436 }
3437
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003439 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003440 if (!mApp.getResources().getBoolean(
3441 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3443 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3444 }
joonhunshin4ac60942023-11-15 15:23:39 +00003445
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003446 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3447 // registered cell info, so return a NULL country instead.
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003450 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3451 // Get default phone in this case.
3452 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3453 }
Jack Yu285100e2022-12-02 22:48:35 -08003454 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003456 if (phone == null) return "";
3457 ServiceStateTracker sst = phone.getServiceStateTracker();
3458 if (sst == null) return "";
3459 LocaleTracker lt = sst.getLocaleTracker();
3460 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003461 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003465 }
3466
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003467 /**
3468 * This method was removed due to potential issues caused by performing partial
3469 * updates of service state, and lack of a credible use case.
3470 *
3471 * This has the ability to break the telephony implementation by disabling notification of
3472 * changes in device connectivity. DO NOT USE THIS!
3473 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003474 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 public void enableLocationUpdates() {
3476 mApp.enforceCallingOrSelfPermission(
3477 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 }
3479
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003480 /**
3481 * This method was removed due to potential issues caused by performing partial
3482 * updates of service state, and lack of a credible use case.
3483 *
3484 * This has the ability to break the telephony implementation by disabling notification of
3485 * changes in device connectivity. DO NOT USE THIS!
3486 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 @Override
3488 public void disableLocationUpdates() {
3489 mApp.enforceCallingOrSelfPermission(
3490 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 }
3492
3493 @Override
3494 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003495 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3496 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003497 try {
3498 mApp.getSystemService(AppOpsManager.class)
3499 .checkPackage(Binder.getCallingUid(), callingPackage);
3500 } catch (SecurityException e) {
3501 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3502 throw e;
3503 }
3504
Nathan Haroldf096d982020-11-18 17:18:06 -08003505 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003506 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3507 throw new SecurityException(
3508 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3509 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003510
Jordan Liu1617b712019-07-10 15:06:26 -07003511 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3513 return null;
3514 }
Svetoslav64fad262015-04-14 14:35:21 -07003515
joonhunshin4ac60942023-11-15 15:23:39 +00003516 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3517 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3518
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003519 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003521 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003522 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523
Nathan Haroldf180aac2018-06-01 18:43:55 -07003524 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3525 for (CellInfo ci : info) {
3526 if (ci instanceof CellInfoGsm) {
3527 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3528 } else if (ci instanceof CellInfoWcdma) {
3529 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003532 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003535 private List<CellInfo> getCachedCellInfo() {
3536 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3537 for (Phone phone : PhoneFactory.getPhones()) {
3538 List<CellInfo> info = phone.getAllCellInfo();
3539 if (info != null) cellInfos.addAll(info);
3540 }
3541 return cellInfos;
3542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543
3544 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003545 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003546 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003547 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003548
3549 LocationAccessPolicy.LocationPermissionResult locationResult =
3550 LocationAccessPolicy.checkLocationPermission(mApp,
3551 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3552 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003553 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003554 .setCallingPid(Binder.getCallingPid())
3555 .setCallingUid(Binder.getCallingUid())
3556 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003557 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003558 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3559 .build());
3560 switch (locationResult) {
3561 case DENIED_HARD:
3562 throw new SecurityException("Not allowed to access cell info");
3563 case DENIED_SOFT:
3564 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003565 }
3566
Nathan Haroldf096d982020-11-18 17:18:06 -08003567 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003568 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3569 return getCachedCellInfo();
3570 }
3571
joonhunshin4ac60942023-11-15 15:23:39 +00003572 enforceTelephonyFeatureWithException(callingPackage,
3573 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3574
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003575 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3580 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003581 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003582 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 if (info != null) cellInfos.addAll(info);
3584 }
3585 return cellInfos;
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003588 }
3589 }
3590
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003591 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003592 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3593 String callingFeatureId) {
3594 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3595 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003596 }
3597
3598 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003599 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3600 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003601 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003602 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003603 }
3604
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003605 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3606 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003608 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003609
3610 LocationAccessPolicy.LocationPermissionResult locationResult =
3611 LocationAccessPolicy.checkLocationPermission(mApp,
3612 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3613 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003614 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003615 .setCallingPid(Binder.getCallingPid())
3616 .setCallingUid(Binder.getCallingUid())
3617 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003618 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3619 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003620 .build());
3621 switch (locationResult) {
3622 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003623 if (TelephonyPermissions
3624 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003625 // Safetynet logging for b/154934934
3626 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3627 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003628 throw new SecurityException("Not allowed to access cell info");
3629 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003630 if (TelephonyPermissions
3631 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003632 // Safetynet logging for b/154934934
3633 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3634 }
Nathan Harold5320c422019-05-09 10:26:08 -07003635 try {
3636 cb.onCellInfo(new ArrayList<CellInfo>());
3637 } catch (RemoteException re) {
3638 // Drop without consequences
3639 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003640 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003641 }
3642
joonhunshin4ac60942023-11-15 15:23:39 +00003643 enforceTelephonyFeatureWithException(callingPackage,
3644 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003645
3646 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003647 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3648
3649 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3650 }
3651
3652 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003653 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003654 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656
3657 final long identity = Binder.clearCallingIdentity();
3658 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003659 Phone phone = getPhone(subId);
3660 if (phone == null) {
3661 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3662 } else {
3663 phone.setCellInfoListRate(rateInMillis, workSource);
3664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 }
3669
Shishir Agrawala9f32182016-04-12 12:00:16 -07003670 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003671 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003672 Phone phone = PhoneFactory.getPhone(slotIndex);
3673 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003674 return null;
3675 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003676 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003677 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003678 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003679 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003680 return null;
3681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 return phone.getImei();
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003689 }
3690
3691 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003692 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3693 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3694 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3695 callingFeatureId, "getPrimaryImei")) {
3696 throw new SecurityException("Caller does not have permission");
3697 }
joonhunshin4ac60942023-11-15 15:23:39 +00003698
arunvoddud5c6ce02022-12-11 06:03:12 +00003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 for (Phone phone : PhoneFactory.getPhones()) {
3702 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3703 return phone.getImei();
3704 }
3705 }
3706 throw new UnsupportedOperationException("Operation not supported");
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
3710 }
3711
3712 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003713 public String getTypeAllocationCodeForSlot(int slotIndex) {
3714 Phone phone = PhoneFactory.getPhone(slotIndex);
3715 String tac = null;
3716 if (phone != null) {
3717 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003718 try {
3719 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3720 } catch (IndexOutOfBoundsException e) {
3721 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3722 return null;
3723 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003724 }
3725 return tac;
3726 }
3727
3728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003729 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003730 try {
3731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3732 } catch (SecurityException se) {
3733 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3734 throw new SecurityException("Package " + callingPackage + " does not belong to "
3735 + Binder.getCallingUid());
3736 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003737 Phone phone = PhoneFactory.getPhone(slotIndex);
3738 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003739 return null;
3740 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003743 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003744 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003745 return null;
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
joonhunshin4ac60942023-11-15 15:23:39 +00003748 enforceTelephonyFeatureWithException(callingPackage,
3749 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 return phone.getMeid();
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Jack Yu2af8d712017-03-15 17:14:14 -07003757 }
3758
3759 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003760 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3762 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3763
David Kelly5e06a7f2018-03-12 14:10:59 +00003764 Phone phone = PhoneFactory.getPhone(slotIndex);
3765 String manufacturerCode = null;
3766 if (phone != null) {
3767 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003768 try {
3769 manufacturerCode =
3770 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3771 } catch (IndexOutOfBoundsException e) {
3772 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3773 return null;
3774 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003775 }
3776 return manufacturerCode;
3777 }
3778
3779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003780 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3781 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003782 Phone phone = PhoneFactory.getPhone(slotIndex);
3783 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 return null;
3785 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003786 int subId = phone.getSubId();
3787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003788 mApp, subId, callingPackage, callingFeatureId,
3789 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003790 return null;
3791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
joonhunshin4ac60942023-11-15 15:23:39 +00003793 enforceTelephonyFeatureWithException(callingPackage,
3794 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 return phone.getDeviceSvn();
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003802 }
3803
fionaxu43304da2017-11-27 22:51:16 -08003804 @Override
3805 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003806 if (!mApp.getResources().getBoolean(
3807 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3809 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3810 }
joonhunshin4ac60942023-11-15 15:23:39 +00003811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
fionaxu43304da2017-11-27 22:51:16 -08003819 }
3820
3821 @Override
3822 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003823 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3824 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
3829 return phone == null ? null : phone.getCarrierName();
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
fionaxu43304da2017-11-27 22:51:16 -08003833 }
3834
calvinpanffe225e2018-11-01 19:43:06 +08003835 @Override
chen xu0026ca62019-03-06 15:28:50 -08003836 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3838 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3839
chen xu25637222018-11-04 17:17:00 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 final Phone phone = getPhone(subId);
3843 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003844 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
3850 @Override
chen xu0026ca62019-03-06 15:28:50 -08003851 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3853 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3854 "getSubscriptionSpecificCarrierName");
3855
chen xu25637222018-11-04 17:17:00 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003859 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
3863 }
3864
chen xu651eec72018-11-11 19:03:44 -08003865 @Override
chen xu864e11c2018-12-06 22:10:03 -08003866 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3867 if (!isSubscriptionMccMnc) {
3868 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3869 }
chen xu651eec72018-11-11 19:03:44 -08003870 final Phone phone = PhoneFactory.getPhone(slotIndex);
3871 if (phone == null) {
3872 return TelephonyManager.UNKNOWN_CARRIER_ID;
3873 }
joonhunshin4ac60942023-11-15 15:23:39 +00003874
3875 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3876 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3877
chen xu651eec72018-11-11 19:03:44 -08003878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
3884 }
3885
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003886 //
3887 // Internal helper methods.
3888 //
3889
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003890 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003891 * Make sure the caller is the calling package itself
3892 *
3893 * @throws SecurityException if the caller is not the calling package
3894 */
3895 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3896 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003897 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3898 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003899 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003900 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003901 } catch (PackageManager.NameNotFoundException e) {
3902 // packageUid is -1
3903 }
3904 if (packageUid != callingUid) {
3905 throw new SecurityException(message + ": Package " + callingPackage
3906 + " does not belong to " + callingUid);
3907 }
3908 }
3909
3910 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3912 *
3913 * @throws SecurityException if the caller does not have the required permission
3914 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003915 @VisibleForTesting
3916 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3918 }
3919
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003920 /**
arunvoddud7401012022-12-15 16:08:12 +00003921 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003922 *
3923 * @throws SecurityException if the caller does not have the required permission
3924 */
3925 @VisibleForTesting
3926 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003927 enforceReadPermission(null);
3928 }
3929
3930 /**
3931 * Make sure the caller has the READ_PHONE_STATE permissions.
3932 *
3933 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3934 */
3935 @VisibleForTesting
3936 public void enforceReadPermission(String msg) {
3937 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003938 }
3939
Shuo Qian3b6ee772019-11-13 17:43:31 -08003940 private void enforceActiveEmergencySessionPermission() {
3941 mApp.enforceCallingOrSelfPermission(
3942 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3943 }
3944
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 /**
3946 * Make sure the caller has the CALL_PHONE permission.
3947 *
3948 * @throws SecurityException if the caller does not have the required permission
3949 */
3950 private void enforceCallPermission() {
3951 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3952 }
3953
paulhu5a773602019-08-23 19:17:33 +08003954 private void enforceSettingsPermission() {
3955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003956 }
3957
Michele Berionne5e411512020-11-13 02:36:59 +00003958 private void enforceRebootPermission() {
3959 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3960 }
3961
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003962 /**
3963 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3964 * @param message - log message to print.
3965 * @throws SecurityException if the caller does not have the required permission
3966 */
3967 private void enforceSatelliteCommunicationPermission(String message) {
3968 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3969 }
3970
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003971 /**
3972 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3973 * @param message - log message to print.
3974 * @throws SecurityException if the caller does not have the required permission
3975 */
3976 private void enforcePackageUsageStatsPermission(String message) {
3977 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3978 }
3979
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003980 private String createTelUrl(String number) {
3981 if (TextUtils.isEmpty(number)) {
3982 return null;
3983 }
3984
Jake Hambye994d462014-02-03 13:10:13 -08003985 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003986 }
3987
Ihab Awadf9e92732013-12-05 18:02:52 -08003988 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003989 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003990 }
3991
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003992 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003993 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003994 }
3995
Ihab Awadf9e92732013-12-05 18:02:52 -08003996 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003997 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003998 }
3999
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004000 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004001 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004002 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004003 }
4004
Sanket Padawe356d7632015-06-22 14:03:32 -07004005 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004006 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004007 if (!mApp.getResources().getBoolean(
4008 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4010 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4011 }
joonhunshin4ac60942023-11-15 15:23:39 +00004012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 final Phone phone = PhoneFactory.getPhone(slotIndex);
4016 if (phone == null) {
4017 return PhoneConstants.PHONE_TYPE_NONE;
4018 } else {
4019 return phone.getPhoneType();
4020 }
4021 } finally {
4022 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004024 }
4025
4026 /**
4027 * Returns the CDMA ERI icon index to display
4028 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4031 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4032 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004033 }
4034
Sanket Padawe356d7632015-06-22 14:03:32 -07004035 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004036 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4037 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004039 mApp, subId, callingPackage, callingFeatureId,
4040 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004041 return -1;
4042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043
joonhunshin4ac60942023-11-15 15:23:39 +00004044 enforceTelephonyFeatureWithException(callingPackage,
4045 PackageManager.FEATURE_TELEPHONY_CDMA,
4046 "getCdmaEriIconIndexForSubscriber");
4047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 final Phone phone = getPhone(subId);
4051 if (phone != null) {
4052 return phone.getCdmaEriIconIndex();
4053 } else {
4054 return -1;
4055 }
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004059 }
4060
4061 /**
4062 * Returns the CDMA ERI icon mode,
4063 * 0 - ON
4064 * 1 - FLASHING
4065 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004067 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4068 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4069 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004070 }
4071
Sanket Padawe356d7632015-06-22 14:03:32 -07004072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004073 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4074 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004076 mApp, subId, callingPackage, callingFeatureId,
4077 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004078 return -1;
4079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080
4081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 final Phone phone = getPhone(subId);
4084 if (phone != null) {
4085 return phone.getCdmaEriIconMode();
4086 } else {
4087 return -1;
4088 }
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004092 }
4093
4094 /**
4095 * Returns the CDMA ERI text,
4096 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004098 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4099 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4100 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004101 }
4102
Sanket Padawe356d7632015-06-22 14:03:32 -07004103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004104 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004107 mApp, subId, callingPackage, callingFeatureId,
4108 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004109 return null;
4110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 final Phone phone = getPhone(subId);
4115 if (phone != null) {
4116 return phone.getCdmaEriText();
4117 } else {
4118 return null;
4119 }
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004123 }
4124
4125 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004126 * Returns the CDMA MDN.
4127 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004128 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004129 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4131 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132
joonhunshin4ac60942023-11-15 15:23:39 +00004133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4134 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004139 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 return phone.getLine1Number();
4141 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004142 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 return null;
4144 }
4145 } finally {
4146 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004147 }
4148 }
4149
4150 /**
4151 * Returns the CDMA MIN.
4152 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004153 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004154 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4156 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157
joonhunshin4ac60942023-11-15 15:23:39 +00004158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4159 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 final Phone phone = getPhone(subId);
4164 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4165 return phone.getCdmaMin();
4166 } else {
4167 return null;
4168 }
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004171 }
4172 }
4173
Hall Liud892bec2018-11-30 14:51:45 -08004174 @Override
4175 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4176 INumberVerificationCallback callback, String callingPackage) {
4177 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4178 != PERMISSION_GRANTED) {
4179 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4180 }
4181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4182
4183 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4184 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004185 throw new SecurityException("Calling package must be configured in the device config: "
4186 + "calling package: " + callingPackage
4187 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004188 }
4189
joonhunshin4ac60942023-11-15 15:23:39 +00004190 enforceTelephonyFeatureWithException(callingPackage,
4191 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4192
Hall Liud892bec2018-11-30 14:51:45 -08004193 if (range == null) {
4194 throw new NullPointerException("Range must be non-null");
4195 }
4196
4197 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004198 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004199
4200 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4201 }
4202
Junda Liuca05d5d2014-08-14 22:36:34 -07004203 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004204 * Returns true if CDMA provisioning needs to run.
4205 */
4206 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4208 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 final long identity = Binder.clearCallingIdentity();
4211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004212 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004216 }
4217
4218 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004219 * Sets the voice mail number of a given subId.
4220 */
4221 @Override
4222 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004223 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4224 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225
joonhunshin4ac60942023-11-15 15:23:39 +00004226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4227 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229 final long identity = Binder.clearCallingIdentity();
4230 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004231 Boolean success = (Boolean) sendRequest(
4232 CMD_SET_VOICEMAIL_NUMBER,
4233 new Pair<String, String>(alphaTag, number),
4234 new Integer(subId),
4235 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4236 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 return success;
4238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004241 }
4242
Ta-wei Yen87c49842016-05-13 21:19:52 -07004243 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004244 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004246 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4247 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004248 if (!TextUtils.equals(callingPackage, systemDialer)) {
4249 throw new SecurityException("caller must be system dialer");
4250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251
joonhunshin4ac60942023-11-15 15:23:39 +00004252 enforceTelephonyFeatureWithException(callingPackage,
4253 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4258 if (phoneAccountHandle == null) {
4259 return null;
4260 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004261 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004264 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004265 }
4266
4267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004268 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4269 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004270 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004274 return null;
4275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
joonhunshin4ac60942023-11-15 15:23:39 +00004277 enforceTelephonyFeatureWithException(callingPackage,
4278 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4279
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004280 final long identity = Binder.clearCallingIdentity();
4281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004282 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004286 }
4287
4288 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004289 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4290 VisualVoicemailSmsFilterSettings settings) {
4291 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004292 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004293 enforceTelephonyFeatureWithException(callingPackage,
4294 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004298 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004302 }
4303
4304 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004305 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004307 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004308 enforceTelephonyFeatureWithException(callingPackage,
4309 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 final long identity = Binder.clearCallingIdentity();
4312 try {
4313 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004314 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004318 }
4319
4320 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004321 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4322 String callingPackage, int subId) {
4323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324
4325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004328 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004332 }
4333
4334 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004335 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337
4338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004341 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004345 }
4346
4347 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004348 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4349 String callingAttributionTag, int subId, String number, int port, String text,
4350 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004351 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004352 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004353 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004354
4355 enforceTelephonyFeatureWithException(callingPackage,
4356 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4357
Amit Mahajandccb3f12019-05-13 13:48:32 -07004358 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004359 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4360 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4361 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004362 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004363
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004364 /**
fionaxu0152e512016-11-14 13:36:14 -08004365 * Sets the voice activation state of a given subId.
4366 */
4367 @Override
4368 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4370 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
joonhunshin4ac60942023-11-15 15:23:39 +00004372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4373 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 final Phone phone = getPhone(subId);
4378 if (phone != null) {
4379 phone.setVoiceActivationState(activationState);
4380 } else {
4381 loge("setVoiceActivationState fails with invalid subId: " + subId);
4382 }
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004385 }
4386 }
4387
4388 /**
4389 * Sets the data activation state of a given subId.
4390 */
4391 @Override
4392 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4394 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395
joonhunshin4ac60942023-11-15 15:23:39 +00004396 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4397 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 final Phone phone = getPhone(subId);
4402 if (phone != null) {
4403 phone.setDataActivationState(activationState);
4404 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004405 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 }
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004409 }
4410 }
4411
4412 /**
4413 * Returns the voice activation state of a given subId.
4414 */
4415 @Override
4416 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418
joonhunshin4ac60942023-11-15 15:23:39 +00004419 enforceTelephonyFeatureWithException(callingPackage,
4420 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4421
fionaxu0152e512016-11-14 13:36:14 -08004422 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 if (phone != null) {
4426 return phone.getVoiceActivationState();
4427 } else {
4428 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4429 }
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004432 }
4433 }
4434
4435 /**
4436 * Returns the data activation state of a given subId.
4437 */
4438 @Override
4439 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441
joonhunshin4ac60942023-11-15 15:23:39 +00004442 enforceTelephonyFeatureWithException(callingPackage,
4443 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4444
fionaxu0152e512016-11-14 13:36:14 -08004445 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 if (phone != null) {
4449 return phone.getDataActivationState();
4450 } else {
4451 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4452 }
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004455 }
4456 }
4457
4458 /**
Wink Saville36469e72014-06-11 15:17:00 -07004459 * Returns the unread count of voicemails for a subId
4460 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004462 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4463 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004465 mApp, subId, callingPackage, callingFeatureId,
4466 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004467 return 0;
4468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 final Phone phone = getPhone(subId);
4472 if (phone != null) {
4473 return phone.getVoiceMessageCount();
4474 } else {
4475 return 0;
4476 }
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004480 }
4481
4482 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004483 * returns true, if the device is in a state where both voice and data
4484 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004485 */
4486 @Override
4487 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004488 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4489 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Ling Mac28f0212023-03-24 16:07:15 -07004493 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004497 }
4498
4499 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004500 * Send the dialer code if called from the current default dialer or the caller has
4501 * carrier privilege.
4502 * @param inputCode The dialer code to send
4503 */
4504 @Override
4505 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004506 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004507 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004508 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4509 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004510 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004511 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004512 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514
joonhunshin4ac60942023-11-15 15:23:39 +00004515 enforceTelephonyFeatureWithException(callingPackage,
4516 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 final long identity = Binder.clearCallingIdentity();
4519 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004520 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
fionaxu235cc5e2017-03-06 22:25:57 -08004524 }
4525
Pengquan Menga1bb6272018-09-06 09:59:22 -07004526 @Override
4527 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004528 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004529 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4530 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004531
4532 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4533 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4534
shilufc958392020-01-20 11:36:01 -08004535 final long identity = Binder.clearCallingIdentity();
4536 try {
4537 if (!isActiveSubscription(subId)) {
4538 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4539 }
4540 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4541 } finally {
4542 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004544 }
4545
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004547 public boolean isInEmergencySmsMode() {
4548 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004549
4550 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4551 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4552
Brad Ebingerb2b65522019-03-15 13:48:47 -07004553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 for (Phone phone : PhoneFactory.getPhones()) {
4556 if (phone.isInEmergencySmsMode()) {
4557 return true;
4558 }
4559 }
4560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 return false;
4564 }
4565
shilu366312e2019-12-17 09:28:10 -08004566 /**
4567 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4568 * @param subId The subscription to use to check the configuration.
4569 * @param c The callback that will be used to send the result.
4570 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004571 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004572 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4573 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004574 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004575 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004576
4577 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4578 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4579 "IMS not available on device.");
4580 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004581 final long token = Binder.clearCallingIdentity();
4582 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004583 int slotId = getSlotIndexOrException(subId);
4584 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004585
4586 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4587 if (controller != null) {
4588 ImsManager imsManager = controller.getImsManager(subId);
4589 if (imsManager != null) {
4590 imsManager.addRegistrationCallbackForSubscription(c, subId);
4591 } else {
4592 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4593 }
4594 } else {
4595 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4596 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004597 } catch (ImsException e) {
4598 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 } finally {
4600 Binder.restoreCallingIdentity(token);
4601 }
4602 }
4603
shilu366312e2019-12-17 09:28:10 -08004604 /**
4605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4606 * @param subId The subscription to use to check the configuration.
4607 * @param c The callback that will be used to send the result.
4608 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004609 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004610 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004611 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004612 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4614 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4615 }
Meng Wangafbc5852019-09-19 17:37:13 -07004616 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004617
Meng Wangafbc5852019-09-19 17:37:13 -07004618 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004619 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4620 if (controller != null) {
4621 ImsManager imsManager = controller.getImsManager(subId);
4622 if (imsManager != null) {
4623 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4624 } else {
4625 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4626 + "is inactive, ignoring unregister.");
4627 // If the ImsManager is not valid, just return, since the callback
4628 // will already have been removed internally.
4629 }
4630 }
Meng Wangafbc5852019-09-19 17:37:13 -07004631 } finally {
4632 Binder.restoreCallingIdentity(token);
4633 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004634 }
4635
Brad Ebingera34a6c22019-10-22 17:36:18 -07004636 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004637 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4638 * @param subId The subscription to use to check the configuration.
4639 * @param c The callback that will be used to send the result.
4640 */
4641 @Override
4642 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4643 throws RemoteException {
4644 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4645 mApp, subId, "registerImsEmergencyRegistrationCallback");
4646
4647 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4648 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4649 "IMS not available on device.");
4650 }
4651 final long token = Binder.clearCallingIdentity();
4652 try {
4653 int slotId = getSlotIndexOrException(subId);
4654 verifyImsMmTelConfiguredOrThrow(slotId);
4655
4656 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4657 if (controller != null) {
4658 ImsManager imsManager = controller.getImsManager(subId);
4659 if (imsManager != null) {
4660 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4661 } else {
4662 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4663 }
4664 } else {
4665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4666 }
4667 } catch (ImsException e) {
4668 throw new ServiceSpecificException(e.getCode());
4669 } finally {
4670 Binder.restoreCallingIdentity(token);
4671 }
4672 }
4673
4674 /**
4675 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4676 * @param subId The subscription to use to check the configuration.
4677 * @param c The callback that will be used to send the result.
4678 */
4679 @Override
4680 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4681 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4682 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4684 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4685 }
4686 final long token = Binder.clearCallingIdentity();
4687
4688 try {
4689 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4690 if (controller != null) {
4691 ImsManager imsManager = controller.getImsManager(subId);
4692 if (imsManager != null) {
4693 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4694 } else {
4695 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4696 + "is inactive, ignoring unregister.");
4697 // If the ImsManager is not valid, just return, since the callback
4698 // will already have been removed internally.
4699 }
4700 }
4701 } finally {
4702 Binder.restoreCallingIdentity(token);
4703 }
4704 }
4705
4706 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004707 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4708 */
4709 @Override
4710 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4711 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4712 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4713 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4714 "IMS not available on device.");
4715 }
4716 final long token = Binder.clearCallingIdentity();
4717 try {
4718 Phone phone = getPhone(subId);
4719 if (phone == null) {
4720 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4721 + subId + "'");
4722 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4723 }
4724 phone.getImsRegistrationState(regState -> {
4725 try {
4726 consumer.accept((regState == null)
4727 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4728 } catch (RemoteException e) {
4729 // Ignore if the remote process is no longer available to call back.
4730 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4731 }
4732 });
4733 } finally {
4734 Binder.restoreCallingIdentity(token);
4735 }
4736 }
4737
4738 /**
4739 * Get the transport type for the IMS service registration state.
4740 */
4741 @Override
4742 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004743 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004744 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004745 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4746 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4747 "IMS not available on device.");
4748 }
4749 final long token = Binder.clearCallingIdentity();
4750 try {
4751 Phone phone = getPhone(subId);
4752 if (phone == null) {
4753 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4754 + subId + "'");
4755 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4756 }
4757 phone.getImsRegistrationTech(regTech -> {
4758 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4759 int regTechConverted = (regTech == null)
4760 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4761 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4762 regTechConverted);
4763 try {
4764 consumer.accept(regTechConverted);
4765 } catch (RemoteException e) {
4766 // Ignore if the remote process is no longer available to call back.
4767 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4768 }
4769 });
4770 } finally {
4771 Binder.restoreCallingIdentity(token);
4772 }
4773 }
4774
shilu366312e2019-12-17 09:28:10 -08004775 /**
4776 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4777 * @param subId The subscription to use to check the configuration.
4778 * @param c The callback that will be used to send the result.
4779 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004781 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4782 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004783 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004784 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004785 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4786 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4787 "IMS not available on device.");
4788 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004789 final long token = Binder.clearCallingIdentity();
4790 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004791 int slotId = getSlotIndexOrException(subId);
4792 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004793
4794 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4795 if (controller != null) {
4796 ImsManager imsManager = controller.getImsManager(subId);
4797 if (imsManager != null) {
4798 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4799 } else {
4800 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4801 }
4802 } else {
4803 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4804 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004805 } catch (ImsException e) {
4806 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004807 } finally {
4808 Binder.restoreCallingIdentity(token);
4809 }
4810 }
4811
shilu366312e2019-12-17 09:28:10 -08004812 /**
4813 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4814 * @param subId The subscription to use to check the configuration.
4815 * @param c The callback that will be used to send the result.
4816 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004818 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004819 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004820 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004821 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4822 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4823 }
Meng Wangafbc5852019-09-19 17:37:13 -07004824
4825 final long token = Binder.clearCallingIdentity();
4826 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004827 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4828 if (controller != null) {
4829 ImsManager imsManager = controller.getImsManager(subId);
4830 if (imsManager != null) {
4831 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4832 } else {
4833 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4834 + " is inactive, ignoring unregister.");
4835 // If the ImsManager is not valid, just return, since the callback
4836 // will already have been removed internally.
4837 }
4838 }
Meng Wangafbc5852019-09-19 17:37:13 -07004839 } finally {
4840 Binder.restoreCallingIdentity(token);
4841 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004842 }
4843
4844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004845 public boolean isCapable(int subId, int capability, int regTech) {
4846 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004847
4848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4849 FEATURE_TELEPHONY_IMS, "isCapable");
4850
Brad Ebinger35c841c2018-10-01 10:40:55 -07004851 final long token = Binder.clearCallingIdentity();
4852 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004853 int slotId = getSlotIndexOrException(subId);
4854 verifyImsMmTelConfiguredOrThrow(slotId);
4855 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4856 } catch (com.android.ims.ImsException e) {
4857 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4858 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004859 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004860 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4861 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004862 } finally {
4863 Binder.restoreCallingIdentity(token);
4864 }
4865 }
4866
4867 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004868 public boolean isAvailable(int subId, int capability, int regTech) {
4869 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004870
4871 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4872 FEATURE_TELEPHONY_IMS, "isAvailable");
4873
Brad Ebinger35c841c2018-10-01 10:40:55 -07004874 final long token = Binder.clearCallingIdentity();
4875 try {
4876 Phone phone = getPhone(subId);
4877 if (phone == null) return false;
4878 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004879 } catch (com.android.ims.ImsException e) {
4880 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4881 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 } finally {
4883 Binder.restoreCallingIdentity(token);
4884 }
4885 }
4886
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004887 /**
4888 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4889 * subscription.
4890 * @param subId The subscription to use to check the configuration.
4891 * @param callback The callback that will be used to send the result.
4892 * @param capability The MmTelFeature capability that will be used to send the result.
4893 * @param transportType The transport type of the MmTelFeature capability.
4894 */
4895 @Override
4896 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4897 int transportType) {
4898 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004899 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4900 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4901 "IMS not available on device.");
4902 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004903 final long token = Binder.clearCallingIdentity();
4904 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004905 int slotId = getSlotIndex(subId);
4906 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4907 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4908 + subId + "'");
4909 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4910 }
4911 verifyImsMmTelConfiguredOrThrow(slotId);
4912 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4913 transportType, aBoolean -> {
4914 try {
4915 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4916 } catch (RemoteException e) {
4917 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4918 + "running. Ignore");
4919 }
4920 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004921 } catch (ImsException e) {
4922 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004923 } finally {
4924 Binder.restoreCallingIdentity(token);
4925 }
4926 }
4927
shilu366312e2019-12-17 09:28:10 -08004928 /**
4929 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4930 * @param subId The subscription to use to check the configuration.
4931 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 @Override
4933 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004934 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004935 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004936
joonhunshin4ac60942023-11-15 15:23:39 +00004937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4938 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4939
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 final long token = Binder.clearCallingIdentity();
4941 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004942 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004943 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004944 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004945 } catch (ImsException e) {
4946 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 } finally {
4948 Binder.restoreCallingIdentity(token);
4949 }
4950 }
4951
4952 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004953 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004955 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004956
4957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4958 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4959
Brad Ebinger35c841c2018-10-01 10:40:55 -07004960 final long identity = Binder.clearCallingIdentity();
4961 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004962 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004963 // This setting doesn't require an active ImsService connection, so do not verify. The
4964 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004965 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004966 } catch (ImsException e) {
4967 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004968 } finally {
4969 Binder.restoreCallingIdentity(identity);
4970 }
4971 }
4972
shilu366312e2019-12-17 09:28:10 -08004973 /**
4974 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4975 * @param subId The subscription to use to check the configuration.
4976 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004977 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004978 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004979 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004980 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004981
4982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4983 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4984
Brad Ebinger35c841c2018-10-01 10:40:55 -07004985 final long identity = Binder.clearCallingIdentity();
4986 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004988 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004989 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004990 } catch (ImsException e) {
4991 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
4995 }
4996
4997 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004998 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005000 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005001
5002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5003 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5004
Brad Ebinger35c841c2018-10-01 10:40:55 -07005005 final long identity = Binder.clearCallingIdentity();
5006 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005007 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005008 // This setting doesn't require an active ImsService connection, so do not verify. The
5009 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005010 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005011 } catch (ImsException e) {
5012 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
5016 }
5017
shilu366312e2019-12-17 09:28:10 -08005018 /**
5019 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5020 * @param subId The subscription to use to check the configuration.
5021 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 @Override
5023 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005024 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005025 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005026
5027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5028 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5029
Brad Ebinger35c841c2018-10-01 10:40:55 -07005030 final long identity = Binder.clearCallingIdentity();
5031 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005033 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005034 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005035 } catch (ImsException e) {
5036 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005037 } finally {
5038 Binder.restoreCallingIdentity(identity);
5039 }
5040 }
5041
5042 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005043 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005045 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005046
5047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5048 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5049
Brad Ebinger35c841c2018-10-01 10:40:55 -07005050 final long identity = Binder.clearCallingIdentity();
5051 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005052 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005053 // This setting doesn't require an active ImsService connection, so do not verify. The
5054 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005055 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005056 } catch (ImsException e) {
5057 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
5061 }
5062
shilu366312e2019-12-17 09:28:10 -08005063 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005064 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5065 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5066 * @param subId The subscription to use to check the configuration.
5067 */
5068 @Override
5069 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005070 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005071 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005072
5073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5074 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5075
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005078 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005079 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005080 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005081 } catch (ImsException e) {
5082 throw new ServiceSpecificException(e.getCode());
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
5085 }
5086 }
5087
5088 /**
5089 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5090 * Requires MODIFY_PHONE_STATE permission.
5091 * @param subId The subscription to use to check the configuration.
5092 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5093 * false otherwise
5094 */
5095 @Override
5096 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5098 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005099
5100 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5101 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5102
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005103 final long identity = Binder.clearCallingIdentity();
5104 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005105 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005106 // This setting doesn't require an active ImsService connection, so do not verify. The
5107 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005108 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005109 } catch (ImsException e) {
5110 throw new ServiceSpecificException(e.getCode());
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
5113 }
5114 }
5115
5116 /**
shilu366312e2019-12-17 09:28:10 -08005117 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5118 * @param subId The subscription to use to check the configuration.
5119 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005121
Brad Ebinger35c841c2018-10-01 10:40:55 -07005122 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005123 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005124 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005125
5126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5127 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5128
Brad Ebinger35c841c2018-10-01 10:40:55 -07005129 final long identity = Binder.clearCallingIdentity();
5130 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005132 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005133 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005134 } catch (ImsException e) {
5135 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
5139 }
5140
5141 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005142 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005144 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005145
5146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5147 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5148
Brad Ebinger35c841c2018-10-01 10:40:55 -07005149 final long identity = Binder.clearCallingIdentity();
5150 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005152 // This setting doesn't require an active ImsService connection, so do not verify. The
5153 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005154 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005155 } catch (ImsException e) {
5156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
5160 }
5161
5162 @Override
5163 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5165 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005166
5167 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5168 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5169
Brad Ebinger35c841c2018-10-01 10:40:55 -07005170 final long identity = Binder.clearCallingIdentity();
5171 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005172 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005173 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005174 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005175 } catch (ImsException e) {
5176 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
5180 }
5181
shilu366312e2019-12-17 09:28:10 -08005182 /**
5183 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5184 * @param subId The subscription to use to check the configuration.
5185 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005186 @Override
5187 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005188 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005189 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005190
5191 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5192 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5193
Brad Ebinger35c841c2018-10-01 10:40:55 -07005194 final long identity = Binder.clearCallingIdentity();
5195 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005196 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005197 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005198 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005199 } catch (ImsException e) {
5200 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
5204 }
5205
5206 @Override
5207 public void setVoWiFiModeSetting(int subId, int mode) {
5208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5209 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005210
5211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5212 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5213
Brad Ebinger35c841c2018-10-01 10:40:55 -07005214 final long identity = Binder.clearCallingIdentity();
5215 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005216 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005217 // This setting doesn't require an active ImsService connection, so do not verify. The
5218 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005219 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005220 } catch (ImsException e) {
5221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
5225 }
5226
5227 @Override
5228 public int getVoWiFiRoamingModeSetting(int subId) {
5229 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005230
5231 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5232 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5233
Brad Ebinger35c841c2018-10-01 10:40:55 -07005234 final long identity = Binder.clearCallingIdentity();
5235 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005236 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005237 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005238 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005239 } catch (ImsException e) {
5240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
5244 }
5245
5246 @Override
5247 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5249 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005250
5251 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5252 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5253
Brad Ebinger35c841c2018-10-01 10:40:55 -07005254 final long identity = Binder.clearCallingIdentity();
5255 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005256 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005257 // This setting doesn't require an active ImsService connection, so do not verify. The
5258 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005259 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005260 } catch (ImsException e) {
5261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
5265 }
5266
5267 @Override
5268 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5270 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005271
5272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5273 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5274
Brad Ebinger35c841c2018-10-01 10:40:55 -07005275 final long identity = Binder.clearCallingIdentity();
5276 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005277 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005278 // This setting doesn't require an active ImsService connection, so do not verify. The
5279 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005280 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005281 } catch (ImsException e) {
5282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
shilu366312e2019-12-17 09:28:10 -08005288 /**
5289 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5290 * @param subId The subscription to use to check the configuration.
5291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005292 @Override
5293 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005294 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005295 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005296
5297 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5298 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5299
Brad Ebinger35c841c2018-10-01 10:40:55 -07005300 final long identity = Binder.clearCallingIdentity();
5301 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005302 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005303 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005304 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005305 } catch (ImsException e) {
5306 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
5310 }
5311
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005312 @Override
5313 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5314 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005315
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005316 final long identity = Binder.clearCallingIdentity();
5317 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005318 if (!isImsAvailableOnDevice()) {
5319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5320 "IMS not available on device.");
5321 }
5322 int slotId = getSlotIndexOrException(subId);
5323 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005324
5325 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5326 if (controller != null) {
5327 ImsManager imsManager = controller.getImsManager(subId);
5328 if (imsManager != null) {
5329 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5330 } else {
5331 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5332 }
5333 } else {
5334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5335 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005336 } catch (ImsException e) {
5337 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
5343 @Override
5344 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5345 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005346
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005347 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005348 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5349 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5350 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005351 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005352 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5353 if (controller != null) {
5354 ImsManager imsManager = controller.getImsManager(subId);
5355 if (imsManager != null) {
5356 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5357 } else {
5358 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5359 + " is inactive, ignoring unregister.");
5360 // If the ImsManager is not valid, just return, since the callback will already
5361 // have been removed internally.
5362 }
5363 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
5367 }
5368
joonhunshincffb7fc2021-11-28 07:32:01 +00005369 @Override
5370 public void registerFeatureProvisioningChangedCallback(int subId,
5371 IFeatureProvisioningCallback callback) {
5372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5373 mApp, subId, "registerFeatureProvisioningChangedCallback");
5374
5375 final long identity = Binder.clearCallingIdentity();
5376 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5377 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5378 }
5379
joonhunshin91bc1952022-04-29 08:47:15 +00005380 try {
5381 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5382 if (controller == null) {
5383 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5384 "Device does not support IMS");
5385 }
5386 controller.addFeatureProvisioningChangedCallback(subId, callback);
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005390 }
5391
5392 @Override
5393 public void unregisterFeatureProvisioningChangedCallback(int subId,
5394 IFeatureProvisioningCallback callback) {
5395 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5396 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5397
5398 final long identity = Binder.clearCallingIdentity();
5399 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5400 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5401 }
5402
joonhunshin91bc1952022-04-29 08:47:15 +00005403 try {
5404 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5405 if (controller == null) {
5406 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5407 return;
5408 }
5409 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5410 } finally {
5411 Binder.restoreCallingIdentity(identity);
5412 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005413 }
allenwtsu99c623b2020-01-03 18:24:23 +08005414
5415 private void checkModifyPhoneStatePermission(int subId, String message) {
5416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5417 message);
5418 }
5419
allenwtsu99c623b2020-01-03 18:24:23 +08005420 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005421 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005422 boolean isProvisioned) {
5423 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5424
joonhunshin4ac60942023-11-15 15:23:39 +00005425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5426 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5427
allenwtsu99c623b2020-01-03 18:24:23 +08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005430 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5431 if (controller == null) {
5432 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5433 return;
5434 }
5435 controller.setRcsProvisioningStatusForCapability(
5436 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
allenwtsu99c623b2020-01-03 18:24:23 +08005440 }
5441
5442
5443 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005444 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5445 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5446 mApp, subId, "getRcsProvisioningStatusForCapability");
5447
joonhunshin4ac60942023-11-15 15:23:39 +00005448 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5449 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5450
allenwtsu99c623b2020-01-03 18:24:23 +08005451 final long identity = Binder.clearCallingIdentity();
5452 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005453 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5454 if (controller == null) {
5455 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5456
5457 // device does not support IMS, this method will return true always.
5458 return true;
5459 }
5460 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
5464 }
5465
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005466 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005467 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5468 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005469 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005470
joonhunshin4ac60942023-11-15 15:23:39 +00005471 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5472 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5473
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005474 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005477 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5478 if (controller == null) {
5479 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5480 return;
5481 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005482 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005483 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
5487 }
5488
5489 @Override
5490 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005491 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5492 mApp, subId, "getProvisioningStatusForCapability");
5493
joonhunshin4ac60942023-11-15 15:23:39 +00005494 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5495 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5496
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005497 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005498 final long identity = Binder.clearCallingIdentity();
5499 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005500 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5501 if (controller == null) {
5502 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005503
joonhunshin91bc1952022-04-29 08:47:15 +00005504 // device does not support IMS, this method will return true always.
5505 return true;
5506 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005507 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5508 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
5512 }
5513
5514 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005515 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5516 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5517 mApp, subId, "isProvisioningRequiredForCapability");
5518
joonhunshin4ac60942023-11-15 15:23:39 +00005519 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5520 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5521
joonhunshincffb7fc2021-11-28 07:32:01 +00005522 final long identity = Binder.clearCallingIdentity();
5523 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005524 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5525 if (controller == null) {
5526 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5527
5528 // device does not support IMS, this method will return false
5529 return false;
5530 }
5531 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005534 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535 }
5536
5537 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005538 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5539 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5540 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005541
joonhunshin4ac60942023-11-15 15:23:39 +00005542 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5543 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5544
joonhunshincffb7fc2021-11-28 07:32:01 +00005545 final long identity = Binder.clearCallingIdentity();
5546 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005547 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5548 if (controller == null) {
5549 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5550
5551 // device does not support IMS, this method will return false
5552 return false;
5553 }
5554 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005558 }
5559
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005560 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005561 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005562 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5563 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5564 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005565 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5566 mApp, subId, "getImsProvisioningInt");
5567
joonhunshin4ac60942023-11-15 15:23:39 +00005568 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5569 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5570
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005571 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005572 final long identity = Binder.clearCallingIdentity();
5573 try {
5574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005575 int slotId = getSlotIndex(subId);
5576 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5577 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5578 + subId + "' for key:" + key);
5579 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5580 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005581
joonhunshin91bc1952022-04-29 08:47:15 +00005582 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5583 if (controller == null) {
5584 loge("getImsProvisioningInt: Device does not support IMS");
5585
5586 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5587 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5588 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005589 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5590 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005591 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5592 return retVal;
5593 }
5594
calvinpanb5a34062021-02-08 19:59:36 +08005595 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005596 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005597 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5598 + subId + "' for key:" + key);
5599 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
5603 }
5604
5605 @Override
5606 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5608 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5609 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005610 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5611 mApp, subId, "getImsProvisioningString");
5612
joonhunshin4ac60942023-11-15 15:23:39 +00005613 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5614 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5615
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005619 int slotId = getSlotIndex(subId);
5620 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5621 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5622 + subId + "' for key:" + key);
5623 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5624 }
calvinpanb5a34062021-02-08 19:59:36 +08005625 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005626 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005627 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5628 + subId + "' for key:" + key);
5629 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
5633 }
5634
5635 @Override
5636 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5638 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5639 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5641 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005642
joonhunshin4ac60942023-11-15 15:23:39 +00005643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5644 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5645
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005646 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005650 int slotId = getSlotIndex(subId);
5651 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5652 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5653 + subId + "' for key:" + key);
5654 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5655 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005656
joonhunshin91bc1952022-04-29 08:47:15 +00005657 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5658 if (controller == null) {
5659 loge("setImsProvisioningInt: Device does not support IMS");
5660
5661 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5662 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5663 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005664 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5665 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005666 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5667 return retVal;
5668 }
5669
calvinpanb5a34062021-02-08 19:59:36 +08005670 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5671 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005672 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005673 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005674 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
5678 }
5679
5680 @Override
5681 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5683 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5684 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5686 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005687
5688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5689 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5690
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005694 int slotId = getSlotIndex(subId);
5695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5696 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5697 + subId + "' for key:" + key);
5698 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5699 }
calvinpanb5a34062021-02-08 19:59:36 +08005700 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5701 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005702 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005703 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005704 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
5708 }
5709
Brad Ebinger919631e2021-06-02 17:46:35 -07005710 /**
5711 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5712 * for the given slot ID or no ImsResolver instance has been created.
5713 * @param slotId The slot ID that the IMS service is created for.
5714 * @throws ImsException If there is no ImsService configured for this slot.
5715 */
5716 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5717 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5718 ImsFeature.FEATURE_MMTEL)) {
5719 throw new ImsException("This subscription does not support MMTEL over IMS",
5720 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5721 }
5722 }
5723
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005724 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005725 int slotId = SubscriptionManager.getSlotIndex(subId);
5726 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005727 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5728 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005729 }
5730 return slotId;
5731 }
5732
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005733 private int getSlotIndex(int subId) {
5734 int slotId = SubscriptionManager.getSlotIndex(subId);
5735 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5736 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5737 }
5738 return slotId;
5739 }
5740
Wink Saville36469e72014-06-11 15:17:00 -07005741 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005742 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005743 */
5744 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005745 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5746 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005747 try {
5748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5749 } catch (SecurityException se) {
5750 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5751 throw new SecurityException("Package " + callingPackage + " does not belong to "
5752 + Binder.getCallingUid());
5753 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005754 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005755 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005756 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005757 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005758 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005759 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005761 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5762 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005763
joonhunshin4ac60942023-11-15 15:23:39 +00005764 enforceTelephonyFeatureWithException(callingPackage,
5765 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 final Phone phone = getPhone(subId);
5770 if (phone != null) {
5771 return phone.getServiceState().getDataNetworkType();
5772 } else {
5773 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5774 }
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005778 }
5779
5780 /**
5781 * Returns the data network type
5782 */
5783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005784 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005785 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005786 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005787 }
5788
5789 /**
5790 * Returns the data network type for a subId
5791 */
5792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005793 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5794 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005795 String functionName = "getDataNetworkTypeForSubscriber";
5796 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5797 mApp, functionName)) {
5798 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5799 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5800 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5801 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005802 }
5803
joonhunshin4ac60942023-11-15 15:23:39 +00005804 enforceTelephonyFeatureWithException(callingPackage,
5805 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 final Phone phone = getPhone(subId);
5810 if (phone != null) {
5811 return phone.getServiceState().getDataNetworkType();
5812 } else {
5813 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5814 }
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005818 }
5819
5820 /**
Wink Saville36469e72014-06-11 15:17:00 -07005821 * Returns the Voice network type for a subId
5822 */
5823 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005824 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5825 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005826 String functionName = "getVoiceNetworkTypeForSubscriber";
5827 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5828 mApp, functionName)) {
5829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5830 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5831 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5832 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005833 }
5834
joonhunshin4ac60942023-11-15 15:23:39 +00005835 enforceTelephonyFeatureWithException(callingPackage,
5836 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 final Phone phone = getPhone(subId);
5841 if (phone != null) {
5842 return phone.getServiceState().getVoiceNetworkType();
5843 } else {
5844 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5845 }
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005849 }
5850
5851 /**
5852 * @return true if a ICC card is present
5853 */
5854 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005855 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005856 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005857 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005858 }
5859
5860 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005861 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005862 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005863 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005864 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005865 if (!mApp.getResources().getBoolean(
5866 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5868 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5869 }
joonhunshin4ac60942023-11-15 15:23:39 +00005870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 final Phone phone = PhoneFactory.getPhone(slotIndex);
5874 if (phone != null) {
5875 return phone.getIccCard().hasIccCard();
5876 } else {
5877 return false;
5878 }
5879 } finally {
5880 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005882 }
5883
5884 /**
5885 * Return if the current radio is LTE on CDMA. This
5886 * is a tri-state return value as for a period of time
5887 * the mode may be unknown.
5888 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005889 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005890 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005891 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005892 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005894 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5895 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5896 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005897 }
5898
Sanket Padawe356d7632015-06-22 14:03:32 -07005899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005900 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5901 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005902 try {
5903 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5904 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005905 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5906 }
5907
joonhunshin4ac60942023-11-15 15:23:39 +00005908 enforceTelephonyFeatureWithException(callingPackage,
5909 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 final Phone phone = getPhone(subId);
5914 if (phone == null) {
5915 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5916 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005917 return TelephonyProperties.lte_on_cdma_device()
5918 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 }
5920 } finally {
5921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005922 }
Wink Saville36469e72014-06-11 15:17:00 -07005923 }
5924
Wink Saville36469e72014-06-11 15:17:00 -07005925 /**
5926 * {@hide}
5927 * Returns Default subId, 0 in the case of single standby.
5928 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005929 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005930 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005931 }
5932
Shishir Agrawala9f32182016-04-12 12:00:16 -07005933 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005934 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005935 }
5936
Wink Savilleb564aae2014-10-23 10:18:09 -07005937 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005938 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005939 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005940
Pengquan Menge92a50d2018-09-21 15:54:48 -07005941 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005942 return getSubscriptionManagerService().isActiveSubId(subId,
5943 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005944 }
5945
Ihab Awadf2177b72013-11-25 13:33:23 -08005946 /**
5947 * @see android.telephony.TelephonyManager.WifiCallingChoices
5948 */
5949 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 final long identity = Binder.clearCallingIdentity();
5951 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005952 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5954 getWhenToMakeWifiCallsDefaultPreference());
5955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005958 }
5959
5960 /**
5961 * @see android.telephony.TelephonyManager.WifiCallingChoices
5962 */
5963 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005967 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005972 }
5973
Sailesh Nepald1e68152013-12-12 19:08:02 -08005974 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005975 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005976 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005977 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005978
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005979 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5980 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5981 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005982 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005983 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005984 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005985 }
5986 return PhoneFactory.getPhone(phoneId);
5987 }
5988
Shishir Agrawal566b7612013-10-28 14:41:00 -07005989 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005990 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005991 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005992
Rambo Wanga1782702021-11-10 20:15:19 -08005993 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5994 /*message=*/ "iccOpenLogicalChannel");
5995
5996 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5997 // Verify that the callingPackage in the request belongs to the calling UID
5998 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5999
joonhunshin4ac60942023-11-15 15:23:39 +00006000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6001 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6002
Rambo Wanga1782702021-11-10 20:15:19 -08006003 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006004 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006005
Rambo Wanga1782702021-11-10 20:15:19 -08006006 private Phone getPhoneFromValidIccLogicalChannelRequest(
6007 @NonNull IccLogicalChannelRequest request, String message) {
6008 Phone phone;
6009 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6011 mApp, request.subId, message);
6012 phone = getPhoneFromSubId(request.subId);
6013 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6014 enforceModifyPermission();
6015 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6016 } else {
6017 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006018 }
Rambo Wanga1782702021-11-10 20:15:19 -08006019 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006020 }
6021
6022 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006023 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 final long identity = Binder.clearCallingIdentity();
6025 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006026 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006028 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6029 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006030 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6031 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 loge("The calling package is not allowed to access ISD-R.");
6033 throw new SecurityException(
6034 "The calling package is not allowed to access ISD-R.");
6035 }
Derek Tan740e1672017-06-27 14:56:27 -07006036 }
Derek Tan740e1672017-06-27 14:56:27 -07006037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006039 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6040 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 return response;
6042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006045 }
6046
6047 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006048 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006049 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6050 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6051
Rambo Wanga1782702021-11-10 20:15:19 -08006052 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6053 /*message=*/"iccCloseLogicalChannel");
6054
6055 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6056
6057 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006058 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006059
Rambo Wanga1782702021-11-10 20:15:19 -08006060 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6061 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006062 // before this feature is enabled, this API should only return false if
6063 // the operation fails instead of throwing runtime exception for
6064 // backward-compatibility.
6065 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6066 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 final long identity = Binder.clearCallingIdentity();
6068 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006069 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006070 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 }
Chen Xue9d737e2022-01-01 23:41:31 -08006072 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006073 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006074 Boolean success = false;
6075 if (result instanceof RuntimeException) {
6076 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006077 if (shouldThrowExceptionOnFailure) {
6078 throw (RuntimeException) result;
6079 } else {
6080 return false;
6081 }
Chen Xue9d737e2022-01-01 23:41:31 -08006082 } else if (result instanceof Boolean) {
6083 success = (Boolean) result;
6084 } else {
6085 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6086 }
Rambo Wanga1782702021-11-10 20:15:19 -08006087 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 return success;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006091 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006092 }
6093
6094 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006095 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006096 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6098 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006099
6100 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6101 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6102
Jordan Liu4c733742019-02-28 12:03:40 -08006103 if (DBG) {
6104 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6105 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6106 + p3 + " data=" + data);
6107 }
6108 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6109 command, p1, p2, p3, data);
6110 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006111
Jordan Liu4c733742019-02-28 12:03:40 -08006112 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006113 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006114 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006115 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006116
6117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6118 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6119 "iccTransmitApduLogicalChannelBySlot");
6120
Jordan Liu4c733742019-02-28 12:03:40 -08006121 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006122 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006123 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6124 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006125 }
6126 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006127 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6128 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006129 }
6130
6131 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6132 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
6134 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006135 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 return "";
6137 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006140 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6141 null /* workSource */);
6142 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 // Append the returned status code to the end of the response payload.
6145 String s = Integer.toHexString(
6146 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6147 if (response.payload != null) {
6148 s = IccUtils.bytesToHexString(response.payload) + s;
6149 }
6150 return s;
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006153 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006154 }
Jake Hambye994d462014-02-03 13:10:13 -08006155
Evan Charltonc66da362014-05-16 14:06:40 -07006156 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006157 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6158 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6160 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006162
6163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6164 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6165
Jordan Liu4c733742019-02-28 12:03:40 -08006166 if (DBG) {
6167 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6168 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6169 }
6170 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6171 cla, command, p1, p2, p3, data);
6172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006173
Jordan Liu4c733742019-02-28 12:03:40 -08006174 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006175 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006176 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006177 enforceModifyPermission();
6178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006179
6180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6181 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6182
Jordan Liu4c733742019-02-28 12:03:40 -08006183 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006184 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006185 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6186 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006187 }
6188
6189 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006190 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6191 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006192 }
6193
6194 // open APDU basic channel assuming the caller has sufficient permissions
6195 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6196 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6200 && TextUtils.equals(ISDR_AID, data)) {
6201 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006202 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6203 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 if (bestComponent == null
6205 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6206 loge("The calling package is not allowed to select ISD-R.");
6207 throw new SecurityException(
6208 "The calling package is not allowed to select ISD-R.");
6209 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006210 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006213 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6214 null /* workSource */);
6215 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 // Append the returned status code to the end of the response payload.
6218 String s = Integer.toHexString(
6219 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6220 if (response.payload != null) {
6221 s = IccUtils.bytesToHexString(response.payload) + s;
6222 }
6223 return s;
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006226 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006227 }
6228
6229 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006230 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006231 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6233 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006234
joonhunshin4ac60942023-11-15 15:23:39 +00006235 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6236 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 if (DBG) {
6241 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6242 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6243 }
6244
6245 IccIoResult response =
6246 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6247 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6248 subId);
6249
6250 if (DBG) {
6251 log("Exchange SIM_IO [R]" + response);
6252 }
6253
6254 byte[] result = null;
6255 int length = 2;
6256 if (response.payload != null) {
6257 length = 2 + response.payload.length;
6258 result = new byte[length];
6259 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6260 } else {
6261 result = new byte[length];
6262 }
6263
6264 result[length - 1] = (byte) response.sw2;
6265 result[length - 2] = (byte) response.sw1;
6266 return result;
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006269 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006270 }
6271
Nathan Haroldb3014052017-01-25 15:57:32 -08006272 /**
6273 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6274 * on a particular subscription
6275 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006276 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6277 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006279 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006280 return null;
6281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282
joonhunshin4ac60942023-11-15 15:23:39 +00006283 enforceTelephonyFeatureWithException(callingPackage,
6284 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 final long identity = Binder.clearCallingIdentity();
6287 try {
6288 if (appType != TelephonyManager.APPTYPE_USIM
6289 && appType != TelephonyManager.APPTYPE_SIM) {
6290 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6291 return null;
6292 }
6293 Object response = sendRequest(
6294 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6295 if (response instanceof String[]) {
6296 return (String[]) response;
6297 }
yincheng zhao2737e882019-09-06 17:06:54 -07006298 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006300 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 } finally {
6302 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006303 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006304 }
6305
yincheng zhao2737e882019-09-06 17:06:54 -07006306 /**
6307 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6308 * subscription.
6309 *
6310 * @param subId the id of the subscription.
6311 * @param appType the uicc app type, must be USIM or SIM.
6312 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6313 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006314 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006315 * @return number of fplmns that is successfully written to the SIM.
6316 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006317 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6318 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6320 mApp, subId, "setForbiddenPlmns");
6321
joonhunshin4ac60942023-11-15 15:23:39 +00006322 enforceTelephonyFeatureWithException(callingPackage,
6323 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6324
yincheng zhao2737e882019-09-06 17:06:54 -07006325 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6326 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6327 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6328 }
6329 if (fplmns == null) {
6330 throw new IllegalArgumentException("Fplmn List provided is null");
6331 }
6332 for (String fplmn : fplmns) {
6333 if (!CellIdentity.isValidPlmn(fplmn)) {
6334 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6335 }
6336 }
6337 final long identity = Binder.clearCallingIdentity();
6338 try {
6339 Object response = sendRequest(
6340 CMD_SET_FORBIDDEN_PLMNS,
6341 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6342 subId);
6343 return (int) response;
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
6346 }
6347 }
6348
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006349 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006350 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6352 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006353
joonhunshin4ac60942023-11-15 15:23:39 +00006354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6355 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6360 if (response.payload == null) {
6361 return "";
6362 }
Evan Charltonc66da362014-05-16 14:06:40 -07006363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 // Append the returned status code to the end of the response payload.
6365 String s = Integer.toHexString(
6366 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6367 s = IccUtils.bytesToHexString(response.payload) + s;
6368 return s;
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Evan Charltonc66da362014-05-16 14:06:40 -07006372 }
6373
Jake Hambye994d462014-02-03 13:10:13 -08006374 /**
6375 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6376 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6377 *
6378 * @param itemID the ID of the item to read
6379 * @return the NV item as a String, or null on error.
6380 */
6381 @Override
6382 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006383 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6385 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
6387 final long identity = Binder.clearCallingIdentity();
6388 try {
6389 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006390 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6392 return value;
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Jake Hambye994d462014-02-03 13:10:13 -08006396 }
6397
6398 /**
6399 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6400 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6401 *
6402 * @param itemID the ID of the item to read
6403 * @param itemValue the value to write, as a String
6404 * @return true on success; false on any failure
6405 */
6406 @Override
6407 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6410 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411
6412 final long identity = Binder.clearCallingIdentity();
6413 try {
6414 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6415 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006416 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6418 return success;
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
Jake Hambye994d462014-02-03 13:10:13 -08006422 }
6423
6424 /**
6425 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6426 * Used for device configuration by some CDMA operators.
6427 *
6428 * @param preferredRoamingList byte array containing the new PRL
6429 * @return true on success; false on any failure
6430 */
6431 @Override
6432 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6434 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6439 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6440 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6441 return success;
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
Jake Hambye994d462014-02-03 13:10:13 -08006445 }
6446
6447 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006448 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006449 * Used for device configuration by some CDMA operators.
6450 *
chen xu6dac5ab2018-10-26 17:39:23 -07006451 * @param slotIndex - device slot.
6452 *
Jake Hambye994d462014-02-03 13:10:13 -08006453 * @return true on success; false on any failure
6454 */
6455 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006456 public boolean resetModemConfig(int slotIndex) {
6457 Phone phone = PhoneFactory.getPhone(slotIndex);
6458 if (phone != null) {
6459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6460 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461
joonhunshin4ac60942023-11-15 15:23:39 +00006462 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6463 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6464
chen xu6dac5ab2018-10-26 17:39:23 -07006465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6468 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6469 return success;
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 }
chen xu6dac5ab2018-10-26 17:39:23 -07006474 return false;
6475 }
6476
6477 /**
6478 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6479 *
6480 * @param slotIndex - device slot.
6481 *
6482 * @return true on success; false on any failure
6483 */
6484 @Override
6485 public boolean rebootModem(int slotIndex) {
6486 Phone phone = PhoneFactory.getPhone(slotIndex);
6487 if (phone != null) {
6488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6489 mApp, phone.getSubId(), "rebootModem");
6490
joonhunshin4ac60942023-11-15 15:23:39 +00006491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6492 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6493
chen xu6dac5ab2018-10-26 17:39:23 -07006494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6497 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6498 return success;
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
6501 }
6502 }
6503 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006504 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006505
Brad Ebinger51f743a2017-01-23 13:50:20 -08006506 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006507 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6508 * {@link #disableIms(int)}.
6509 * @param slotIndex device slot.
6510 */
6511 public void resetIms(int slotIndex) {
6512 enforceModifyPermission();
6513
joonhunshin4ac60942023-11-15 15:23:39 +00006514 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6515 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6516
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006517 final long identity = Binder.clearCallingIdentity();
6518 try {
6519 if (mImsResolver == null) {
6520 // may happen if the does not support IMS.
6521 return;
6522 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006523 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006524 } finally {
6525 Binder.restoreCallingIdentity(identity);
6526 }
6527 }
6528
6529 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006530 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6531 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006532 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006533 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006534 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535
6536 final long identity = Binder.clearCallingIdentity();
6537 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006538 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006539 // may happen if the device does not support IMS.
6540 return;
6541 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006542 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543 } finally {
6544 Binder.restoreCallingIdentity(identity);
6545 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006546 }
6547
6548 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006549 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6550 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006551 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006552 public void disableIms(int slotId) {
6553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006557 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006558 // may happen if the device does not support IMS.
6559 return;
6560 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006561 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006565 }
6566
6567 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006568 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6569 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006570 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006571 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006572 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006577 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006578 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6579 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006580 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006581 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006585 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006586 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006587 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6588 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006589 @Override
6590 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006591 enforceModifyPermission();
6592
6593 final long identity = Binder.clearCallingIdentity();
6594 try {
6595 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006596 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006597 } finally {
6598 Binder.restoreCallingIdentity(identity);
6599 }
6600 }
6601
6602 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006603 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006604 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006605 */
6606 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608
6609 final long identity = Binder.clearCallingIdentity();
6610 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006612 // may happen if the device does not support IMS.
6613 return null;
6614 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006615 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
6618 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006619 }
6620
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006621 /**
6622 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006623 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006624 */
6625 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6626 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627
6628 final long identity = Binder.clearCallingIdentity();
6629 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006630 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006631 // may happen if the device does not support IMS.
6632 return null;
6633 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006634 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 } finally {
6636 Binder.restoreCallingIdentity(identity);
6637 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006638 }
6639
Brad Ebinger884c07b2018-02-15 16:17:40 -08006640 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006641 * Sets the ImsService Package Name that Telephony will bind to.
6642 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006643 * @param slotIndex the slot ID that the ImsService should bind for.
Brad Ebinger555ddec2024-11-04 13:46:31 -08006644 * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL}
6645 * if there is no preference.
Brad Ebinger24c29992019-12-05 13:03:21 -08006646 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006647 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006648 * @param featureTypes An integer array of feature types associated with a packageName.
6649 * @param packageName The name of the package that the current configuration will be replaced
6650 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006652 */
Brad Ebinger555ddec2024-11-04 13:46:31 -08006653 public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService,
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006657 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 final long identity = Binder.clearCallingIdentity();
6660 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006661 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006662 // may happen if the device does not support IMS.
6663 return false;
6664 }
Brad Ebinger555ddec2024-11-04 13:46:31 -08006665 return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId,
6666 isCarrierService, featureTypes);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006670 }
6671
6672 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006673 * Clears any carrier ImsService overrides for the slot index specified that were previously
6674 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6675 *
6676 * This should only be used for testing.
6677 *
6678 * @param slotIndex the slot ID that the ImsService should bind for.
6679 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6680 */
6681 @Override
6682 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6684 "clearCarrierImsServiceOverride");
6685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006686 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 if (mImsResolver == null) {
6691 // may happen if the device does not support IMS.
6692 return false;
6693 }
6694 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
6698 }
6699
6700 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006701 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006702 *
6703 * @param slotId The slot that the ImsService is associated with.
6704 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6705 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006706 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006707 * @return the package name of the ImsService configuration.
6708 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006709 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6710 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006711 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6713 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006718 // may happen if the device does not support IMS.
6719 return "";
6720 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006721 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006722 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6723 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006727 }
6728
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006729 /**
6730 * Get the MmTelFeature state associated with the requested subscription id.
6731 * @param subId The subscription that the MmTelFeature is associated with.
6732 * @param callback A callback with an integer containing the
6733 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6734 */
6735 @Override
6736 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6737 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6740 "IMS not available on device.");
6741 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006742 final long token = Binder.clearCallingIdentity();
6743 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006744 int slotId = getSlotIndex(subId);
6745 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6746 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6747 + subId + "'");
6748 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6749 }
6750 verifyImsMmTelConfiguredOrThrow(slotId);
6751 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6752 try {
6753 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6754 } catch (RemoteException e) {
6755 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6756 + "Ignore");
6757 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006758 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006759 } catch (ImsException e) {
6760 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006761 } finally {
6762 Binder.restoreCallingIdentity(token);
6763 }
6764 }
6765
Daniel Brightbb5840b2021-01-12 15:48:18 -08006766 /**
6767 * Sets the ims registration state on all valid {@link Phone}s.
6768 */
6769 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006770 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771
6772 final long identity = Binder.clearCallingIdentity();
6773 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006774 // NOTE: Before S, this method only set the default phone.
6775 for (final Phone phone : PhoneFactory.getPhones()) {
6776 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6777 phone.setImsRegistrationState(registered);
6778 }
6779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
Wink Saville36469e72014-06-11 15:17:00 -07006783 }
6784
6785 /**
Stuart Scott54788802015-03-30 13:18:01 -07006786 * Set the network selection mode to automatic.
6787 *
6788 */
6789 @Override
6790 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6792 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
joonhunshin4ac60942023-11-15 15:23:39 +00006794 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6795 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
6798 try {
shilufc958392020-01-20 11:36:01 -08006799 if (!isActiveSubscription(subId)) {
6800 return;
6801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006803 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006804 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
Stuart Scott54788802015-03-30 13:18:01 -07006808 }
6809
Jack Yud10cdd42020-09-28 20:28:01 -07006810 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006811 * Ask the radio to connect to the input network and change selection mode to manual.
6812 *
6813 * @param subId the id of the subscription.
6814 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6815 * the operator to attach to.
6816 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6817 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6818 * normal network selection next time.
6819 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006820 */
6821 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006822 public boolean setNetworkSelectionModeManual(
6823 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6825 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006826
joonhunshin4ac60942023-11-15 15:23:39 +00006827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6828 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6829
Jack Yu285100e2022-12-02 22:48:35 -08006830 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006831 if (!isActiveSubscription(subId)) {
6832 return false;
6833 }
6834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006836 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006838 if (DBG) {
6839 log("setNetworkSelectionModeManual: subId: " + subId
6840 + " operator: " + operatorInfo);
6841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006846 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006847 /**
shilu84f6e8b2019-12-19 13:58:01 -08006848 * Get the manual network selection
6849 *
6850 * @param subId the id of the subscription.
6851 *
6852 * @return the previously saved user selected PLMN
6853 */
6854 @Override
6855 public String getManualNetworkSelectionPlmn(int subId) {
6856 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006857 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6858 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006859
joonhunshin4ac60942023-11-15 15:23:39 +00006860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6862
shilu84f6e8b2019-12-19 13:58:01 -08006863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006866 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006867 }
6868
6869 final Phone phone = getPhone(subId);
6870 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006871 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006872 }
6873 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6874 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006875 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006880
6881 /**
6882 * Scans for available networks.
6883 */
6884 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006885 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6886 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6888 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006889 LocationAccessPolicy.LocationPermissionResult locationResult =
6890 LocationAccessPolicy.checkLocationPermission(mApp,
6891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6892 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006893 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006894 .setCallingPid(Binder.getCallingPid())
6895 .setCallingUid(Binder.getCallingUid())
6896 .setMethod("getCellNetworkScanResults")
6897 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6899 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006900 .build());
6901 switch (locationResult) {
6902 case DENIED_HARD:
6903 throw new SecurityException("Not allowed to access scan results -- location");
6904 case DENIED_SOFT:
6905 return null;
6906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907
Pengquan Menga1bb6272018-09-06 09:59:22 -07006908 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 try {
6910 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006911 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006916 }
6917
6918 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006919 * Get the call forwarding info, given the call forwarding reason.
6920 */
6921 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006922 public void getCallForwarding(int subId, int callForwardingReason,
6923 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006924 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006925
6926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6927 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6928
Shuo Qian4a594052020-01-23 11:59:30 -08006929 long identity = Binder.clearCallingIdentity();
6930 try {
6931 if (DBG) {
6932 log("getCallForwarding: subId " + subId
6933 + " callForwardingReason" + callForwardingReason);
6934 }
Hall Liu27d24262020-09-18 19:04:59 -07006935
6936 Phone phone = getPhone(subId);
6937 if (phone == null) {
6938 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006939 callback.onError(
6940 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006941 } catch (RemoteException e) {
6942 // ignore
6943 }
6944 return;
6945 }
6946
6947 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6948 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6949 @Override
6950 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6951 try {
6952 callback.onCallForwardingInfoAvailable(info);
6953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 }
6957
6958 @Override
6959 public void onError(int error) {
6960 try {
6961 callback.onError(error);
6962 } catch (RemoteException e) {
6963 // ignore
6964 }
6965 }
6966 });
6967 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
6973 /**
6974 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6975 * reason, the number to forward, and the timeout before the forwarding is attempted.
6976 */
6977 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006978 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6979 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006980 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006981
6982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6983 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6984
Shuo Qian4a594052020-01-23 11:59:30 -08006985 long identity = Binder.clearCallingIdentity();
6986 try {
6987 if (DBG) {
6988 log("setCallForwarding: subId " + subId
6989 + " callForwardingInfo" + callForwardingInfo);
6990 }
Hall Liu27d24262020-09-18 19:04:59 -07006991
6992 Phone phone = getPhone(subId);
6993 if (phone == null) {
6994 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006995 callback.accept(
6996 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006997 } catch (RemoteException e) {
6998 // ignore
6999 }
7000 return;
7001 }
7002
7003 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7004 FunctionalUtils.ignoreRemoteException(callback::accept));
7005
7006 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 }
7011
7012 /**
Hall Liu27d24262020-09-18 19:04:59 -07007013 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007014 */
7015 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007016 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007017 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007018
7019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7020 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7021
Shuo Qian4a594052020-01-23 11:59:30 -08007022 long identity = Binder.clearCallingIdentity();
7023 try {
Hall Liu27d24262020-09-18 19:04:59 -07007024 Phone phone = getPhone(subId);
7025 if (phone == null) {
7026 try {
7027 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7028 } catch (RemoteException e) {
7029 // ignore
7030 }
7031 return;
7032 }
SongFerngWang0e767992021-03-31 22:08:45 +08007033 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7034 PersistableBundle c = configManager.getConfigForSubId(subId);
7035 boolean requireUssd = c.getBoolean(
7036 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007037
Shuo Qian4a594052020-01-23 11:59:30 -08007038 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007039 if (requireUssd) {
7040 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7041 getSubscriptionCarrierId(subId));
7042 String newUssdCommand = "";
7043 try {
7044 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007045 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007046 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7047 } catch (NullPointerException e) {
7048 loge("Failed to generate USSD number" + e);
7049 }
7050 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7051 mMainThreadHandler, callback, carrierXmlParser,
7052 CarrierXmlParser.SsEntry.SSAction.QUERY);
7053 final String ussdCommand = newUssdCommand;
7054 Executors.newSingleThreadExecutor().execute(() -> {
7055 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7056 });
7057 } else {
7058 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7059 callback::accept);
7060 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7061 }
Shuo Qian4a594052020-01-23 11:59:30 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
7065 }
7066
7067 /**
Hall Liu27d24262020-09-18 19:04:59 -07007068 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007069 */
7070 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007071 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007072 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007073
7074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7075 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7076
Shuo Qian4a594052020-01-23 11:59:30 -08007077 long identity = Binder.clearCallingIdentity();
7078 try {
Hall Liu27d24262020-09-18 19:04:59 -07007079 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7080
7081 Phone phone = getPhone(subId);
7082 if (phone == null) {
7083 try {
7084 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7085 } catch (RemoteException e) {
7086 // ignore
7087 }
7088 return;
7089 }
7090
SongFerngWang0e767992021-03-31 22:08:45 +08007091 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7092 PersistableBundle c = configManager.getConfigForSubId(subId);
7093 boolean requireUssd = c.getBoolean(
7094 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007095
SongFerngWang0e767992021-03-31 22:08:45 +08007096 if (DBG) log("getCallWaitingStatus: subId " + subId);
7097 if (requireUssd) {
7098 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7099 getSubscriptionCarrierId(subId));
7100 CarrierXmlParser.SsEntry.SSAction ssAction =
7101 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7102 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7103 String newUssdCommand = "";
7104 try {
7105 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007106 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007107 .makeCommand(ssAction, null);
7108 } catch (NullPointerException e) {
7109 loge("Failed to generate USSD number" + e);
7110 }
7111 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7112 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7113 final String ussdCommand = newUssdCommand;
7114 Executors.newSingleThreadExecutor().execute(() -> {
7115 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7116 });
7117 } else {
7118 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7119 FunctionalUtils.ignoreRemoteException(callback::accept));
7120
7121 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7122 }
Shuo Qian4a594052020-01-23 11:59:30 -08007123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
7126 }
7127
7128 /**
yinxub1bed742017-04-17 11:45:04 -07007129 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007130 *
yinxub1bed742017-04-17 11:45:04 -07007131 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007132 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7133 * location related information which will be sent if the caller already possess
7134 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007135 * @param request contains the radio access networks with bands/channels to scan
7136 * @param messenger callback messenger for scan results or errors
7137 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007138 * @return the id of the requested scan which can be used to stop the scan.
7139 */
7140 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007141 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7142 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007143 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7145 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007146 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007147 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7148 if (!renounceFineLocationAccess) {
7149 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007150 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7151 .setCallingPackage(callingPackage)
7152 .setCallingFeatureId(callingFeatureId)
7153 .setCallingPid(Binder.getCallingPid())
7154 .setCallingUid(Binder.getCallingUid())
7155 .setMethod("requestNetworkScan")
7156 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7158 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7159 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007160 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007162 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7163 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007164 if (e != null) {
7165 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7166 throw e;
7167 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007168 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007169 return TelephonyScanManager.INVALID_SCAN_ID;
7170 }
7171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 }
joonhunshin4ac60942023-11-15 15:23:39 +00007173
7174 enforceTelephonyFeatureWithException(callingPackage,
7175 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7176
Hall Liu912dfd32019-04-25 14:02:26 -07007177 int callingUid = Binder.getCallingUid();
7178 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007182 renounceFineLocationAccess, request, messenger, binder,
7183 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007184 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
yinxu504e1392017-04-12 16:03:22 -07007188 }
7189
Hall Liub2ac8ef2019-02-28 15:56:23 -08007190 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007191 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007192 boolean hasCarrierPriv;
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7196 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Hall Liu558027f2019-05-15 19:14:05 -07007200 boolean hasNetworkScanPermission =
7201 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007202 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007203
7204 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7205 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7206 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007207 }
7208
7209 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7210 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007211 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7212 return new SecurityException("Specific channels must not be"
7213 + " scanned without location access.");
7214 }
7215 }
7216 }
7217
Hall Liub2ac8ef2019-02-28 15:56:23 -08007218 return null;
7219 }
7220
yinxu504e1392017-04-12 16:03:22 -07007221 /**
7222 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007223 *
7224 * @param subId id of the subscription
7225 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007226 */
7227 @Override
7228 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7230 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231
Hall Liu912dfd32019-04-25 14:02:26 -07007232 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007235 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
yinxu504e1392017-04-12 16:03:22 -07007239 }
7240
7241 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007242 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007243 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007244 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007245 */
7246 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007247 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007248 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007249 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007250 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
joonhunshin4ac60942023-11-15 15:23:39 +00007252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7253 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 final long identity = Binder.clearCallingIdentity();
7256 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007257 if (DBG) log("getAllowedNetworkTypesBitmask");
7258 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7259 int networkTypesBitmask = (result != null ? result[0] : -1);
7260 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7261 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007265 }
7266
7267 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007268 * Get the allowed network types for certain reason.
7269 *
7270 * @param subId the id of the subscription.
7271 * @param reason the reason the allowed network type change is taking place
7272 * @return the allowed network types.
7273 */
7274 @Override
7275 public long getAllowedNetworkTypesForReason(int subId,
7276 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007278 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007279
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007280 if (!mApp.getResources().getBoolean(
7281 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7283 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7284 "getAllowedNetworkTypesForReason");
7285 }
joonhunshin4ac60942023-11-15 15:23:39 +00007286
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007287 final long identity = Binder.clearCallingIdentity();
7288 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007289 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007296 * Enable/Disable E-UTRA-NR Dual Connectivity
7297 * @param subId subscription id of the sim card
7298 * @param nrDualConnectivityState expected NR dual connectivity state
7299 * This can be passed following states
7300 * <ol>
7301 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7302 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7303 * <li>Disable NR dual connectivity and force secondary cell to be released
7304 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7305 * </ol>
7306 * @return operation result.
7307 */
7308 @Override
7309 public int setNrDualConnectivityState(int subId,
7310 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7312 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007313 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007314 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7315 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7316 }
7317
Sooraj Sasindran37444802020-08-11 10:40:43 -07007318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7322 nrDualConnectivityState, subId,
7323 workSource);
7324 if (DBG) log("enableNRDualConnectivity result: " + result);
7325 return result;
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
7329 }
7330
7331 /**
7332 * Is E-UTRA-NR Dual Connectivity enabled
7333 * @return true if dual connectivity is enabled else false
7334 */
7335 @Override
7336 public boolean isNrDualConnectivityEnabled(int subId) {
7337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007339 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007340 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007341 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7342 return false;
7343 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7348 null, subId, workSource);
7349 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7350 return isEnabled;
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
7354 }
7355
7356 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007357 * Set the allowed network types of the device and
7358 * provide the reason triggering the allowed network change.
7359 *
7360 * @param subId the id of the subscription.
7361 * @param reason the reason the allowed network type change is taking place
7362 * @param allowedNetworkTypes the allowed network types.
7363 * @return true on success; false on any failure.
7364 */
7365 @Override
7366 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007367 @TelephonyManager.AllowedNetworkTypesReason int reason,
7368 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7370 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007371 // If the caller only has carrier privileges, then they should not be able to override
7372 // any network types which were set for security reasons.
7373 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7374 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007375 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007376 throw new SecurityException(
7377 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007378 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007379 }
joonhunshin4ac60942023-11-15 15:23:39 +00007380
7381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7382 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7383
SongFerngWang3ef3e072020-12-21 16:41:52 +08007384 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007385 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007386 return false;
7387 }
7388 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7389 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007390 return false;
7391 }
7392
Jack Yu5b494332023-01-23 18:18:04 +00007393 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7394 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007395
Jack Yue37dd262022-12-16 11:53:37 -08007396 Phone phone = getPhone(subId);
7397 if (phone == null) {
7398 return false;
7399 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007400
Jack Yue37dd262022-12-16 11:53:37 -08007401 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007402 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007403 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007404 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007405
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007406 final long identity = Binder.clearCallingIdentity();
7407 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007408 Boolean success = (Boolean) sendRequest(
7409 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7410 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7411
7412 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7413 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
7417 }
7418
7419 /**
Miaoa84611c2019-03-15 09:21:10 +08007420 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007421 *
Miaoa84611c2019-03-15 09:21:10 +08007422 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007423 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007424 * @hide
7425 */
7426 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007427 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007428 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007429
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007430 if (!mApp.getResources().getBoolean(
7431 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7433 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7434 }
joonhunshin4ac60942023-11-15 15:23:39 +00007435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007437 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 try {
Miaoa84611c2019-03-15 09:21:10 +08007439 if (phone != null) {
7440 return phone.hasMatchedTetherApnSetting();
7441 } else {
7442 return false;
7443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007446 }
Junda Liu475951f2014-11-07 16:45:03 -08007447 }
7448
7449 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007450 * Get the user enabled state of Mobile Data.
7451 *
7452 * TODO: remove and use isUserDataEnabled.
7453 * This can't be removed now because some vendor codes
7454 * calls through ITelephony directly while they should
7455 * use TelephonyManager.
7456 *
7457 * @return true on enabled
7458 */
7459 @Override
7460 public boolean getDataEnabled(int subId) {
7461 return isUserDataEnabled(subId);
7462 }
7463
7464 /**
7465 * Get whether mobile data is enabled per user setting.
7466 *
7467 * There are other factors deciding whether mobile data is actually enabled, but they are
7468 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007469 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007470 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7471 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007472 *
7473 * @return {@code true} if data is enabled else {@code false}
7474 */
7475 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007476 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007477 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007478 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007479 try {
7480 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7481 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007482 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007483 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7484 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007485 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007487 mApp, subId, functionName);
7488
Robert Greenwalt646120a2014-05-23 11:54:03 -07007489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
Jack Yu285100e2022-12-02 22:48:35 -08007493 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7495 Phone phone = PhoneFactory.getPhone(phoneId);
7496 if (phone != null) {
7497 boolean retVal = phone.isUserDataEnabled();
7498 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7499 return retVal;
7500 } else {
7501 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7502 return false;
7503 }
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007506 }
7507 }
7508
7509 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007510 * Checks if the device is capable of mobile data by considering whether whether the
7511 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7512 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007513 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007514 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007515 */
7516 @Override
7517 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007519 try {
7520 try {
7521 mApp.enforceCallingOrSelfPermission(
7522 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007524 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007525 try {
7526 mApp.enforceCallingOrSelfPermission(
7527 android.Manifest.permission.READ_PHONE_STATE,
7528 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007529 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007530 mApp.enforceCallingOrSelfPermission(
7531 permission.READ_BASIC_PHONE_STATE, functionName);
7532 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007533 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007534 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007535 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537
joonhunshin4ac60942023-11-15 15:23:39 +00007538 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7539 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
7542 try {
Jack Yu285100e2022-12-02 22:48:35 -08007543 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007545 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007546 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007547 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 return retVal;
7549 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007550 if (DBG) {
7551 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7552 + subId + " retVal=false");
7553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 return false;
7555 }
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007558 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007559 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007560
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007561 /**
7562 * Check if data is enabled for a specific reason
7563 * @param subId Subscription index
7564 * @param reason the reason the data enable change is taking place
7565 * @return {@code true} if the overall data is enabled; {@code false} if not.
7566 */
7567 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007568 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007569 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007570 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007571 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007572 try {
7573 mApp.enforceCallingOrSelfPermission(
7574 android.Manifest.permission.ACCESS_NETWORK_STATE,
7575 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007576 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007577 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7578 functionName);
7579 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007580 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007581 try {
7582 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007583 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007584 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007586 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007587 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007588 }
7589
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007590 if (!mApp.getResources().getBoolean(
7591 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7592 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7593 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7594 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
Jack Yu285100e2022-12-02 22:48:35 -08007598 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007599 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007600 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007601 + " reason=" + reason);
7602 }
7603 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007604 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007605 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007606 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007607 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007608 return retVal;
7609 } else {
7610 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007611 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007612 + subId + " retVal=false");
7613 }
7614 return false;
7615 }
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
7620
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007621 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007622 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007623 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7624 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7625
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007626 // No permission needed; this only lets the caller inspect their own status.
7627 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007628 }
Junda Liu29340342014-07-10 15:23:27 -07007629
7630 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007631 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007632 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007633
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007634 if (!mApp.getResources().getBoolean(
7635 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7636 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7637 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7638 "getCarrierPrivilegeStatusForUid");
7639 }
joonhunshin4ac60942023-11-15 15:23:39 +00007640
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007641 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7642 }
7643
7644 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7645 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007646 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007647 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007648 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7649 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007650 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7651 if (cpt == null) {
7652 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7654 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007655 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007656 }
7657
7658 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007659 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007660 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007661
7662 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7663 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7664
chen xuf7e9fe82019-05-09 19:31:02 -07007665 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007666 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007667 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007668 Phone phone = getPhone(subId);
7669 if (phone == null) {
7670 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7671 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7672 }
7673 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7674 if (cpt == null) {
7675 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007676 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7677 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007678 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007679 }
7680
7681 @Override
7682 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007683 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007684
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007685 if (!mApp.getResources().getBoolean(
7686 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7688 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7689 "checkCarrierPrivilegesForPackageAnyPhone");
7690 }
joonhunshin4ac60942023-11-15 15:23:39 +00007691
Rambo Wange7209ce2022-02-23 13:41:02 -08007692 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7693 }
7694
7695 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007696 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007697 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007698 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007699 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007700 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7701 Phone phone = PhoneFactory.getPhone(phoneId);
7702 if (phone == null) {
7703 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007704 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007705 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7706 if (cpt == null) {
7707 continue;
7708 }
7709 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007710 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7711 break;
7712 }
7713 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007714 return result;
Junda Liu29340342014-07-10 15:23:27 -07007715 }
Derek Tan89e89d42014-07-08 17:00:10 -07007716
7717 @Override
Junda Liue64de782015-04-16 17:19:16 -07007718 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007719 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007720
7721 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7722 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7723 "getCarrierPackageNamesForIntentAndPhone");
7724
Rambo Wang8a247eb2022-02-08 21:11:18 +00007725 Phone phone = PhoneFactory.getPhone(phoneId);
7726 if (phone == null) {
7727 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007728 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007729 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7730 if (cpt == null) {
7731 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007732 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007733 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007734 }
7735
Amith Yamasani6e118872016-02-19 12:53:51 -08007736 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007737 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007738 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007739
7740 enforceTelephonyFeatureWithException(
7741 getCurrentPackageName(),
7742 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7743 "getPackagesWithCarrierPrivileges");
7744
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007745 Phone phone = PhoneFactory.getPhone(phoneId);
7746 if (phone == null) {
7747 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007748 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007749 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7750 if (cpt == null) {
7751 return Collections.emptyList();
7752 }
7753 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007754 }
7755
chen xuf7e9fe82019-05-09 19:31:02 -07007756 @Override
7757 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007758 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007759
7760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7761 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7762 "getPackagesWithCarrierPrivilegesForAllPhones");
7763
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007764 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007765 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007766 try {
7767 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7768 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7769 }
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007772 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007773 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007774 }
7775
Rambo Wang6812ffb2022-03-15 16:54:17 -07007776 @Override
7777 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7778 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7779
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007780 if (!mApp.getResources().getBoolean(
7781 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7783 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7784 "getCarrierServicePackageNameForLogicalSlot");
7785 }
joonhunshin4ac60942023-11-15 15:23:39 +00007786
Rambo Wang6812ffb2022-03-15 16:54:17 -07007787 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7788 if (phone == null) {
7789 return null;
7790 }
7791 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7792 if (cpt == null) {
7793 return null;
7794 }
7795 return cpt.getCarrierServicePackageName();
7796 }
7797
Wink Savilleb564aae2014-10-23 10:18:09 -07007798 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007799 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007800 UiccPort port = phone == null ? null : phone.getUiccPort();
7801 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007802 return null;
7803 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007804 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007805 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007806 return null;
7807 }
7808 return iccId;
7809 }
7810
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007811 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007812 public void setCallComposerStatus(int subId, int status) {
7813 enforceModifyPermission();
7814
joonhunshin4ac60942023-11-15 15:23:39 +00007815 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7816 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7817
Shuo Qiane4e11672020-12-15 22:15:33 -08007818 final long identity = Binder.clearCallingIdentity();
7819 try {
7820 Phone phone = getPhone(subId);
7821 if (phone != null) {
7822 Phone defaultPhone = phone.getImsPhone();
7823 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7824 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7825 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007826 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7827 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007828 }
7829 }
Shuo Qian284ae752020-12-22 19:10:14 -08007830 } catch (ImsException e) {
7831 throw new ServiceSpecificException(e.getCode());
7832 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007833 Binder.restoreCallingIdentity(identity);
7834 }
7835 }
7836
7837 @Override
7838 public int getCallComposerStatus(int subId) {
7839 enforceReadPrivilegedPermission("getCallComposerStatus");
7840
joonhunshin4ac60942023-11-15 15:23:39 +00007841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7842 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7843
Shuo Qiane4e11672020-12-15 22:15:33 -08007844 final long identity = Binder.clearCallingIdentity();
7845 try {
7846 Phone phone = getPhone(subId);
7847 if (phone != null) {
7848 Phone defaultPhone = phone.getImsPhone();
7849 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7850 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7851 return imsPhone.getCallComposerStatus();
7852 }
7853 }
7854 } finally {
7855 Binder.restoreCallingIdentity(identity);
7856 }
7857 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7858 }
7859
7860 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007861 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7862 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007863 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007864 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007865
joonhunshin4ac60942023-11-15 15:23:39 +00007866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7867 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7868 "setLine1NumberForDisplayForSubscriber");
7869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 final String iccId = getIccId(subId);
7873 final Phone phone = getPhone(subId);
7874 if (phone == null) {
7875 return false;
7876 }
arunvoddub1365e62024-07-31 09:42:31 +00007877 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7878 Rlog.e(LOG_TAG, "Number is too long");
7879 return false;
7880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881 final String subscriberId = phone.getSubscriberId();
7882
7883 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007884 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 + subscriberId + " to " + number);
7886 }
7887
7888 if (TextUtils.isEmpty(iccId)) {
7889 return false;
7890 }
7891
7892 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7893
7894 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7895 if (alphaTag == null) {
7896 editor.remove(alphaTagPrefKey);
7897 } else {
7898 editor.putString(alphaTagPrefKey, alphaTag);
7899 }
7900
7901 // Record both the line number and IMSI for this ICCID, since we need to
7902 // track all merged IMSIs based on line number
7903 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7904 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7905 if (number == null) {
7906 editor.remove(numberPrefKey);
7907 editor.remove(subscriberPrefKey);
7908 } else {
7909 editor.putString(numberPrefKey, number);
7910 editor.putString(subscriberPrefKey, subscriberId);
7911 }
7912
7913 editor.commit();
7914 return true;
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007917 }
Derek Tan7226c842014-07-02 17:42:23 -07007918 }
7919
7920 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007921 public String getLine1NumberForDisplay(int subId, String callingPackage,
7922 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007923 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007926 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007927 return null;
7928 }
Derek Tan97ebb422014-09-05 16:55:38 -07007929
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007930 if (!mApp.getResources().getBoolean(
7931 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7932 enforceTelephonyFeatureWithException(callingPackage,
7933 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7934 }
joonhunshin4ac60942023-11-15 15:23:39 +00007935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 String iccId = getIccId(subId);
7939 if (iccId != null) {
7940 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7941 if (DBG_MERGE) {
7942 log("getLine1NumberForDisplay returning "
7943 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7944 }
7945 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7948 return null;
7949 } finally {
7950 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007951 }
Derek Tan7226c842014-07-02 17:42:23 -07007952 }
7953
7954 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007955 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7956 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007958 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007959 return null;
7960 }
Derek Tan97ebb422014-09-05 16:55:38 -07007961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 String iccId = getIccId(subId);
7965 if (iccId != null) {
7966 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7967 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7968 }
7969 return null;
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007972 }
Derek Tan7226c842014-07-02 17:42:23 -07007973 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007974
7975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007976 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7977 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007978 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7979 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007981 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007982 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007983 return null;
7984 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007985
Jordan Liub49b04b2019-05-06 14:45:15 -07007986 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7987 // the process, where TelephonyManager was instantiated.
7988 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007989 final long identity = Binder.clearCallingIdentity();
7990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 final TelephonyManager tele = TelephonyManager.from(context);
7993 final SubscriptionManager sub = SubscriptionManager.from(context);
7994
7995 // Figure out what subscribers are currently active
7996 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997
Jordan Liub49b04b2019-05-06 14:45:15 -07007998 // Only consider subs which match the current subId
7999 // This logic can be simplified. See b/131189269 for progress.
8000 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008001 activeSubscriberIds.add(tele.getSubscriberId(subId));
8002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003
8004 // First pass, find a number override for an active subscriber
8005 String mergeNumber = null;
8006 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8007 for (String key : prefs.keySet()) {
8008 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8009 final String subscriberId = (String) prefs.get(key);
8010 if (activeSubscriberIds.contains(subscriberId)) {
8011 final String iccId = key.substring(
8012 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8013 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8014 mergeNumber = (String) prefs.get(numberKey);
8015 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008016 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 + " for active subscriber " + subscriberId);
8018 }
8019 if (!TextUtils.isEmpty(mergeNumber)) {
8020 break;
8021 }
8022 }
8023 }
8024 }
8025
8026 // Shortcut when no active merged subscribers
8027 if (TextUtils.isEmpty(mergeNumber)) {
8028 return null;
8029 }
8030
8031 // Second pass, find all subscribers under that line override
8032 final ArraySet<String> result = new ArraySet<>();
8033 for (String key : prefs.keySet()) {
8034 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8035 final String number = (String) prefs.get(key);
8036 if (mergeNumber.equals(number)) {
8037 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8038 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8039 final String subscriberId = (String) prefs.get(subscriberKey);
8040 if (!TextUtils.isEmpty(subscriberId)) {
8041 result.add(subscriberId);
8042 }
8043 }
8044 }
8045 }
8046
8047 final String[] resultArray = result.toArray(new String[result.size()]);
8048 Arrays.sort(resultArray);
8049 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008050 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8052 }
8053 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008054 } finally {
8055 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008056 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008057 }
8058
8059 @Override
zoey chen38003472019-12-13 17:16:31 +08008060 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8061 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008062
joonhunshin4ac60942023-11-15 15:23:39 +00008063 enforceTelephonyFeatureWithException(callingPackage,
8064 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8065
Malcolm Chen6ca97372019-07-01 16:28:21 -07008066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 final TelephonyManager telephonyManager = mApp.getSystemService(
8069 TelephonyManager.class);
8070 String subscriberId = telephonyManager.getSubscriberId(subId);
8071 if (subscriberId == null) {
8072 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008073 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008074 + subId);
8075 }
8076 return null;
8077 }
8078
Jack Yu3beaf9d2023-04-14 09:17:27 -07008079 final SubscriptionInfo info = getSubscriptionManagerService()
8080 .getSubscriptionInfo(subId);
8081 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008082 // If it doesn't belong to any group, return just subscriberId of itself.
8083 if (groupUuid == null) {
8084 return new String[]{subscriberId};
8085 }
8086
8087 // Get all subscriberIds from the group.
8088 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008089 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8090 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8091 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008092 for (SubscriptionInfo subInfo : groupInfos) {
8093 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8094 if (subscriberId != null) {
8095 mergedSubscriberIds.add(subscriberId);
8096 }
8097 }
8098
8099 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
8102
8103 }
8104 }
8105
8106 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008107 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008108 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008109 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110
joonhunshin4ac60942023-11-15 15:23:39 +00008111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8112 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 final long identity = Binder.clearCallingIdentity();
8115 try {
8116 final Phone phone = getPhone(subId);
8117 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008121 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008122
8123 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008124 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008125 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8126 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008127 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8128 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129
8130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 final Phone phone = getPhone(subId);
8133 if (phone == null) {
8134 return false;
8135 }
8136 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8137 cdmaNonRoamingList);
8138 } finally {
8139 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008140 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008141 }
8142
8143 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008144 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008145 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008146 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008147 if (phone == null) {
8148 return raf;
8149 }
8150
Shuo Qiandee53402020-05-29 14:08:15 -07008151 try {
8152 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008153 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008154 mApp, phone.getSubId(), "getRadioAccessFamily");
8155 } catch (SecurityException e) {
8156 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8157 throw e;
8158 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008159
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008160 if (!mApp.getResources().getBoolean(
8161 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8162 enforceTelephonyFeatureWithException(callingPackage,
8163 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8164 }
joonhunshin4ac60942023-11-15 15:23:39 +00008165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 final long identity = Binder.clearCallingIdentity();
8167 try {
chen xub97461a2018-10-26 14:17:57 -07008168 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
chen xub97461a2018-10-26 14:17:57 -07008172 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008173 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008174
8175 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008176 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008177 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008178 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8179 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008180 enforceTelephonyFeatureWithException(callingPackage,
8181 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8182
Hall Liu82694d52020-12-11 18:22:04 -08008183 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008184 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008185 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8186 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008187 if (!dialerRoleHolders.contains(callingPackage)) {
8188 throw new SecurityException("App must be the dialer role holder to"
8189 + " upload a call composer pic");
8190 }
8191
8192 Executors.newSingleThreadExecutor().execute(() -> {
8193 ByteArrayOutputStream output = new ByteArrayOutputStream(
8194 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8195 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8196 boolean readUntilEnd = false;
8197 int totalBytesRead = 0;
8198 byte[] buffer = new byte[16 * 1024];
8199 while (true) {
8200 int numRead;
8201 try {
8202 numRead = input.read(buffer);
8203 } catch (IOException e) {
8204 try {
8205 fd.checkError();
8206 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8207 null);
8208 } catch (IOException e1) {
8209 // This means that the other side closed explicitly with an error. If this
8210 // happens, log and ignore.
8211 loge("Remote end of call composer picture pipe closed: " + e1);
8212 }
8213 break;
8214 }
8215 if (numRead == -1) {
8216 readUntilEnd = true;
8217 break;
8218 }
8219 totalBytesRead += numRead;
8220 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8221 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8222 try {
8223 input.close();
8224 } catch (IOException e) {
8225 // ignore
8226 }
8227 break;
8228 }
8229 output.write(buffer, 0, numRead);
8230 }
8231 // Generally, the remote end will close the file descriptors. The only case where we
8232 // close is above, where the picture size is too big.
8233
8234 try {
8235 fd.checkError();
8236 } catch (IOException e) {
8237 loge("Remote end for call composer closed with an error: " + e);
8238 return;
8239 }
8240
Hall Liuaa4211e2021-01-20 15:43:39 -08008241 if (!readUntilEnd) {
8242 loge("Did not finish reading entire image; aborting");
8243 return;
8244 }
Hall Liu82694d52020-12-11 18:22:04 -08008245
Hall Liuaa4211e2021-01-20 15:43:39 -08008246 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8247 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8248 new CallComposerPictureTransfer.Factory() {},
8249 imageData,
8250 (result) -> {
8251 if (result.first != null) {
8252 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8253 Bundle outputResult = new Bundle();
8254 outputResult.putParcelable(
8255 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8256 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8257 outputResult);
8258 } else {
8259 callback.send(result.second, null);
8260 }
8261 }
8262 );
Hall Liu82694d52020-12-11 18:22:04 -08008263 });
8264 }
8265
8266 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008267 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008268 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
joonhunshin4ac60942023-11-15 15:23:39 +00008271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8272 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 final long identity = Binder.clearCallingIdentity();
8275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008276 ImsManager.getInstance(defaultPhone.getContext(),
8277 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008281 }
8282
8283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008284 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008285 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8287 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008288 return false;
8289 }
Svet Ganovb320e182015-04-16 12:30:10 -07008290
joonhunshin4ac60942023-11-15 15:23:39 +00008291 enforceTelephonyFeatureWithException(callingPackage,
8292 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 // Check the user preference and the system-level IMS setting. Even if the user has
8297 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8298 // In the long run, we may instead need to check if there exists a connection service
8299 // which can support video calling.
8300 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 return imsManager.isVtEnabledByPlatform()
8303 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8304 && imsManager.isVtEnabledByUser();
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
8307 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008308 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008309
Andrew Leea1239f22015-03-02 17:44:07 -08008310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008311 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8312 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008314 mApp, subId, callingPackage, callingFeatureId,
8315 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 return false;
8317 }
8318
joonhunshin4ac60942023-11-15 15:23:39 +00008319 enforceTelephonyFeatureWithException(callingPackage,
8320 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 final long identity = Binder.clearCallingIdentity();
8323 try {
8324 CarrierConfigManager configManager =
8325 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008326 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
Andrew Leea1239f22015-03-02 17:44:07 -08008331 }
8332
8333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008334 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008336 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 return false;
8338 }
8339
joonhunshin4ac60942023-11-15 15:23:39 +00008340 enforceTelephonyFeatureWithException(callingPackage,
8341 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 final long identity = Binder.clearCallingIdentity();
8344 try {
8345 CarrierConfigManager configManager =
8346 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008347 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
Andrew Leea1239f22015-03-02 17:44:07 -08008352 }
8353
Andrew Lee9431b832015-03-09 18:46:45 -07008354 @Override
8355 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008356 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008357 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008358 }
8359
8360 @Override
8361 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8363 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 final long identity = Binder.clearCallingIdentity();
8366 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008367 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
Andrew Lee9431b832015-03-09 18:46:45 -07008371 }
8372
Hall Liuf6668912018-10-31 17:05:23 -07008373 /**
8374 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8375 * support for the feature and device firmware support.
8376 *
8377 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8378 */
8379 @Override
8380 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8382 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008384 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 final Phone phone = getPhone(subscriptionId);
8386 if (phone == null) {
8387 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8388 return false;
8389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008391 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008393 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8394 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8395 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 return isCarrierSupported && isDeviceSupported;
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
Hall Liu98187582018-01-22 19:15:32 -08008400 }
8401
Hall Liuf6668912018-10-31 17:05:23 -07008402 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008403 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8404 * RTT setting, will return true if the device and carrier both support RTT.
8405 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008406 */
8407 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408 final long identity = Binder.clearCallingIdentity();
8409 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008410 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8411 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8412 return false;
8413 }
8414 }
8415
Hall Liu5bab75c2019-12-11 23:58:20 +00008416 boolean isRttSupported = isRttSupported(subscriptionId);
8417 boolean isUserRttSettingOn = Settings.Secure.getInt(
8418 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8419 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8420 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8421 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008425 }
8426
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008427 @Deprecated
8428 @Override
8429 public String getDeviceId(String callingPackage) {
8430 return getDeviceIdWithFeature(callingPackage, null);
8431 }
8432
Sanket Padawe7310cc72015-01-14 09:53:20 -08008433 /**
8434 * Returns the unique device ID of phone, for example, the IMEI for
8435 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8436 *
8437 * <p>Requires Permission:
8438 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8439 */
8440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008441 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008442 try {
8443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8444 } catch (SecurityException se) {
8445 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8446 throw new SecurityException("Package " + callingPackage + " does not belong to "
8447 + Binder.getCallingUid());
8448 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008449 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008450 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008451 return null;
8452 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008453 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008454 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008455 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008456 return null;
8457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458
8459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 return phone.getDeviceId();
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008465 }
8466
Ping Sunc67b7c22016-03-02 19:16:45 +08008467 /**
8468 * {@hide}
8469 * Returns the IMS Registration Status on a particular subid
8470 *
8471 * @param subId
8472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008473 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008474 Phone phone = getPhone(subId);
8475 if (phone != null) {
8476 return phone.isImsRegistered();
8477 } else {
8478 return false;
8479 }
8480 }
8481
Santos Cordon7a1885b2015-02-03 11:15:19 -08008482 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008483 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008484 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008486 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008487 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8488 }
8489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
8494 }
8495 }
8496
8497 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008498 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008499 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008500 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008501 mApp,
8502 subscriptionId,
8503 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8504 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008505
8506 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8507 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8508
Tyler Gunnf70ed162019-04-03 15:28:53 -07008509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 Phone phone = getPhone(subscriptionId);
8512 if (phone == null) {
8513 return null;
8514 }
8515 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008521 /**
8522 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008523 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008524 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 Phone phone = getPhone(subId);
8528 if (phone != null) {
8529 return phone.isWifiCallingEnabled();
8530 } else {
8531 return false;
8532 }
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008535 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008536 }
8537
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008538 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008540 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008541 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 Phone phone = getPhone(subId);
8545 if (phone != null) {
8546 return phone.isVideoEnabled();
8547 } else {
8548 return false;
8549 }
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008552 }
8553 }
8554
8555 /**
8556 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8557 * defined in {@link ImsRegistrationImplBase}.
8558 */
8559 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008560 final long identity = Binder.clearCallingIdentity();
8561 try {
8562 Phone phone = getPhone(subId);
8563 if (phone != null) {
8564 return phone.getImsRegistrationTech();
8565 } else {
8566 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8567 }
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008570 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008571 }
8572
Stuart Scott8eef64f2015-04-08 15:13:54 -07008573 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008574 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008575 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008576
8577 enforceTelephonyFeatureWithException(callingPackage,
8578 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8579
Stuart Scott981d8582015-04-21 14:09:50 -07008580 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8581 return;
8582 }
Kai Shif70f46f2021-03-03 13:59:46 -08008583 Phone defaultPhone = getDefaultPhone();
8584 if (defaultPhone != null) {
8585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8586 mApp, getDefaultPhone().getSubId(), "factoryReset");
8587 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008588 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008589
Svet Ganovcc087f82015-05-12 20:35:54 -07008590 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008591 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8592 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008593 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008594 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008595 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008596 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008597 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008598 setDataRoamingEnabled(subId, phone == null ? false
8599 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008600 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008601 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008602 // There has been issues when Sms raw table somehow stores orphan
8603 // fragments. They lead to garbled message when new fragments come
8604 // in and combined with those stale ones. In case this happens again,
8605 // user can reset all network settings which will clean up this table.
8606 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008607 // Clean up IMS settings as well here.
8608 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008609 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008610 ImsManager.getInstance(mApp, slotId).factoryReset();
8611 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008612
Kai Shif70f46f2021-03-03 13:59:46 -08008613 if (defaultPhone == null) {
8614 return;
8615 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008616 // Erase modem config if erase modem on network setting is enabled.
8617 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8618 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8619 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008620 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008621 }
Kai Shif70f46f2021-03-03 13:59:46 -08008622
8623 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008624 } finally {
8625 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008626 }
8627 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008628
SongFerngWangfd89b102021-05-27 22:44:54 +08008629 @VisibleForTesting
8630 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8631 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8632 return;
8633 }
8634 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8635 RILConstants.PREFERRED_NETWORK_MODE);
8636 SubscriptionManager.setSubscriptionProperty(subId,
8637 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8638 "user=" + defaultNetworkType);
8639 phone.loadAllowedNetworksFromSubscriptionDatabase();
8640 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8641 defaultNetworkType, null);
8642 }
8643
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008644 private void cleanUpSmsRawTable(Context context) {
8645 ContentResolver resolver = context.getContentResolver();
8646 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8647 resolver.delete(uri, null, null);
8648 }
8649
Narayan Kamath1c496c22015-04-16 14:40:19 +01008650 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008651 public String getSimLocaleForSubscriber(int subId) {
8652 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008653
8654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8655 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8656
chen xu5d3637b2019-01-21 23:31:38 -08008657 final Phone phone = getPhone(subId);
8658 if (phone == null) {
8659 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008660 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008662 final long identity = Binder.clearCallingIdentity();
8663 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008664 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8665 phone.getContext().getOpPackageName(),
8666 phone.getContext().getAttributionTag());
8667 if (info == null) {
8668 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8669 return null;
chen xu6291c472019-02-04 12:55:53 -08008670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 // Try and fetch the locale from the carrier properties or from the SIM language
8672 // preferences (EF-PL and EF-LI)...
8673 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008674 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008675 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8676 if (localeFromDefaultSim != null) {
8677 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8678 if (DBG) log("Using locale from subId: " + subId + " locale: "
8679 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008680 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008681 } else {
8682 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 }
8684 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008686 // The SIM language preferences only store a language (e.g. fr = French), not an
8687 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8688 // the SIM and carrier preferences does not include a country we add the country
8689 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008690 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008692 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008693 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008694 }
8695
8696 if (DBG) log("No locale found - returning null");
8697 return null;
8698 } finally {
8699 Binder.restoreCallingIdentity(identity);
8700 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008701 }
8702
tom hsu0b59d292022-09-29 23:49:21 +08008703 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008704 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008705 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008706 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008707 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008708 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8709 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008710 Locale.forLanguageTag(localeTag).getCountry())) {
8711 return localeTag;
8712 }
8713 }
8714 return inputLocale.toLanguageTag();
8715 }
8716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008717 /**
8718 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8719 */
8720 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008721 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008722 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008723 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008724
Gary Jian3aa9a762022-01-24 16:41:19 +08008725 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8726 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008727
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008728 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008729 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8730 * representing the state of the modem.
8731 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008732 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8733 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008734 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008735 */
8736 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008737 public void requestModemActivityInfo(ResultReceiver result) {
8738 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008739
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008740 if (!mApp.getResources().getBoolean(
8741 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8743 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8744 }
joonhunshin4ac60942023-11-15 15:23:39 +00008745
vagdeviaf9a5b92018-08-15 16:01:53 -07008746 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747
8748 final long identity = Binder.clearCallingIdentity();
8749 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008750 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008751 } finally {
8752 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008753 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008754 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008755
Gary Jian76280a42022-12-07 16:18:33 +08008756 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008757 // less than total activity duration.
8758 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8759 if (info == null) {
8760 return false;
8761 }
8762 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008763 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008764 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8765
Hall Liu49656c02020-10-09 19:00:11 -07008766 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8767
Siddharth Rayb8114062018-06-17 15:02:38 -07008768 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008769 && (info.getSleepTimeMillis() <= activityDurationMs)
8770 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008771 }
8772
Gary Jian3aa9a762022-01-24 16:41:19 +08008773 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8774 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8775 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8776 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8777
8778 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8779 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8780 }
8781
8782 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8783 mLastModemActivityInfo.setReceiveTimeMillis(
8784 rat,
8785 freq,
8786 info.getReceiveTimeMillis(rat, freq)
8787 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8788 }
8789
8790 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8791 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8792 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8793 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8794
8795 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8796 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8797 }
8798 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8799 mLastModemActivityInfo.setReceiveTimeMillis(
8800 rat,
8801 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8802 }
8803
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008804 /**
8805 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8806 * @param info recent ModemActivityInfo
8807 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008808 private void mergeModemActivityInfo(ModemActivityInfo info) {
8809 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008810 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008811 boolean matched;
8812 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8813 matched = false;
8814 int rat = info.getSpecificInfoRat(i);
8815 int freq = info.getSpecificInfoFrequencyRange(i);
8816 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8817 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8818 //if it already exists
8819 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8820 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8821 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8822 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8823 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8824 updateLastModemActivityInfo(info, rat, freq);
8825 matched = true;
8826 }
8827 } else {
8828 updateLastModemActivityInfo(info, rat);
8829 matched = true;
8830 }
8831 }
8832 }
8833
8834 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008835 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008836 new ActivityStatsTechSpecificInfo(
8837 rat,
8838 freq,
8839 info.getTransmitTimeMillis(rat, freq),
8840 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008841 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008842 }
8843 }
8844 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8845 mLastModemActivitySpecificInfo =
8846 new ActivityStatsTechSpecificInfo[merged.size()];
8847 merged.toArray(mLastModemActivitySpecificInfo);
8848
8849 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8850 mLastModemActivityInfo.setSleepTimeMillis(
8851 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008852 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008853 mLastModemActivityInfo.setIdleTimeMillis(
8854 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008855 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008856
8857 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008858 new ModemActivityInfo(
8859 mLastModemActivityInfo.getTimestampMillis(),
8860 mLastModemActivityInfo.getSleepTimeMillis(),
8861 mLastModemActivityInfo.getIdleTimeMillis(),
8862 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008863 }
8864
8865 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8866 ActivityStatsTechSpecificInfo[] info) {
8867 int infoSize = info.length;
8868 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8869 for (int i = 0; i < infoSize; i++) {
8870 ret[i] = new ActivityStatsTechSpecificInfo(
8871 info[i].getRat(), info[i].getFrequencyRange(),
8872 info[i].getTransmitTimeMillis(),
8873 (int) info[i].getReceiveTimeMillis());
8874 }
8875 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008876 }
8877
Jack Yu85bd38a2015-11-09 11:34:32 -08008878 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008879 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008880 */
8881 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008882 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8883 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8884 Phone phone = PhoneFactory.getPhone(slotIndex);
8885 if (phone == null) {
8886 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8887 return null;
8888 }
8889
8890 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008892 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008893 return null;
8894 }
8895
joonhunshin4ac60942023-11-15 15:23:39 +00008896 enforceTelephonyFeatureWithException(callingPackage,
8897 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8898
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008899 boolean hasFinePermission = false;
8900 boolean hasCoarsePermission = false;
8901 if (!renounceFineLocationAccess) {
8902 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8903 LocationAccessPolicy.checkLocationPermission(mApp,
8904 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8905 .setCallingPackage(callingPackage)
8906 .setCallingFeatureId(callingFeatureId)
8907 .setCallingPid(Binder.getCallingPid())
8908 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008909 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008910 .setLogAsInfo(true)
8911 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8912 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8913 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8914 .build());
8915 hasFinePermission =
8916 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8917 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008918
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008919 if (!renounceCoarseLocationAccess) {
8920 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8921 LocationAccessPolicy.checkLocationPermission(mApp,
8922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8923 .setCallingPackage(callingPackage)
8924 .setCallingFeatureId(callingFeatureId)
8925 .setCallingPid(Binder.getCallingPid())
8926 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008927 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008928 .setLogAsInfo(true)
8929 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8930 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8931 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8932 .build());
8933 hasCoarsePermission =
8934 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8935 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008936
Jordan Liu0f2bc442020-11-18 16:47:37 -08008937 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008939 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8940 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008941 if (subInfo != null && !subInfo.isActive()) {
8942 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008943 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008944 }
8945
Hall Liuf19c44f2018-11-27 14:38:17 -08008946 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008947 boolean isCallingPackageDataService = phone.getDataServicePackages()
8948 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008949
8950 // Scrub out the location info in ServiceState depending on what level of access
8951 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008952 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008953 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8954 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008959
8960 /**
8961 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8962 *
8963 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8964 * voicemail ringtone.
8965 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8966 * PhoneAccount.
8967 */
8968 @Override
8969 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8971 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008977 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008984 }
8985
8986 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008987 * Sets the per-account voicemail ringtone.
8988 *
8989 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8990 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8991 *
8992 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8993 * voicemail ringtone.
8994 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8995 * PhoneAccount.
8996 */
8997 @Override
8998 public void setVoicemailRingtoneUri(String callingPackage,
8999 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009000 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009002 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9003 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9005 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9006 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009008
joonhunshin4ac60942023-11-15 15:23:39 +00009009 enforceTelephonyFeatureWithException(callingPackage,
9010 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012 final long identity = Binder.clearCallingIdentity();
9013 try {
9014 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9015 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009016 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009017 }
9018 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009021 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009022 }
9023
9024 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009025 * Returns whether vibration is set for voicemail notification in Phone settings.
9026 *
9027 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9028 * voicemail vibration setting.
9029 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9030 */
9031 @Override
9032 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009033 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9034 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9039 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009040 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009047 }
9048
Youhan Wange64578a2016-05-02 15:32:42 -07009049 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009050 * Sets the per-account voicemail vibration.
9051 *
9052 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9053 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9054 *
9055 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9056 * voicemail vibration setting.
9057 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9058 * specific PhoneAccount.
9059 */
9060 @Override
9061 public void setVoicemailVibrationEnabled(String callingPackage,
9062 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009063 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009065 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9066 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9068 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9069 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009070 }
9071
joonhunshin4ac60942023-11-15 15:23:39 +00009072 enforceTelephonyFeatureWithException(callingPackage,
9073 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 final long identity = Binder.clearCallingIdentity();
9076 try {
9077 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9078 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009079 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009080 }
9081 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009084 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009085 }
9086
9087 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009088 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9089 *
9090 * @throws SecurityException if the caller does not have the required permission
9091 */
arunvoddud7401012022-12-15 16:08:12 +00009092 @VisibleForTesting
9093 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009095 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009096 }
9097
9098 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009099 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9100 * permission.
9101 *
9102 * @throws SecurityException if the caller does not have the required permission
9103 */
9104 private void enforceSendSmsPermission() {
9105 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9106 }
9107
9108 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009109 * Make sure either called from same process as self (phone) or IPC caller has interact across
9110 * users permission.
9111 *
9112 * @throws SecurityException if the caller does not have the required permission
9113 */
9114 private void enforceInteractAcrossUsersPermission(String message) {
9115 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9116 }
9117
9118 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009119 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009120 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009121 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009122 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009123 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009127 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009128 if (componentName == null) {
9129 throw new SecurityException(
9130 "Caller not current active visual voicemail package[null]");
9131 }
9132 String vvmPackage = componentName.getPackageName();
9133 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009134 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135 }
9136 } finally {
9137 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009138 }
9139 }
9140
9141 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009142 * Return the application ID for the app type.
9143 *
9144 * @param subId the subscription ID that this request applies to.
9145 * @param appType the uicc app type.
9146 * @return Application ID for specificied app type, or null if no uicc.
9147 */
9148 @Override
9149 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009150 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009151
9152 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9153 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9154
Youhan Wange64578a2016-05-02 15:32:42 -07009155 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156
9157 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009158 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009159 if (phone == null) {
9160 return null;
9161 }
9162 String aid = null;
9163 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009164 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165 .getApplicationByType(appType).getAid();
9166 } catch (Exception e) {
9167 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9168 }
9169 return aid;
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009172 }
Youhan Wange64578a2016-05-02 15:32:42 -07009173 }
9174
Youhan Wang4001d252016-05-11 10:29:41 -07009175 /**
9176 * Return the Electronic Serial Number.
9177 *
9178 * @param subId the subscription ID that this request applies to.
9179 * @return ESN or null if error.
9180 */
9181 @Override
9182 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009183 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009184 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185
9186 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009187 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188 if (phone == null) {
9189 return null;
9190 }
9191 String esn = null;
9192 try {
9193 esn = phone.getEsn();
9194 } catch (Exception e) {
9195 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9196 }
9197 return esn;
9198 } finally {
9199 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009200 }
Youhan Wang4001d252016-05-11 10:29:41 -07009201 }
9202
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009203 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009204 * Return the Preferred Roaming List Version.
9205 *
9206 * @param subId the subscription ID that this request applies to.
9207 * @return PRLVersion or null if error.
9208 */
9209 @Override
9210 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009211 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009212
9213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9214 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9215
Youhan Wang66ad5d72016-07-18 17:56:58 -07009216 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009217
9218 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009219 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009220 if (phone == null) {
9221 return null;
9222 }
9223 String cdmaPrlVersion = null;
9224 try {
9225 cdmaPrlVersion = phone.getCdmaPrlVersion();
9226 } catch (Exception e) {
9227 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9228 }
9229 return cdmaPrlVersion;
9230 } finally {
9231 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009232 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009233 }
9234
9235 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009236 * Get snapshot of Telephony histograms
9237 * @return List of Telephony histograms
9238 * @hide
9239 */
9240 @Override
9241 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9243 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 return RIL.getTelephonyRILTimingHistograms();
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009252
9253 /**
9254 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009255 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9256 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009257 * Require system privileges. In the future we may add this to carrier APIs.
9258 *
Michele Berionne482f8202018-11-27 18:57:59 -08009259 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009260 */
9261 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009262 @TelephonyManager.SetCarrierRestrictionResult
9263 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009264 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009265
9266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9267 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9268
vagdeviaf9a5b92018-08-15 16:01:53 -07009269 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009270
Michele Berionne482f8202018-11-27 18:57:59 -08009271 if (carrierRestrictionRules == null) {
9272 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009273 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009275 final long identity = Binder.clearCallingIdentity();
9276 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009277 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009278 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009282 }
9283
9284 /**
9285 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009286 * Get the allowed carrier list and the excluded carrier list, including the priority between
9287 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009288 * Require system privileges. In the future we may add this to carrier APIs.
9289 *
Michele Berionne482f8202018-11-27 18:57:59 -08009290 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009291 */
9292 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009293 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009294 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009295
9296 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9297 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9298
vagdeviaf9a5b92018-08-15 16:01:53 -07009299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009303 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9304 if (response instanceof CarrierRestrictionRules) {
9305 return (CarrierRestrictionRules) response;
9306 }
9307 // Response is an Exception of some kind,
9308 // which is signalled to the user as a NULL retval
9309 return null;
9310 } catch (Exception e) {
9311 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9312 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313 } finally {
9314 Binder.restoreCallingIdentity(identity);
9315 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009316 }
9317
fionaxu59545b42016-05-25 15:53:37 -07009318 /**
arunvoddud7401012022-12-15 16:08:12 +00009319 * Fetches the carrier restriction status of the device and sends the status to the caller
9320 * through the callback.
9321 *
9322 * @param callback The callback that will be used to send the result.
9323 * @throws SecurityException if the caller does not have the required permission/privileges or
9324 * the caller is not allowlisted.
9325 */
9326 @Override
9327 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009328 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009329 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009330 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9331 try {
9332 mApp.enforceCallingOrSelfPermission(
9333 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9334 functionName);
9335 } catch (SecurityException e) {
9336 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9337 functionName);
9338 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009339 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9340 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009341 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9342 throw new SecurityException("Not an authorized caller");
9343 }
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
9346 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009347 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009348 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
arunvoddu567f2b42023-04-25 17:22:00 +00009354 @Override
9355 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9356 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9357 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9358 return allowListInfo.getShaIdList(pkgName, carrierId);
9359 }
9360
arunvoddud7401012022-12-15 16:08:12 +00009361 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009362 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009363 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009364 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009365 }
9366
9367 /**
fionaxu59545b42016-05-25 15:53:37 -07009368 * Action set from carrier signalling broadcast receivers to enable/disable radio
9369 * @param subId the subscription ID that this action applies to.
9370 * @param enabled control enable or disable radio.
9371 * {@hide}
9372 */
9373 @Override
9374 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9375 enforceModifyPermission();
9376 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009377
9378 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009379 if (phone == null) {
9380 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9381 return;
9382 }
9383 try {
9384 phone.carrierActionSetRadioEnabled(enabled);
9385 } catch (Exception e) {
9386 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009387 } finally {
9388 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009389 }
9390 }
9391
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009392 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009393 * Enable or disable Voice over NR (VoNR)
9394 * @param subId the subscription ID that this action applies to.
9395 * @param enabled enable or disable VoNR.
9396 * @return operation result.
9397 */
9398 @Override
9399 public int setVoNrEnabled(int subId, boolean enabled) {
9400 enforceModifyPermission();
9401 final Phone phone = getPhone(subId);
9402
9403 final long identity = Binder.clearCallingIdentity();
9404 if (phone == null) {
9405 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9406 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9407 }
9408
9409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9410 try {
9411 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9412 workSource);
9413 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009414
9415 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9416 if (DBG) {
9417 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9418 }
9419 SubscriptionManager.setSubscriptionProperty(
9420 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9421 (enabled ? "1" : "0"));
9422 }
9423
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009424 return result;
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
9430 /**
9431 * Is voice over NR enabled
9432 * @return true if VoNR is enabled else false
9433 */
9434 @Override
9435 public boolean isVoNrEnabled(int subId) {
9436 enforceReadPrivilegedPermission("isVoNrEnabled");
9437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9438 final long identity = Binder.clearCallingIdentity();
9439 try {
9440 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9441 null, subId, workSource);
9442 if (DBG) log("isVoNrEnabled: " + isEnabled);
9443 return isEnabled;
9444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
9447 }
9448
9449 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009450 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9451 * network status based on which carrier apps could apply actions accordingly,
9452 * enable/disable default url handler for example.
9453 *
9454 * @param subId the subscription ID that this action applies to.
9455 * @param report control start/stop reporting the default network status.
9456 * {@hide}
9457 */
9458 @Override
9459 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9460 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009461
9462 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9463 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9464 "carrierActionReportDefaultNetworkStatus");
9465
fionaxu8da9cb12017-05-23 15:02:46 -07009466 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009467
9468 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009469 if (phone == null) {
9470 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9471 return;
9472 }
9473 try {
9474 phone.carrierActionReportDefaultNetworkStatus(report);
9475 } catch (Exception e) {
9476 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009477 } finally {
9478 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009479 }
9480 }
9481
9482 /**
fionaxud9622282017-07-17 17:51:30 -07009483 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9484 * @param subId the subscription ID that this action applies to.
9485 * {@hide}
9486 */
9487 @Override
9488 public void carrierActionResetAll(int subId) {
9489 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009490
9491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9492 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9493
fionaxud9622282017-07-17 17:51:30 -07009494 final Phone phone = getPhone(subId);
9495 if (phone == null) {
9496 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9497 return;
9498 }
9499 try {
9500 phone.carrierActionResetAll();
9501 } catch (Exception e) {
9502 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9503 }
9504 }
9505
9506 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009507 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9508 * bug report is being generated.
9509 */
9510 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009511 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009512 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9513 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009514 writer.println("Permission Denial: can't dump Phone from pid="
9515 + Binder.getCallingPid()
9516 + ", uid=" + Binder.getCallingUid()
9517 + "without permission "
9518 + android.Manifest.permission.DUMP);
9519 return;
9520 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009521 try {
9522 DumpsysHandler.dump(mApp, fd, writer, args);
9523 } catch (Exception e) {
9524 writer.println("Failed to dump phone information: " + e);
9525 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009526 }
Jack Yueb89b242016-06-22 13:27:47 -07009527
Brad Ebingerdac2f002018-04-03 15:17:52 -07009528 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009529 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9530 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9531 @NonNull String[] args) {
9532 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9533 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009534 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009535 }
9536
Jack Yueb89b242016-06-22 13:27:47 -07009537 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009538 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009539 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009540 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009541 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009542 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009543 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009544 */
9545 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009546 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009547 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009548 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9549 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9550 try {
9551 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009552 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009553 } catch (SecurityException se) {
9554 enforceModifyPermission();
9555 }
9556 } else {
9557 enforceModifyPermission();
9558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009559
joonhunshin4ac60942023-11-15 15:23:39 +00009560 enforceTelephonyFeatureWithException(callingPackage,
9561 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9562
Nate Myren116695d2024-02-09 09:36:01 -08009563 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009564 final long identity = Binder.clearCallingIdentity();
9565 try {
Nate Myren116695d2024-02-09 09:36:01 -08009566 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9567 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009568 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009569 callingUid, callingPackage, null, null);
9570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009571 Phone phone = getPhone(subId);
9572 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009573 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9574 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009575 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009576 phone.getDataSettingsManager().setDataEnabled(
9577 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009579 }
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009582 }
9583 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009584
9585 /**
9586 * Get Client request stats
9587 * @return List of Client Request Stats
9588 * @hide
9589 */
9590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009591 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9592 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009594 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009595 return null;
9596 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009597 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 if (phone != null) {
9602 return phone.getClientRequestStats();
9603 }
9604
9605 return null;
9606 } finally {
9607 Binder.restoreCallingIdentity(identity);
9608 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009609 }
9610
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009611 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009612 PackageManager pm;
9613 if (mFeatureFlags.hsumPackageManager()) {
9614 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9615 .getPackageManager();
9616 } else {
9617 pm = mApp.getPackageManager();
9618 }
9619
9620 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009621 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009622 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9623 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9624 // exception. ROOT_UID seems not to have a valid package name returned by
9625 // PackageManager, so just fake it here to avoid issues when running telephony shell
9626 // commands that plumb through the RIL as root, like so:
9627 // $ adb root
9628 // $ adb shell cmd phone ...
9629 packageName = "root";
9630 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009631 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009632 }
Jack Yueb4124c2017-02-16 15:32:43 -08009633
9634 /**
Grace Chen70990072017-03-24 17:21:30 -07009635 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009636 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009637 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009638 * @param state State of SIM (power down, power up, pass through)
9639 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9640 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9641 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009642 *
9643 **/
9644 @Override
Grace Chen70990072017-03-24 17:21:30 -07009645 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009646 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009647
9648 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9649 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9650
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009651 Phone phone = PhoneFactory.getPhone(slotIndex);
9652
vagdeviaf9a5b92018-08-15 16:01:53 -07009653 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009655 final long identity = Binder.clearCallingIdentity();
9656 try {
9657 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009658 phone.setSimPowerState(state, null, workSource);
9659 }
9660 } finally {
9661 Binder.restoreCallingIdentity(identity);
9662 }
9663 }
9664
9665 /**
9666 * Set SIM card power state.
9667 *
9668 * @param slotIndex SIM slot id.
9669 * @param state State of SIM (power down, power up, pass through)
9670 * @param callback callback to trigger after success or failure
9671 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9672 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9674 *
9675 **/
9676 @Override
9677 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9678 IIntegerConsumer callback) {
9679 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009680
9681 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9682 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9683 "setSimPowerStateForSlotWithCallback");
9684
Jordan Liu109698e2020-11-24 14:50:34 -08009685 Phone phone = PhoneFactory.getPhone(slotIndex);
9686
9687 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9688
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
9691 if (phone != null) {
9692 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9693 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009694 }
9695 } finally {
9696 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009697 }
9698 }
Shuo Qiandd210312017-04-12 22:11:33 +00009699
Tyler Gunn65d45c22017-06-05 11:22:26 -07009700 private boolean isUssdApiAllowed(int subId) {
9701 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009702 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009703 if (configManager == null) {
9704 return false;
9705 }
9706 PersistableBundle pb = configManager.getConfigForSubId(subId);
9707 if (pb == null) {
9708 return false;
9709 }
9710 return pb.getBoolean(
9711 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9712 }
9713
Shuo Qiandd210312017-04-12 22:11:33 +00009714 /**
Ling Mac28f0212023-03-24 16:07:15 -07009715 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009716 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009717 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009718 */
goneil9c5f4872017-12-05 14:07:56 -08009719 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009720 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009721 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009722
9723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9724 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009726 final long identity = Binder.clearCallingIdentity();
9727 try {
Ling Mac28f0212023-03-24 16:07:15 -07009728 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009729 } finally {
9730 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009731 }
9732 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009733
9734 /**
9735 * Get the current signal strength information for the given subscription.
9736 * Because this information is not updated when the device is in a low power state
9737 * it should not be relied-upon to be current.
9738 * @param subId Subscription index
9739 * @return the most recent cached signal strength info from the modem
9740 */
9741 @Override
9742 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9744 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009746 final long identity = Binder.clearCallingIdentity();
9747 try {
9748 Phone p = getPhone(subId);
9749 if (p == null) {
9750 return null;
9751 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009753 return p.getSignalStrength();
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009757 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009758
Pengquan Meng77b7f132018-08-22 14:49:57 -07009759 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009760 * Get the current modem radio state for the given slot.
9761 * @param slotIndex slot index.
9762 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009763 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009764 * @return the current radio power state from the modem
9765 */
9766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009767 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009768 Phone phone = PhoneFactory.getPhone(slotIndex);
9769 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9771 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009772 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9773 }
9774
joonhunshin4ac60942023-11-15 15:23:39 +00009775 enforceTelephonyFeatureWithException(callingPackage,
9776 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9777
Chen Xuf792fd62018-10-17 17:54:36 +00009778 final long identity = Binder.clearCallingIdentity();
9779 try {
9780 return phone.getRadioPowerState();
9781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
9785 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9786 }
9787
9788 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009789 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9790 *
9791 * <p>Requires one of the following permissions:
9792 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009793 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009794 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9795 * privileges.
9796 *
9797 * @param subId subscription id
9798 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9799 * {@code false}.
9800 */
9801 @Override
9802 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009803 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009804 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009805 try {
9806 mApp.enforceCallingOrSelfPermission(
9807 android.Manifest.permission.ACCESS_NETWORK_STATE,
9808 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009809 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009810 mApp.enforceCallingOrSelfPermission(
9811 permission.READ_BASIC_PHONE_STATE, functionName);
9812 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009813 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009814 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009815 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009816 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009817
joonhunshin4ac60942023-11-15 15:23:39 +00009818 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9819 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9820
Pengquan Menga1bb6272018-09-06 09:59:22 -07009821 boolean isEnabled = false;
9822 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009823 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009824 Phone phone = getPhone(subId);
9825 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009826 } finally {
9827 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009828 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009829 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009830 }
9831
9832
9833 /**
9834 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9835 *
9836 * <p> Requires permission:
9837 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9838 * privileges.
9839 *
9840 * @param subId subscription id
9841 * @param isEnabled {@code true} means enable, {@code false} means disable.
9842 */
9843 @Override
9844 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9846 mApp, subId, "setDataRoamingEnabled");
9847
joonhunshin4ac60942023-11-15 15:23:39 +00009848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9849 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9850
Pengquan Menga1bb6272018-09-06 09:59:22 -07009851 final long identity = Binder.clearCallingIdentity();
9852 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009853 Phone phone = getPhone(subId);
9854 if (phone != null) {
9855 phone.setDataRoamingEnabled(isEnabled);
9856 }
9857 } finally {
9858 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009859 }
9860 }
9861
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009862 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009863 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009864 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009865 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009866 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009867
joonhunshin4ac60942023-11-15 15:23:39 +00009868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9869 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9870
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009871 boolean isAllowed = true;
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009874 Phone phone = getPhone(subId);
9875 if (phone != null) {
9876 isAllowed = phone.isCspPlmnEnabled();
9877 }
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 return isAllowed;
9882 }
9883
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009884 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9885 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009886 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009887 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009888 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009889 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9890 if (phone == null) {
9891 return false;
9892 }
9893 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9894 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9895 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009896 }
9897
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009898 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009899 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009900 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009901 mApp.getSystemService(AppOpsManager.class)
9902 .checkPackage(Binder.getCallingUid(), callingPackage);
9903
Jordan Liu1e142fc2019-04-22 15:10:43 -07009904 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009905 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009906 try {
9907 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009908 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009909 } catch (SecurityException e) {
9910 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9911 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009912 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009913 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009914 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009915 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009916 }
joonhunshin4ac60942023-11-15 15:23:39 +00009917
9918 enforceTelephonyFeatureWithException(callingPackage,
9919 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9920
sandeepjsb6c87872021-09-27 15:34:44 +00009921 // checking compatibility, if calling app's target SDK is T and beyond.
9922 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9923 Binder.getCallingUid())) {
9924 isIccIdAccessRestricted = true;
9925 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009926 final long identity = Binder.clearCallingIdentity();
9927 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009928 UiccController uiccController = UiccController.getInstance();
9929 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009930 if (hasReadPermission) {
9931 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009932 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009933
9934 // Remove private info if the caller doesn't have access
9935 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9936 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009937 //setting the value after compatibility check
9938 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009939 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9940 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009941 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009942 if (card == null) {
9943 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009944 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009945 continue;
9946 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009947 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9948 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009949 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009950 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009951 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009952 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9953 for (UiccPortInfo portInfo : portInfos) {
9954 UiccPort port = uiccController.getUiccPortForSlot(
9955 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9956 if (port == null) {
9957 // assume no access if port is null
9958 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9959 continue;
9960 }
9961 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9962 uiccPortInfos.add(portInfo);
9963 } else {
9964 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9965 }
9966 }
9967 filteredInfos.add(new UiccCardInfo(
9968 cardInfo.isEuicc(),
9969 cardInfo.getCardId(),
9970 null,
9971 cardInfo.getPhysicalSlotIndex(),
9972 cardInfo.isRemovable(),
9973 cardInfo.isMultipleEnabledProfilesSupported(),
9974 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009975 }
9976 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
9981
sandeepjsb6c87872021-09-27 15:34:44 +00009982 /**
9983 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9984 * generally private and require carrier privileges to view.
9985 *
9986 * @hide
9987 */
9988 @NonNull
9989 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9990 List<UiccPortInfo> portinfo = new ArrayList<>();
9991 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9992 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9993 }
9994 return new UiccCardInfo(
9995 cardInfo.isEuicc(),
9996 cardInfo.getCardId(),
9997 null,
9998 cardInfo.getPhysicalSlotIndex(),
9999 cardInfo.isRemovable(),
10000 cardInfo.isMultipleEnabledProfilesSupported(),
10001 portinfo
10002 );
10003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010004
sandeepjsb6c87872021-09-27 15:34:44 +000010005 /**
10006 * @hide
10007 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10008 * These values are generally private and require carrier privileges to view.
10009 */
10010 @NonNull
10011 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10012 return new UiccPortInfo(
10013 UiccPortInfo.ICCID_REDACTED,
10014 portInfo.getPortIndex(),
10015 portInfo.getLogicalSlotIndex(),
10016 portInfo.isActive()
10017 );
10018 }
10019 @Override
10020 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010021 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010022 mApp.getSystemService(AppOpsManager.class)
10023 .checkPackage(Binder.getCallingUid(), callingPackage);
10024
sandeepjsb6c87872021-09-27 15:34:44 +000010025 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010026
Aman Guptaf3c90b32022-03-17 04:54:16 +000010027 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10028 // we are reading iccId which is PII data.
10029 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010030
joonhunshin4ac60942023-11-15 15:23:39 +000010031 enforceTelephonyFeatureWithException(callingPackage,
10032 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10033
sandeepjsb6c87872021-09-27 15:34:44 +000010034 // checking compatibility, if calling app's target SDK is T and beyond.
10035 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10036 Binder.getCallingUid())) {
10037 isLogicalSlotAccessRestricted = true;
10038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010039 final long identity = Binder.clearCallingIdentity();
10040 try {
10041 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010042 if (slots == null || slots.length == 0) {
10043 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010044 return null;
10045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010046 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10047 for (int i = 0; i < slots.length; i++) {
10048 UiccSlot slot = slots[i];
10049 if (slot == null) {
10050 continue;
10051 }
10052
Jordan Liu7be7e652019-05-06 18:55:02 +000010053 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010054 UiccCard card = slot.getUiccCard();
10055 if (card != null) {
10056 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010057 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010058 cardId = slot.getEid();
10059 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010060 // If cardId is null, use iccId of default port as cardId.
10061 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010063 }
10064
Jordan Liu857451f2019-05-09 16:35:35 -070010065 if (cardId != null) {
10066 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10067 // if cardId is an EID, it's all digits so this is fine
10068 cardId = IccUtils.stripTrailingFs(cardId);
10069 }
10070
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010071 int cardState = 0;
10072 switch (slot.getCardState()) {
10073 case CARDSTATE_ABSENT:
10074 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10075 break;
10076 case CARDSTATE_PRESENT:
10077 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10078 break;
10079 case CARDSTATE_ERROR:
10080 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10081 break;
10082 case CARDSTATE_RESTRICTED:
10083 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10084 break;
10085 default:
10086 break;
10087
10088 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010089 List<UiccPortInfo> portInfos = new ArrayList<>();
10090 int[] portIndexes = slot.getPortList();
10091 for (int portIdx : portIndexes) {
10092 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010093 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010094 portInfos.add(new UiccPortInfo(iccId, portIdx,
10095 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010097 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010098 slot.isEuicc(),
10099 cardId,
10100 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010101 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010102 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010103 //setting the value after compatibility check
10104 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010105 }
10106 return infos;
10107 } finally {
10108 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010109 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010110 }
10111
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010112 /* Returns null if doesn't have read permission or carrier privilege access. */
10113 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10114 boolean hasReadPermission) {
10115 String iccId = slot.getIccId(portIndex);
10116 if (hasReadPermission) { // if has read permission
10117 return iccId;
10118 } else {
10119 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10120 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10121 // if no read permission, checking carrier privilege access
10122 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10123 return iccId;
10124 }
10125 }
10126 }
10127 // No read permission or carrier privilege access.
10128 return UiccPortInfo.ICCID_REDACTED;
10129 }
10130
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010131 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010132 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010133 public boolean switchSlots(int[] physicalSlots) {
10134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010135
joonhunshin4ac60942023-11-15 15:23:39 +000010136 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10137 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10138
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010139 final long identity = Binder.clearCallingIdentity();
10140 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010141 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10142 for (int i = 0; i < physicalSlots.length; i++) {
10143 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10144 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10145 physicalSlots[i], i));
10146 }
10147 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010148 } finally {
10149 Binder.restoreCallingIdentity(identity);
10150 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010151 }
Jack Yu4c988042018-02-27 15:30:01 -080010152
10153 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010154 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10155 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10156 enforceModifyPermission();
10157
joonhunshin4ac60942023-11-15 15:23:39 +000010158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10159 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10160
sandeepjsb6c87872021-09-27 15:34:44 +000010161 final long identity = Binder.clearCallingIdentity();
10162 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010163 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
10169 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010170 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010171 enforceTelephonyFeatureWithException(callingPackage,
10172 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10173
Jordan Liu7de49fa2018-12-06 14:48:49 -080010174 final long identity = Binder.clearCallingIdentity();
10175 try {
10176 return UiccController.getInstance().getCardIdForDefaultEuicc();
10177 } finally {
10178 Binder.restoreCallingIdentity(identity);
10179 }
10180 }
10181
Pengquan Meng85728fb2018-03-12 16:31:21 -070010182 /**
goneil47ffb6e2018-04-06 15:40:58 -070010183 * A test API to reload the UICC profile.
10184 *
10185 * <p>Requires that the calling app has permission
10186 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10187 * @hide
10188 */
10189 @Override
10190 public void refreshUiccProfile(int subId) {
10191 enforceModifyPermission();
10192
10193 final long identity = Binder.clearCallingIdentity();
10194 try {
10195 Phone phone = getPhone(subId);
10196 if (phone == null) {
10197 return;
10198 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010199 UiccPort uiccPort = phone.getUiccPort();
10200 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010201 return;
10202 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010203 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010204 if (uiccProfile == null) {
10205 return;
10206 }
10207 uiccProfile.refresh();
10208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
10212
10213 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010214 * Returns false if the mobile data is disabled by default, otherwise return true.
10215 */
10216 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010217 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010218 }
10219
10220 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010221 * Returns the default network type for the given {@code subId}, if the default network type is
10222 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10223 */
10224 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010225 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010226 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010227 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10228 return list.get(phoneId);
10229 }
10230 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010231 }
fionaxua13278b2018-03-21 00:08:13 -070010232
10233 @Override
10234 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010235 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010237
10238 final long identity = Binder.clearCallingIdentity();
10239 try {
10240 final Phone phone = getPhone(subId);
10241 if (phone == null) {
10242 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10243 return;
10244 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010245 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10246 if (cpt != null) {
10247 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10248 }
10249 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010250 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10251 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010252 if (carrierPrivilegeRules == null) {
10253 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10254 } else {
10255 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010257 } finally {
10258 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010259 }
fionaxua13278b2018-03-21 00:08:13 -070010260 }
10261
10262 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010263 public void setCarrierServicePackageOverride(
10264 int subId, String carrierServicePackage, String callingPackage) {
10265 TelephonyPermissions.enforceShellOnly(
10266 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10267
Benedict Wong66477622023-02-03 23:30:57 +000010268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 final Phone phone = getPhone(subId);
10271 if (phone == null || phone.getSubId() != subId) {
10272 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10273 throw new IllegalArgumentException("No phone for subid");
10274 }
10275 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10276 if (cpt == null) {
10277 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10278 throw new IllegalStateException("No CPT for phone");
10279 }
10280 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10281 } finally {
10282 Binder.restoreCallingIdentity(identity);
10283 }
10284 }
10285
10286 @Override
fionaxua13278b2018-03-21 00:08:13 -070010287 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010288 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010289
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
10292 final Phone phone = getPhone(subId);
10293 if (phone == null) {
10294 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10295 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10296 }
10297 return phone.getCarrierIdListVersion();
10298 } finally {
10299 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010300 }
fionaxua13278b2018-03-21 00:08:13 -070010301 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010302
10303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010304 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10305 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010307 mApp, subId, callingPackage, callingFeatureId,
10308 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010309 return -1;
10310 }
10311
10312 final long identity = Binder.clearCallingIdentity();
10313 try {
10314 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10315 } finally {
10316 Binder.restoreCallingIdentity(identity);
10317 }
10318 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010319
10320 @Override
10321 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010322 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010323 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010324 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010325
joonhunshin4ac60942023-11-15 15:23:39 +000010326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10327 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10328
Pengquan Menga1bb6272018-09-06 09:59:22 -070010329 final long identity = Binder.clearCallingIdentity();
10330 try {
10331 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 @Override
10338 public boolean setCdmaRoamingMode(int subId, int mode) {
10339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10340 mApp, subId, "setCdmaRoamingMode");
10341
joonhunshin4ac60942023-11-15 15:23:39 +000010342 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10343 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10344
Pengquan Menga1bb6272018-09-06 09:59:22 -070010345 final long identity = Binder.clearCallingIdentity();
10346 try {
10347 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351 }
10352
10353 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010354 public int getCdmaSubscriptionMode(int subId) {
10355 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010356 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010357 mApp, subId, "getCdmaSubscriptionMode");
10358
joonhunshin4ac60942023-11-15 15:23:39 +000010359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10360 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10361
Sarah Chinbaab1432020-10-28 13:46:24 -070010362 final long identity = Binder.clearCallingIdentity();
10363 try {
10364 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368 }
10369
10370 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010371 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10373 mApp, subId, "setCdmaSubscriptionMode");
10374
joonhunshin4ac60942023-11-15 15:23:39 +000010375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10376 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10377
Pengquan Menga1bb6272018-09-06 09:59:22 -070010378 final long identity = Binder.clearCallingIdentity();
10379 try {
10380 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10381 } finally {
10382 Binder.restoreCallingIdentity(identity);
10383 }
10384 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010385
sqianc5eccab2018-10-19 18:46:41 -070010386 @Override
sqian8c685422019-02-22 15:55:18 -080010387 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010388 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010390 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10391 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010392 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10393 }
joonhunshin4ac60942023-11-15 15:23:39 +000010394
10395 enforceTelephonyFeatureWithException(callingPackage,
10396 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10397
sqian11b7a0e2018-12-05 18:48:28 -080010398 final long identity = Binder.clearCallingIdentity();
10399 try {
sqian854d44b2018-12-12 16:48:18 -080010400 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10401 for (Phone phone: PhoneFactory.getPhones()) {
10402 if (phone.getEmergencyNumberTracker() != null
10403 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10404 emergencyNumberListInternal.put(
10405 phone.getSubId(),
10406 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10407 }
sqian11b7a0e2018-12-05 18:48:28 -080010408 }
sqian854d44b2018-12-12 16:48:18 -080010409 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
sqianc5eccab2018-10-19 18:46:41 -070010413 }
10414
10415 @Override
sqian8c685422019-02-22 15:55:18 -080010416 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010417 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010418 if (!exactMatch) {
10419 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010420 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010421 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010422 }
joonhunshin4ac60942023-11-15 15:23:39 +000010423
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010424 if (!mApp.getResources().getBoolean(
10425 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10427 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10428 }
joonhunshin4ac60942023-11-15 15:23:39 +000010429
sqian11b7a0e2018-12-05 18:48:28 -080010430 final long identity = Binder.clearCallingIdentity();
10431 try {
sqian854d44b2018-12-12 16:48:18 -080010432 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010433 //Note: we ignore passed in param exactMatch. We can remove it once
10434 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010435 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010436 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010437 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010438 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010439 }
sqian11b7a0e2018-12-05 18:48:28 -080010440 }
10441 return false;
10442 } finally {
10443 Binder.restoreCallingIdentity(identity);
10444 }
10445 }
10446
sqianf4ca7ed2019-01-15 18:32:07 -080010447 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010448 * Start emergency callback mode for GsmCdmaPhone for testing.
10449 */
10450 @Override
10451 public void startEmergencyCallbackMode() {
10452 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10453 "startEmergencyCallbackMode");
10454 enforceModifyPermission();
10455 final long identity = Binder.clearCallingIdentity();
10456 try {
10457 for (Phone phone : PhoneFactory.getPhones()) {
10458 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10459 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10460 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10461 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10462 gsmCdmaPhone.obtainMessage(
10463 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10464 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10465 }
10466 }
10467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
10471
10472 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010473 * Update emergency number list for test mode.
10474 */
10475 @Override
10476 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10477 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10478 "updateEmergencyNumberListTestMode");
10479
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
10482 for (Phone phone: PhoneFactory.getPhones()) {
10483 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10484 if (tracker != null) {
10485 tracker.executeEmergencyNumberTestModeCommand(action, num);
10486 }
10487 }
10488 } finally {
10489 Binder.restoreCallingIdentity(identity);
10490 }
10491 }
10492
10493 /**
10494 * Get the full emergency number list for test mode.
10495 */
10496 @Override
10497 public List<String> getEmergencyNumberListTestMode() {
10498 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10499 "getEmergencyNumberListTestMode");
10500
10501 final long identity = Binder.clearCallingIdentity();
10502 try {
10503 Set<String> emergencyNumbers = new HashSet<>();
10504 for (Phone phone: PhoneFactory.getPhones()) {
10505 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10506 if (tracker != null) {
10507 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10508 emergencyNumbers.add(num.getNumber());
10509 }
10510 }
10511 }
10512 return new ArrayList<>(emergencyNumbers);
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 }
10517
chen xud6b45bd2018-10-30 22:27:10 -070010518 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010519 public int getEmergencyNumberDbVersion(int subId) {
10520 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10521
joonhunshin4ac60942023-11-15 15:23:39 +000010522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10523 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10524
Shuo Qian3b6ee772019-11-13 17:43:31 -080010525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 final Phone phone = getPhone(subId);
10528 if (phone == null) {
10529 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10530 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10531 }
10532 return phone.getEmergencyNumberDbVersion();
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
10537
10538 @Override
10539 public void notifyOtaEmergencyNumberDbInstalled() {
10540 enforceModifyPermission();
10541
joonhunshin4ac60942023-11-15 15:23:39 +000010542 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10543 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10544
Shuo Qian3b6ee772019-11-13 17:43:31 -080010545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 for (Phone phone: PhoneFactory.getPhones()) {
10548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10549 if (tracker != null) {
10550 tracker.updateOtaEmergencyNumberDatabase();
10551 }
10552 }
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
10558 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010559 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010560 enforceActiveEmergencySessionPermission();
10561
joonhunshin4ac60942023-11-15 15:23:39 +000010562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10563 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10564
Shuo Qian3b6ee772019-11-13 17:43:31 -080010565 final long identity = Binder.clearCallingIdentity();
10566 try {
10567 for (Phone phone: PhoneFactory.getPhones()) {
10568 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10569 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010570 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10571 }
10572 }
10573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 }
10577
10578 @Override
10579 public void resetOtaEmergencyNumberDbFilePath() {
10580 enforceActiveEmergencySessionPermission();
10581
joonhunshin4ac60942023-11-15 15:23:39 +000010582 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10583 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10584
Shuo Qianc373f112020-03-05 17:55:34 -080010585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 for (Phone phone: PhoneFactory.getPhones()) {
10588 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10589 if (tracker != null) {
10590 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010591 }
10592 }
10593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
10597
10598 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010599 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10600 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10601 Phone phone = getPhone(subId);
10602 if (phone == null) {
10603 return null;
10604 }
10605 final long identity = Binder.clearCallingIdentity();
10606 try {
10607 UiccProfile profile = UiccController.getInstance()
10608 .getUiccProfileForPhone(phone.getPhoneId());
10609 if (profile != null) {
10610 return profile.getCertsFromCarrierPrivilegeAccessRules();
10611 }
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 return null;
10616 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010617
10618 /**
10619 * Enable or disable a modem stack.
10620 */
10621 @Override
10622 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10623 enforceModifyPermission();
10624
joonhunshin4ac60942023-11-15 15:23:39 +000010625 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10626 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10627
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 Phone phone = PhoneFactory.getPhone(slotIndex);
10631 if (phone == null) {
10632 return false;
10633 } else {
10634 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10635 }
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
Michelecea4cf22018-12-21 15:00:11 -080010640
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010641 /**
10642 * Whether a modem stack is enabled or not.
10643 */
10644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010645 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10646 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010647 Phone phone = PhoneFactory.getPhone(slotIndex);
10648 if (phone == null) return false;
10649
10650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010651 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10652 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010653 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10654 }
10655
joonhunshin4ac60942023-11-15 15:23:39 +000010656 enforceTelephonyFeatureWithException(callingPackage,
10657 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10658
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010659 final long identity = Binder.clearCallingIdentity();
10660 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010661 try {
10662 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10663 } catch (NoSuchElementException ex) {
10664 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10665 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010666 } finally {
10667 Binder.restoreCallingIdentity(identity);
10668 }
10669 }
10670
Michelecea4cf22018-12-21 15:00:11 -080010671 @Override
Michele0ea7d782019-03-19 14:58:42 -070010672 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010673 enforceModifyPermission();
10674
joonhunshin4ac60942023-11-15 15:23:39 +000010675 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10676 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10677
Michelecea4cf22018-12-21 15:00:11 -080010678 final long identity = Binder.clearCallingIdentity();
10679 try {
10680 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010681 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010682 .commit();
10683 } finally {
10684 Binder.restoreCallingIdentity(identity);
10685 }
10686 }
10687
10688 @Override
Michele0ea7d782019-03-19 14:58:42 -070010689 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010690 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010692 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10693 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010694 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010695 }
Michelecea4cf22018-12-21 15:00:11 -080010696
joonhunshin4ac60942023-11-15 15:23:39 +000010697 enforceTelephonyFeatureWithException(callingPackage,
10698 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10699
Michelecea4cf22018-12-21 15:00:11 -080010700 final long identity = Binder.clearCallingIdentity();
10701 try {
Michele0ea7d782019-03-19 14:58:42 -070010702 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010703 } finally {
10704 Binder.restoreCallingIdentity(identity);
10705 }
10706 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010707
Michele0ea7d782019-03-19 14:58:42 -070010708 @TelephonyManager.IsMultiSimSupportedResult
10709 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010710 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10711 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10712 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010713 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10714 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010715 }
10716 // Check if the hardware supports multisim functionality. If usage of multisim is not
10717 // supported by the modem, indicate that it is restricted.
10718 PhoneCapability staticCapability =
10719 mPhoneConfigurationManager.getStaticPhoneCapability();
10720 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010721 loge("isMultiSimSupportedInternal: no static configuration available");
10722 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010723 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010724 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010725 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10726 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010727 }
10728 // Check if support of multiple SIMs is restricted by carrier
10729 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010730 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010731 }
10732
Michele0ea7d782019-03-19 14:58:42 -070010733 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010734 }
10735
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010736 /**
10737 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010738 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10739 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10740 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010741 * @param numOfSims number of active sims we want to switch to
10742 */
10743 @Override
10744 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010745 if (numOfSims == 1) {
10746 enforceModifyPermission();
10747 } else {
10748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10749 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10750 }
joonhunshin4ac60942023-11-15 15:23:39 +000010751
10752 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10753 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10754
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010755 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010756
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010757 try {
Michele30b57b22019-03-01 12:01:14 -080010758 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010759 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010760 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10761 return;
10762 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010763 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10764 } finally {
10765 Binder.restoreCallingIdentity(identity);
10766 }
10767 }
10768
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010769 @Override
10770 public boolean isApplicationOnUicc(int subId, int appType) {
10771 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010772
10773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10774 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10775
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010776 Phone phone = getPhone(subId);
10777 if (phone == null) {
10778 return false;
10779 }
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010782 UiccPort uiccPort = phone.getUiccPort();
10783 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010784 return false;
10785 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010786 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010787 if (uiccProfile == null) {
10788 return false;
10789 }
10790 if (TelephonyManager.APPTYPE_SIM <= appType
10791 && appType <= TelephonyManager.APPTYPE_ISIM) {
10792 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10793 }
10794 return false;
10795 } finally {
10796 Binder.restoreCallingIdentity(identity);
10797 }
10798 }
10799
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010800 /**
chen xub4baa772019-04-03 10:23:41 -070010801 * Get whether making changes to modem configurations will trigger reboot.
10802 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010803 */
10804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010805 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10806 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010808 mApp, subId, callingPackage, callingFeatureId,
10809 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010810 return false;
10811 }
joonhunshin4ac60942023-11-15 15:23:39 +000010812
10813 enforceTelephonyFeatureWithException(callingPackage,
10814 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10815 "doesSwitchMultiSimConfigTriggerReboot");
10816
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010817 final long identity = Binder.clearCallingIdentity();
10818 try {
10819 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
Nathan Harold29f5f052019-02-15 13:41:57 -080010825 private void updateModemStateMetrics() {
10826 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10827 // TODO: check the state for each modem if the api is ready.
10828 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10829 }
10830
Pengquan Meng3889a572019-01-23 11:16:29 -080010831 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010832 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010833 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010834 // Verify that the callingPackage belongs to the calling UID
10835 mApp.getSystemService(AppOpsManager.class)
10836 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010837
10838 enforceTelephonyFeatureWithException(callingPackage,
10839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10840
Pengquan Meng3889a572019-01-23 11:16:29 -080010841 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010842 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010843 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010844 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10845 if (slotInfos != null) {
10846 for (int i = 0; i < slotInfos.length; i++) {
10847 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10848 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10849 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10850 portInfo.getLogicalSlotIndex()));
10851 }
10852 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010853 }
10854 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010855 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010860
10861 /**
10862 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010863 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010864 */
jimsunf9ec1622022-09-13 21:18:43 +080010865 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010866 @Override
10867 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010868 return getHalVersion(HAL_SERVICE_RADIO);
10869 }
10870
10871 /**
10872 * Get the HAL Version of a specific service
10873 */
10874 @Override
10875 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010876 Phone phone = getDefaultPhone();
10877 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010878 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010879 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10880 return hv.major * 100 + hv.minor;
10881 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010882
10883 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010884 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010885 *
10886 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010887 */
10888 @Override
sangyun097dcf72024-01-04 10:35:49 +090010889 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010890 if (mFeatureFlags.hsumPackageManager()) {
10891 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10892 Binder.getCallingUserHandle(), 0).getPackageManager();
10893 if (pm == null) return null;
10894 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10895 return (callingUids == null) ? null : callingUids[0];
10896 }
10897 if (mPackageManager == null) return null;
10898 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10899 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010900 }
10901
10902 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010903 * @return The calling package name or "phone" if the caller is the phone process. This is done
10904 * because multiple Phone has multiple packages in it and the first element in the array is not
10905 * actually always the caller.
10906 * Note: This is for logging purposes only and should not be used for security checks.
10907 */
10908 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010909 PackageManager pm;
10910 if (mFeatureFlags.hsumPackageManager()) {
10911 pm = mApp.getBaseContext().createContextAsUser(
10912 Binder.getCallingUserHandle(), 0).getPackageManager();
10913 } else {
10914 pm = mApp.getPackageManager();
10915 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010916 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10917 if (uidName != null && !uidName.isEmpty()) return uidName;
10918 return getCurrentPackageName();
10919 }
10920
10921 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010922 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10923 * corresponding network requests on a subId.
10924 *
10925 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010926 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010927 * 2) APN is un-metered for this subscription, or
10928 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010929 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010930 *
10931 * @return whether data is allowed for a apn type.
10932 *
10933 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010934 */
10935 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010936 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010937 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10938 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010939
joonhunshin4ac60942023-11-15 15:23:39 +000010940 enforceTelephonyFeatureWithException(callingPackage,
10941 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10942
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010943 // Now that all security checks passes, perform the operation as ourselves.
10944 final long identity = Binder.clearCallingIdentity();
10945 try {
10946 Phone phone = getPhone(subId);
10947 if (phone == null) return false;
10948
Jack Yu27422a52022-03-21 10:38:05 -070010949 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010950 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010951 isMetered = phone.getDataNetworkController().getDataConfigManager()
10952 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10953 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010954 isDataEnabled = (phone.getDataSettingsManager() != null)
10955 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010956 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
10961
10962 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010963 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010964 enforceReadPrivilegedPermission("isApnMetered");
10965
joonhunshin4ac60942023-11-15 15:23:39 +000010966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10967 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10968
Malcolm Chene5ad5792019-04-18 13:51:02 -070010969 // Now that all security checks passes, perform the operation as ourselves.
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 Phone phone = getPhone(subId);
10973 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010974 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10975 DataUtils.apnTypeToNetworkCapability(apnType),
10976 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010977 } finally {
10978 Binder.restoreCallingIdentity(identity);
10979 }
10980 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010981
10982 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010983 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10984 int subscriptionId, IBooleanConsumer resultCallback) {
10985 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010986
10987 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10988 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10989
Hall Liu73f5d362020-01-20 13:42:00 -080010990 long token = Binder.clearCallingIdentity();
10991 try {
10992 Phone phone = getPhone(subscriptionId);
10993 if (phone == null) {
10994 try {
10995 if (resultCallback != null) {
10996 resultCallback.accept(false);
10997 }
10998 } catch (RemoteException e) {
10999 // ignore
11000 }
11001 return;
11002 }
11003 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11004 Pair.create(specifiers, (x) -> {
11005 try {
11006 if (resultCallback != null) {
11007 resultCallback.accept(x);
11008 }
11009 } catch (RemoteException e) {
11010 // ignore
11011 }
11012 });
11013 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11014 } finally {
11015 Binder.restoreCallingIdentity(token);
11016 }
11017 }
11018
11019 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011020 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11021 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011022 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011023 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011024
11025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11026 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11027
Sarah Chin679c08a2020-11-18 13:39:35 -080011028 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11029 final long identity = Binder.clearCallingIdentity();
11030 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011031 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11032 if (result instanceof IllegalStateException) {
11033 throw (IllegalStateException) result;
11034 }
11035 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011036 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11037 return specifiers;
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
11043 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011044 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011045 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011046
11047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11048 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11049
Jack Yu8b766fc2022-03-21 09:42:33 -070011050 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011051 }
11052
11053 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011054 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11055 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011056 if (callingPackage == null) {
11057 callingPackage = getCurrentPackageName();
11058 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011059 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11060 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011061 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11062 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011063 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11064 }
11065 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11066 Intent intent = new Intent();
11067 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11068 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11069 // Bring up choose default SMS subscription dialog right now
11070 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11071 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011072 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011073 }
chen xud5ca2d52019-05-28 15:20:57 -070011074
11075 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011076 public void showSwitchToManagedProfileDialog() {
11077 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011078 try {
11079 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11080 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11081 // for work telephony.
11082 Intent intent = new Intent(Intent.ACTION_SENDTO);
11083 intent.setData(Uri.parse("smsto:"));
11084 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011085 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011086 } catch (ActivityNotFoundException e) {
11087 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11088 Intent intent = new Intent();
11089 intent.setClass(mApp, ErrorDialogActivity.class);
11090 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011091 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011092 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011093 }
11094
11095 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011096 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11098 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11099
chen xud5ca2d52019-05-28 15:20:57 -070011100 //TODO investigate if this API should require proper permission check in R b/133791609
11101 final long identity = Binder.clearCallingIdentity();
11102 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011103 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11104 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11105 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11106 return carrierUAProfUrl;
11107 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011108 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11109 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011110 } finally {
11111 Binder.restoreCallingIdentity(identity);
11112 }
11113 }
11114
11115 @Override
11116 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11118 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11119
chen xud5ca2d52019-05-28 15:20:57 -070011120 //TODO investigate if this API should require proper permission check in R b/133791609
11121 final long identity = Binder.clearCallingIdentity();
11122 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011123 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11124 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11125 if (!TextUtils.isEmpty(carrierUserAgent)) {
11126 return carrierUserAgent;
11127 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011128 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11129 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
Jack Yub07d4972019-05-28 16:12:25 -070011134
11135 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011136 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11137 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011138
joonhunshin4ac60942023-11-15 15:23:39 +000011139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11140 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11141
Jack Yub07d4972019-05-28 16:12:25 -070011142 final long identity = Binder.clearCallingIdentity();
11143 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011144 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011145 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011146
Ling Maf188d502022-09-16 15:22:36 -070011147 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011148 } finally {
11149 Binder.restoreCallingIdentity(identity);
11150 }
11151 }
11152
11153 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011154 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011155 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011156 enforceModifyPermission();
11157
joonhunshin4ac60942023-11-15 15:23:39 +000011158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11159 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11160
changbettyd5c246e2019-12-24 15:40:37 +080011161 final long identity = Binder.clearCallingIdentity();
11162 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011163 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011164 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011165
Ling Maf188d502022-09-16 15:22:36 -070011166 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011167 } finally {
11168 Binder.restoreCallingIdentity(identity);
11169 }
11170 }
11171
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011172 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011173 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011174 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11175 * otherwise.
11176 */
11177 @Override
11178 public void setCepEnabled(boolean isCepEnabled) {
11179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11180
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
11183 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11184 for (Phone phone : PhoneFactory.getPhones()) {
11185 Phone defaultPhone = phone.getImsPhone();
11186 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11187 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11188 ImsPhoneCallTracker imsPhoneCallTracker =
11189 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11190 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11191 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11192 + imsPhone.getMsisdn());
11193 }
11194 }
11195 } finally {
11196 Binder.restoreCallingIdentity(identity);
11197 }
11198 }
allenwtsu46dcc572020-01-08 18:24:03 +080011199
11200 /**
11201 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11202 *
11203 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11204 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11205 * before being read.
11206 */
11207 @Override
11208 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11209 isCompressed) {
11210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11211 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11213 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11214 }
joonhunshin4ac60942023-11-15 15:23:39 +000011215
11216 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11217 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11218 Binder.getCallingUserHandle())) {
11219 if (!isImsAvailableOnDevice()) {
11220 // ProvisioningManager can not handle ServiceSpecificException.
11221 // Throw the IllegalStateException and annotate ProvisioningManager.
11222 throw new IllegalStateException("IMS not available on device.");
11223 }
11224 } else {
11225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11226 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11227 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011228 }
11229
11230 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011231 try {
Hui Wang761a6682020-10-31 05:12:53 +000011232 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11233 } finally {
11234 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011235 }
11236 }
zoey chene02881a2019-12-30 16:11:23 +080011237
11238 @Override
11239 public boolean isIccLockEnabled(int subId) {
11240 enforceReadPrivilegedPermission("isIccLockEnabled");
11241
joonhunshin4ac60942023-11-15 15:23:39 +000011242 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11243 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11244
zoey chene02881a2019-12-30 16:11:23 +080011245 // Now that all security checks passes, perform the operation as ourselves.
11246 final long identity = Binder.clearCallingIdentity();
11247 try {
11248 Phone phone = getPhone(subId);
11249 if (phone != null && phone.getIccCard() != null) {
11250 return phone.getIccCard().getIccLockEnabled();
11251 } else {
11252 return false;
11253 }
11254 } finally {
11255 Binder.restoreCallingIdentity(identity);
11256 }
11257 }
11258
11259 /**
11260 * Set the ICC pin lock enabled or disabled.
11261 *
11262 * @return an integer representing the status of IccLock enabled or disabled in the following
11263 * three cases:
11264 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11265 * successfully.
11266 * - Positive number and zero for remaining password attempts.
11267 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11268 *
11269 */
11270 @Override
11271 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11272 enforceModifyPermission();
11273
joonhunshin4ac60942023-11-15 15:23:39 +000011274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11275 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11276
zoey chene02881a2019-12-30 16:11:23 +080011277 Phone phone = getPhone(subId);
11278 if (phone == null) {
11279 return 0;
11280 }
11281 // Now that all security checks passes, perform the operation as ourselves.
11282 final long identity = Binder.clearCallingIdentity();
11283 try {
11284 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11285 new Pair<Boolean, String>(enabled, password), phone, null);
11286 return attemptsRemaining;
11287
11288 } catch (Exception e) {
11289 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 return 0;
11294 }
11295
11296 /**
11297 * Change the ICC password used in ICC pin lock.
11298 *
11299 * @return an integer representing the status of IccLock changed in the following three cases:
11300 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11301 * - Positive number and zero for remaining password attempts.
11302 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11303 *
11304 */
11305 @Override
11306 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11307 enforceModifyPermission();
11308
joonhunshin4ac60942023-11-15 15:23:39 +000011309 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11310 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11311
zoey chene02881a2019-12-30 16:11:23 +080011312 Phone phone = getPhone(subId);
11313 if (phone == null) {
11314 return 0;
11315 }
11316 // Now that all security checks passes, perform the operation as ourselves.
11317 final long identity = Binder.clearCallingIdentity();
11318 try {
11319 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11320 new Pair<String, String>(oldPassword, newPassword), phone, null);
11321 return attemptsRemaining;
11322
11323 } catch (Exception e) {
11324 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11325 } finally {
11326 Binder.restoreCallingIdentity(identity);
11327 }
11328 return 0;
11329 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011330
11331 /**
11332 * Request for receiving user activity notification
11333 */
11334 @Override
11335 public void requestUserActivityNotification() {
11336 if (!mNotifyUserActivity.get()
11337 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11338 mNotifyUserActivity.set(true);
11339 }
11340 }
11341
11342 /**
11343 * Called when userActivity is signalled in the power manager.
11344 * This is safe to call from any thread, with any window manager locks held or not.
11345 */
11346 @Override
11347 public void userActivity() {
11348 // ***************************************
11349 // * Inherited from PhoneWindowManager *
11350 // ***************************************
11351 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11352 // WITH ITS LOCKS HELD.
11353 //
11354 // This code must be VERY careful about the locks
11355 // it acquires.
11356 // In fact, the current code acquires way too many,
11357 // and probably has lurking deadlocks.
11358
Jack Yu86374492024-09-16 13:05:44 -070011359 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011360 throw new SecurityException("Only the OS may call notifyUserActivity()");
11361 }
11362
11363 if (mNotifyUserActivity.getAndSet(false)) {
11364 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11365 USER_ACTIVITY_NOTIFICATION_DELAY);
11366 }
11367 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011368
11369 @Override
11370 public boolean canConnectTo5GInDsdsMode() {
11371 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11372 }
Jack Yud10cdd42020-09-28 20:28:01 -070011373
11374 @Override
11375 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11376 String callingFeatureId) {
11377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11378 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11379 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11380 }
11381
joonhunshin4ac60942023-11-15 15:23:39 +000011382 enforceTelephonyFeatureWithException(callingPackage,
11383 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11384
Jack Yud10cdd42020-09-28 20:28:01 -070011385 Phone phone = getPhone(subId);
11386 if (phone == null) {
11387 throw new RuntimeException("phone is not available");
11388 }
11389 // Now that all security checks passes, perform the operation as ourselves.
11390 final long identity = Binder.clearCallingIdentity();
11391 try {
11392 return phone.getEquivalentHomePlmns();
11393 } finally {
11394 Binder.restoreCallingIdentity(identity);
11395 }
11396 }
Daniel Bright59e67312020-11-13 11:49:37 -080011397
11398 @Override
11399 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011400 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011401 if (!mApp.getResources().getBoolean(
11402 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11404 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11405 "isRadioInterfaceCapabilitySupported");
11406 }
joonhunshin4ac60942023-11-15 15:23:39 +000011407
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011408 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011409 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011410 if (radioInterfaceCapabilities == null) {
11411 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011412 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011413 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011414 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011415
Hui Wang641e81c2020-10-12 12:14:23 -070011416 @Override
11417 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11418 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011419 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11420 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11421 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11422 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11423 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011424
11425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11426 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11427
Hui Wang641e81c2020-10-12 12:14:23 -070011428 if (DBG) {
11429 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11430 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11431 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11432 }
11433
11434 if (!SubscriptionManager.isValidSubscriptionId(subId)
11435 || appType < TelephonyManager.APPTYPE_UNKNOWN
11436 || appType > TelephonyManager.APPTYPE_ISIM
11437 || nafUrl == null || securityProtocol == null || callback == null) {
11438 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11439 if (callback != null) {
11440 try {
11441 callback.onAuthenticationFailure(
11442 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11443 } catch (RemoteException exception) {
11444 log("Fail to notify onAuthenticationFailure due to " + exception);
11445 }
11446 return;
11447 }
11448 }
11449
11450 final long token = Binder.clearCallingIdentity();
11451 try {
11452 getGbaManager(subId).bootstrapAuthenticationRequest(
11453 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011454 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011455 } finally {
11456 Binder.restoreCallingIdentity(token);
11457 }
11458 }
11459
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011460 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011461 * Attempts to set the radio power state for all phones for thermal reason.
11462 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011463 * requested radio power state will actually be set. See {@link
11464 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11465 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011466 * @param enable {@code true} if trying to turn radio on.
11467 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11468 * false}.
11469 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011470 private boolean setRadioPowerForThermal(boolean enable) {
11471 boolean isPhoneAvailable = false;
11472 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11473 Phone phone = PhoneFactory.getPhone(i);
11474 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011475 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011476 isPhoneAvailable = true;
11477 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011478 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011479
11480 // return true if successfully informed the phone object about the thermal radio power
11481 // request.
11482 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011483 }
11484
11485 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011486 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011487 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11488 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11489 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11490 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11491 throw new IllegalArgumentException("modem does not support data throttling");
11492 }
11493
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011494 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11495 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011496 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011497 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11498 }
11499
Sarah Chinecc78c42022-03-31 21:16:48 -070011500 setDataEnabledForReason(
11501 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011502
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011503 if (isDataThrottlingSupported) {
11504 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011505 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011506 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11507 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11508 } else if (thermalMitigationResult
11509 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011510 log("Modem likely does not support data throttling on secondary carrier. Data " +
11511 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11512 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011513 }
11514 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011516
11517 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 }
11519
Jack Nudelman644b91a2021-03-12 14:09:48 -080011520 private static List<String> getThermalMitigationAllowlist(Context context) {
11521 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11522 for (String pckg : context.getResources()
11523 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11524 sThermalMitigationAllowlistedPackages.add(pckg);
11525 }
11526 }
11527
11528 return sThermalMitigationAllowlistedPackages;
11529 }
11530
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011531 private boolean isAnyPhoneInEmergencyState() {
11532 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11533 if (tm.isInEmergencyCall()) {
11534 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11535 return true;
11536 }
11537 for (Phone phone : PhoneFactory.getPhones()) {
11538 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11539 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011540 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11541 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011542 return true;
11543 }
11544 }
11545
11546 return false;
11547 }
11548
Jack Nudelman644b91a2021-03-12 14:09:48 -080011549 /**
11550 * Used by shell commands to add an authorized package name for thermal mitigation.
11551 * @param packageName name of package to be allowlisted
11552 * @param context
11553 */
11554 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11555 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11556 sThermalMitigationAllowlistedPackages.add(packageName);
11557 }
11558
11559 /**
11560 * Used by shell commands to remove an authorized package name for thermal mitigation.
11561 * @param packageName name of package to remove from allowlist
11562 * @param context
11563 */
11564 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11565 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11566 sThermalMitigationAllowlistedPackages.remove(packageName);
11567 }
11568
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011569 /**
11570 * Thermal mitigation request to control functionalities at modem.
11571 *
11572 * @param subId the id of the subscription.
11573 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011574 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011575 *
11576 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11577 */
11578 @Override
11579 @ThermalMitigationResult
11580 public int sendThermalMitigationRequest(
11581 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011582 ThermalMitigationRequest thermalMitigationRequest,
11583 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011584 enforceModifyPermission();
11585
Jack Nudelman644b91a2021-03-12 14:09:48 -080011586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011587
11588 enforceTelephonyFeatureWithException(callingPackage,
11589 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11590
Jack Nudelman644b91a2021-03-12 14:09:48 -080011591 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11592 .contains(callingPackage)) {
11593 throw new SecurityException("Calling package must be configured in the device config. "
11594 + "calling package: " + callingPackage);
11595 }
11596
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011597 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11598 final long identity = Binder.clearCallingIdentity();
11599
11600 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11601 try {
11602 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11603 switch (thermalMitigationAction) {
11604 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11605 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011606 handleDataThrottlingRequest(subId,
11607 thermalMitigationRequest.getDataThrottlingRequest(),
11608 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011609 break;
11610 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11611 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11612 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11613 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11614 }
11615
11616 // Ensure that radio is on. If not able to power on due to phone being
11617 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011618 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011619 thermalMitigationResult =
11620 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11621 break;
11622 }
11623
11624 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011625 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011626 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11627 break;
11628 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11629 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11630 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11631 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11632 }
11633
11634 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11635 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011636 Phone phone = getPhone(subId);
11637 if (phone == null) {
11638 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011639 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011640 break;
11641 }
11642
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011643 TelephonyConnectionService service =
11644 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011645 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011646 Log.e(LOG_TAG, "An emergency call is pending");
11647 thermalMitigationResult =
11648 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11649 break;
11650 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011651 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011652 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011653 break;
11654 }
11655 } else {
11656 thermalMitigationResult =
11657 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11658 break;
11659 }
11660
11661 // Turn radio off. If not able to power off due to phone being unavailable,
11662 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011663 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011664 thermalMitigationResult =
11665 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11666 break;
11667 }
11668 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011669 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011670 break;
11671 default:
11672 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11673 + "not exist. Requested action: " + thermalMitigationAction);
11674 }
11675 } catch (IllegalArgumentException e) {
11676 throw e;
11677 } catch (Exception e) {
11678 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11679 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11680 } finally {
11681 Binder.restoreCallingIdentity(identity);
11682 }
11683
11684 if (DBG) {
11685 log("thermalMitigationRequest returning with thermalMitigationResult: "
11686 + thermalMitigationResult);
11687 }
11688
11689 return thermalMitigationResult;
11690 }
Hui Wang641e81c2020-10-12 12:14:23 -070011691
11692 /**
11693 * Set the GbaService Package Name that Telephony will bind to.
11694 *
11695 * @param subId The sim that the GbaService is associated with.
11696 * @param packageName The name of the package to be replaced with.
11697 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11698 */
11699 @Override
11700 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11701 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011702 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011703 final long identity = Binder.clearCallingIdentity();
11704 try {
Jack Yu02533f12024-10-03 18:44:32 -070011705 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011706 } finally {
11707 Binder.restoreCallingIdentity(identity);
11708 }
11709 }
11710
11711 /**
11712 * Return the package name of the currently bound GbaService.
11713 *
11714 * @param subId The sim that the GbaService is associated with.
11715 * @return the package name of the GbaService configuration, null if GBA is not supported.
11716 */
11717 @Override
11718 public String getBoundGbaService(int subId) {
11719 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11720
11721 final long identity = Binder.clearCallingIdentity();
11722 try {
11723 return getGbaManager(subId).getServicePackage();
11724 } finally {
11725 Binder.restoreCallingIdentity(identity);
11726 }
11727 }
11728
11729 /**
11730 * Set the release time for telephony to unbind GbaService.
11731 *
11732 * @param subId The sim that the GbaService is associated with.
11733 * @param interval The release time to unbind GbaService by millisecond.
11734 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11735 */
11736 @Override
11737 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11738 enforceModifyPermission();
11739
11740 final long identity = Binder.clearCallingIdentity();
11741 try {
11742 return getGbaManager(subId).overrideReleaseTime(interval);
11743 } finally {
11744 Binder.restoreCallingIdentity(identity);
11745 }
11746 }
11747
11748 /**
11749 * Return the release time for telephony to unbind GbaService.
11750 *
11751 * @param subId The sim that the GbaService is associated with.
11752 * @return The release time to unbind GbaService by millisecond.
11753 */
11754 @Override
11755 public int getGbaReleaseTime(int subId) {
11756 enforceReadPrivilegedPermission("getGbaReleaseTime");
11757
11758 final long identity = Binder.clearCallingIdentity();
11759 try {
11760 return getGbaManager(subId).getReleaseTime();
11761 } finally {
11762 Binder.restoreCallingIdentity(identity);
11763 }
11764 }
11765
11766 private GbaManager getGbaManager(int subId) {
11767 GbaManager instance = GbaManager.getInstance(subId);
11768 if (instance == null) {
11769 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11770 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11771 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11772 }
11773 return instance;
11774 }
Hui Wang761a6682020-10-31 05:12:53 +000011775
11776 /**
11777 * indicate whether the device and the carrier can support
11778 * RCS VoLTE single registration.
11779 */
11780 @Override
11781 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011782 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11783 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11784 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11785 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011786
11787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11788 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11789 }
11790
11791 final long identity = Binder.clearCallingIdentity();
11792 try {
11793 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11794 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011795 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11796 if (isCapable != null) {
11797 return isCapable;
11798 }
Hui Wang761a6682020-10-31 05:12:53 +000011799 }
Hui Wang67af90e2021-06-04 16:57:15 -070011800 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11801 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011802 } finally {
11803 Binder.restoreCallingIdentity(identity);
11804 }
11805 }
11806
11807 /**
11808 * Register RCS provisioning callback.
11809 */
11810 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011811 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011812 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011813 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011814 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011815 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11816 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011817
11818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11819 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11820 }
joonhunshin4ac60942023-11-15 15:23:39 +000011821 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11822 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11823 Binder.getCallingUserHandle())) {
11824 if (!isImsAvailableOnDevice()) {
11825 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11826 "IMS not available on device.");
11827 }
11828 } else {
11829 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11830 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011831 }
11832
11833 final long identity = Binder.clearCallingIdentity();
11834 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011835 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011836 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011837 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11838 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011839 }
Hui Wang761a6682020-10-31 05:12:53 +000011840 } finally {
11841 Binder.restoreCallingIdentity(identity);
11842 }
11843 }
11844
11845 /**
11846 * Unregister RCS provisioning callback.
11847 */
11848 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011849 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011850 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011851 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011852 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011853 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11854 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011855
11856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11858 }
joonhunshin4ac60942023-11-15 15:23:39 +000011859
11860 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11861 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11862 Binder.getCallingUserHandle())) {
11863 if (!isImsAvailableOnDevice()) {
11864 // operation failed silently
11865 Rlog.w(LOG_TAG, "IMS not available on device.");
11866 return;
11867 }
11868 } else {
11869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11870 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11871 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011872 }
11873
11874 final long identity = Binder.clearCallingIdentity();
11875 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011876 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011877 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011878 } finally {
11879 Binder.restoreCallingIdentity(identity);
11880 }
11881 }
11882
11883 /**
11884 * trigger RCS reconfiguration.
11885 */
11886 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011887 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11888 "triggerRcsReconfiguration",
11889 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011890
11891 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11892 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11893 }
joonhunshin4ac60942023-11-15 15:23:39 +000011894 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11895 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11896 Binder.getCallingUserHandle())) {
11897 if (!isImsAvailableOnDevice()) {
11898 // ProvisioningManager can not handle ServiceSpecificException.
11899 // Throw the IllegalStateException and annotate ProvisioningManager.
11900 throw new IllegalStateException("IMS not available on device.");
11901 }
11902 } else {
11903 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11904 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011905 }
11906
11907 final long identity = Binder.clearCallingIdentity();
11908 try {
11909 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11910 } finally {
11911 Binder.restoreCallingIdentity(identity);
11912 }
11913 }
11914
11915 /**
11916 * Provide the client configuration parameters of the RCS application.
11917 */
11918 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011919 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11920 "setRcsClientConfiguration",
11921 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011922
11923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11924 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11925 }
joonhunshin4ac60942023-11-15 15:23:39 +000011926 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11927 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11928 Binder.getCallingUserHandle())) {
11929 if (!isImsAvailableOnDevice()) {
11930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11931 "IMS not available on device.");
11932 }
11933 } else {
11934 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11935 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011936 }
11937
11938 final long identity = Binder.clearCallingIdentity();
11939
11940 try {
11941 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11942 if (configBinder == null) {
11943 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011944 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11945 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011946 } else {
11947 configBinder.setRcsClientConfiguration(rcc);
11948 }
joonhunshin3e154242021-09-17 06:33:39 +000011949
11950 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11951 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011952 } catch (RemoteException e) {
11953 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011954 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11955 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011956 } finally {
11957 Binder.restoreCallingIdentity(identity);
11958 }
11959 }
11960
11961 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011962 * Enables or disables the test mode for RCS VoLTE single registration.
11963 */
11964 @Override
11965 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11966 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11967 "setRcsSingleRegistrationTestModeEnabled");
11968
11969 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11970 }
11971
11972 /**
11973 * Gets the test mode for RCS VoLTE single registration.
11974 */
11975 @Override
11976 public boolean getRcsSingleRegistrationTestModeEnabled() {
11977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11978 "getRcsSingleRegistrationTestModeEnabled");
11979
11980 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11981 }
11982
11983 /**
Hui Wang761a6682020-10-31 05:12:53 +000011984 * Overrides the config of RCS VoLTE single registration enabled for the device.
11985 */
11986 @Override
11987 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11989 "setDeviceSingleRegistrationEnabledOverride");
11990 enforceModifyPermission();
11991
11992 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11993 : Boolean.parseBoolean(enabledStr);
11994 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011995 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011996 }
11997
11998 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011999 * Sends a device to device communication message. Only usable via shell.
12000 * @param message message to send.
12001 * @param value message value.
12002 */
12003 @Override
12004 public void sendDeviceToDeviceMessage(int message, int value) {
12005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012006 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012007 enforceModifyPermission();
12008
12009 final long identity = Binder.clearCallingIdentity();
12010 try {
12011 TelephonyConnectionService service =
12012 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12013 if (service == null) {
12014 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12015 return;
12016 }
12017 service.sendTestDeviceToDeviceMessage(message, value);
12018 } finally {
12019 Binder.restoreCallingIdentity(identity);
12020 }
12021 }
12022
Tyler Gunnbabbda02021-02-10 11:05:02 -080012023 /**
12024 * Sets the specified device to device transport active.
12025 * @param transport The transport to set active.
12026 */
12027 @Override
12028 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12030 "setActiveDeviceToDeviceTransport");
12031 enforceModifyPermission();
12032
12033 final long identity = Binder.clearCallingIdentity();
12034 try {
12035 TelephonyConnectionService service =
12036 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12037 if (service == null) {
12038 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12039 return;
12040 }
12041 service.setActiveDeviceToDeviceTransport(transport);
12042 } finally {
12043 Binder.restoreCallingIdentity(identity);
12044 }
12045 }
Tyler Gunn92479152021-01-20 16:30:10 -080012046
Tyler Gunnd4339262021-05-03 14:46:49 -070012047 @Override
12048 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12050 "setDeviceToDeviceForceEnabled");
12051
12052 final long identity = Binder.clearCallingIdentity();
12053 try {
12054 Arrays.stream(PhoneFactory.getPhones()).forEach(
12055 p -> {
12056 Phone thePhone = p.getImsPhone();
12057 if (thePhone != null && thePhone instanceof ImsPhone) {
12058 ImsPhone imsPhone = (ImsPhone) thePhone;
12059 CallTracker tracker = imsPhone.getCallTracker();
12060 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12061 ImsPhoneCallTracker imsPhoneCallTracker =
12062 (ImsPhoneCallTracker) tracker;
12063 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12064 }
12065 }
12066 }
12067 );
12068 } finally {
12069 Binder.restoreCallingIdentity(identity);
12070 }
12071 }
12072
Tyler Gunn92479152021-01-20 16:30:10 -080012073 /**
Hui Wang761a6682020-10-31 05:12:53 +000012074 * Gets the config of RCS VoLTE single registration enabled for the device.
12075 */
12076 @Override
12077 public boolean getDeviceSingleRegistrationEnabled() {
12078 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12079 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12080 }
12081
12082 /**
12083 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12084 */
12085 @Override
12086 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12088 "setCarrierSingleRegistrationEnabledOverride");
12089 enforceModifyPermission();
12090
12091 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12092 : Boolean.parseBoolean(enabledStr);
12093 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12094 subId, enabled);
12095 }
12096
12097 /**
12098 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12099 */
12100 @Override
12101 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12102 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12103 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12104 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012105
12106 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012107 * Overrides the ims feature validation result
12108 */
12109 @Override
12110 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12112 "setImsFeatureValidationOverride");
12113
12114 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12115 : Boolean.parseBoolean(enabledStr);
12116 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12117 subId, enabled);
12118 }
12119
12120 /**
12121 * Gets the ims feature validation override value
12122 */
12123 @Override
12124 public boolean getImsFeatureValidationOverride(int subId) {
12125 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12126 "getImsFeatureValidationOverride");
12127 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12128 }
12129
12130 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012131 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12132 * their mobile plan.
12133 */
12134 @Override
12135 public String getMobileProvisioningUrl() {
12136 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12137 final long identity = Binder.clearCallingIdentity();
12138 try {
12139 return getDefaultPhone().getMobileProvisioningUrl();
12140 } finally {
12141 Binder.restoreCallingIdentity(identity);
12142 }
12143 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012144
James.cf Linbcdf8b32021-01-14 16:44:13 +080012145 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012146 * Get the EAB contact from the EAB database.
12147 */
12148 @Override
12149 public String getContactFromEab(String contact) {
12150 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12151 enforceModifyPermission();
12152 final long identity = Binder.clearCallingIdentity();
12153 try {
12154 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12155 } finally {
12156 Binder.restoreCallingIdentity(identity);
12157 }
12158 }
12159
12160 /**
Calvin Pana1434322021-07-01 19:27:01 +080012161 * Get the EAB capability from the EAB database.
12162 */
12163 @Override
12164 public String getCapabilityFromEab(String contact) {
12165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12166 enforceModifyPermission();
12167 final long identity = Binder.clearCallingIdentity();
12168 try {
12169 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12170 } finally {
12171 Binder.restoreCallingIdentity(identity);
12172 }
12173 }
12174
12175 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012176 * Remove the EAB contacts from the EAB database.
12177 */
12178 @Override
12179 public int removeContactFromEab(int subId, String contacts) {
12180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12181 enforceModifyPermission();
12182 final long identity = Binder.clearCallingIdentity();
12183 try {
12184 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12185 } finally {
12186 Binder.restoreCallingIdentity(identity);
12187 }
12188 }
12189
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012190 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012191 public boolean getDeviceUceEnabled() {
12192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12193 final long identity = Binder.clearCallingIdentity();
12194 try {
12195 return mApp.getDeviceUceEnabled();
12196 } finally {
12197 Binder.restoreCallingIdentity(identity);
12198 }
12199 }
12200
12201 @Override
12202 public void setDeviceUceEnabled(boolean isEnabled) {
12203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12204 final long identity = Binder.clearCallingIdentity();
12205 try {
12206 mApp.setDeviceUceEnabled(isEnabled);
12207 } finally {
12208 Binder.restoreCallingIdentity(identity);
12209 }
12210 }
12211
Brad Ebinger14d467f2021-02-12 06:18:28 +000012212 /**
12213 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12214 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12215 */
12216 // Used for SHELL command only right now.
12217 @Override
12218 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12219 List<String> featureTags) {
12220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12221 "addUceRegistrationOverrideShell");
12222 final long identity = Binder.clearCallingIdentity();
12223 try {
12224 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12225 new ArraySet<>(featureTags));
12226 } catch (ImsException e) {
12227 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12228 } finally {
12229 Binder.restoreCallingIdentity(identity);
12230 }
12231 }
12232
12233 /**
12234 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12235 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12236 */
12237 // Used for SHELL command only right now.
12238 @Override
12239 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12240 List<String> featureTags) {
12241 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12242 "removeUceRegistrationOverrideShell");
12243 final long identity = Binder.clearCallingIdentity();
12244 try {
12245 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12246 new ArraySet<>(featureTags));
12247 } catch (ImsException e) {
12248 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12249 } finally {
12250 Binder.restoreCallingIdentity(identity);
12251 }
12252 }
12253
12254 /**
12255 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12256 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12257 */
12258 // Used for SHELL command only right now.
12259 @Override
12260 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12262 "clearUceRegistrationOverrideShell");
12263 final long identity = Binder.clearCallingIdentity();
12264 try {
12265 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12266 } catch (ImsException e) {
12267 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12268 } finally {
12269 Binder.restoreCallingIdentity(identity);
12270 }
12271 }
12272
12273 /**
12274 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12275 */
12276 // Used for SHELL command only right now.
12277 @Override
12278 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12279 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12280 "getLatestRcsContactUceCapabilityShell");
12281 final long identity = Binder.clearCallingIdentity();
12282 try {
12283 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12284 } catch (ImsException e) {
12285 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12286 } finally {
12287 Binder.restoreCallingIdentity(identity);
12288 }
12289 }
12290
12291 /**
12292 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12293 * device does not have an active PUBLISH.
12294 */
12295 // Used for SHELL command only right now.
12296 @Override
12297 public String getLastUcePidfXmlShell(int subId) {
12298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12299 final long identity = Binder.clearCallingIdentity();
12300 try {
12301 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12302 } catch (ImsException e) {
12303 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12304 } finally {
12305 Binder.restoreCallingIdentity(identity);
12306 }
12307 }
12308
James.cf Line8713a42021-04-29 16:04:26 +080012309 /**
12310 * Remove UCE requests cannot be sent to the network status.
12311 */
12312 // Used for SHELL command only right now.
12313 @Override
12314 public boolean removeUceRequestDisallowedStatus(int subId) {
12315 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12316 final long identity = Binder.clearCallingIdentity();
12317 try {
12318 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12319 } catch (ImsException e) {
12320 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12321 } finally {
12322 Binder.restoreCallingIdentity(identity);
12323 }
12324 }
12325
James.cf Lin18bb9002021-05-25 01:37:38 +080012326 /**
12327 * Remove UCE requests cannot be sent to the network status.
12328 */
12329 // Used for SHELL command only.
12330 @Override
12331 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12332 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12333 final long identity = Binder.clearCallingIdentity();
12334 try {
12335 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12336 } catch (ImsException e) {
12337 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12338 } finally {
12339 Binder.restoreCallingIdentity(identity);
12340 }
12341 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012342
James.cf Lin4b784aa2021-01-31 03:25:15 +080012343 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012344 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12345 String callingPackage) {
12346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12347 mApp, subId, "setSignalStrengthUpdateRequest");
12348
joonhunshin4ac60942023-11-15 15:23:39 +000012349 enforceTelephonyFeatureWithException(callingPackage,
12350 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12351
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012352 final int callingUid = Binder.getCallingUid();
12353 // Verify that tha callingPackage belongs to the calling UID
12354 mApp.getSystemService(AppOpsManager.class)
12355 .checkPackage(callingUid, callingPackage);
12356
Rambo Wang3607f502021-02-01 21:51:40 -080012357 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012358
12359 final long identity = Binder.clearCallingIdentity();
12360 try {
12361 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12362 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12363
12364 if (result instanceof IllegalStateException) {
12365 throw (IllegalStateException) result;
12366 }
12367 } finally {
12368 Binder.restoreCallingIdentity(identity);
12369 }
12370 }
12371
12372 @Override
12373 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12374 String callingPackage) {
12375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12376 mApp, subId, "clearSignalStrengthUpdateRequest");
12377
joonhunshin4ac60942023-11-15 15:23:39 +000012378 enforceTelephonyFeatureWithException(callingPackage,
12379 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12380
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012381 final int callingUid = Binder.getCallingUid();
12382 // Verify that tha callingPackage belongs to the calling UID
12383 mApp.getSystemService(AppOpsManager.class)
12384 .checkPackage(callingUid, callingPackage);
12385
12386 final long identity = Binder.clearCallingIdentity();
12387 try {
12388 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12389 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12390
12391 if (result instanceof IllegalStateException) {
12392 throw (IllegalStateException) result;
12393 }
12394 } finally {
12395 Binder.restoreCallingIdentity(identity);
12396 }
12397 }
12398
Rambo Wang3607f502021-02-01 21:51:40 -080012399 private static void validateSignalStrengthUpdateRequest(Context context,
12400 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012401 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012402 // phone/system process do not have further restriction on request
12403 return;
12404 }
12405
12406 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012407 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012408 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012409 context.enforceCallingOrSelfPermission(
12410 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12411 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012412 }
12413
12414 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012415 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012416 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012417 || info.isEnabled()) {
12418 throw new IllegalArgumentException(
12419 "Only system can set hide fields in SignalThresholdInfo");
12420 }
12421
12422 // Thresholds length for each RAN need in range. This has been validated in
12423 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12424 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12425 final int[] thresholds = info.getThresholds();
12426 Objects.requireNonNull(thresholds);
12427 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12428 || thresholds.length
12429 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12430 throw new IllegalArgumentException(
12431 "thresholds length is out of range: " + thresholds.length);
12432 }
12433 }
12434 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012435
12436 /**
12437 * Gets the current phone capability.
12438 *
12439 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12440 * @return the PhoneCapability which describes the data connection capability of modem.
12441 * It's used to evaluate possible phone config change, for example from single
12442 * SIM device to multi-SIM device.
12443 */
12444 @Override
12445 public PhoneCapability getPhoneCapability() {
12446 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012447
12448 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12449 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12450
SongFerngWang8236caa2021-01-17 21:51:44 +080012451 final long identity = Binder.clearCallingIdentity();
12452 try {
12453 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12454 } finally {
12455 Binder.restoreCallingIdentity(identity);
12456 }
12457 }
Michele Berionne5e411512020-11-13 02:36:59 +000012458
12459 /**
12460 * Prepare TelephonyManager for an unattended reboot. The reboot is
12461 * required to be done shortly after the API is invoked.
12462 */
12463 @Override
12464 @TelephonyManager.PrepareUnattendedRebootResult
12465 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012467 enforceRebootPermission();
12468
joonhunshin4ac60942023-11-15 15:23:39 +000012469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12470 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12471
Michele Berionne5e411512020-11-13 02:36:59 +000012472 final long identity = Binder.clearCallingIdentity();
12473 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012474 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012475 } finally {
12476 Binder.restoreCallingIdentity(identity);
12477 }
12478 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012479
12480 /**
12481 * Request to get the current slicing configuration including URSP rules and
12482 * NSSAIs (configured, allowed and rejected).
12483 *
12484 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12485 */
12486 @Override
12487 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012488 TelephonyPermissions
12489 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12490 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012491
joonhunshin4ac60942023-11-15 15:23:39 +000012492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12493 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12494 "getSlicingConfig");
12495
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012496 final long identity = Binder.clearCallingIdentity();
12497 try {
12498 Phone phone = getDefaultPhone();
12499 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12500 } finally {
12501 Binder.restoreCallingIdentity(identity);
12502 }
12503 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012504
12505 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012506 * Check whether the given premium capability is available for purchase from the carrier.
12507 *
12508 * @param capability The premium capability to check.
12509 * @param subId The subId to check the premium capability for.
12510 *
12511 * @return Whether the given premium capability is available to purchase.
12512 */
12513 @Override
12514 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12515 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12516 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12517 log("Premium capability "
12518 + TelephonyManager.convertPremiumCapabilityToString(capability)
12519 + " is not available for purchase due to missing permissions.");
12520 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12521 + "permission READ_BASIC_PHONE_STATE.");
12522 }
12523
joonhunshin4ac60942023-11-15 15:23:39 +000012524 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12525 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12526
Sarah Chin2ec39f62022-08-31 17:03:26 -070012527 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012528 if (phone == null) {
12529 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12530 return false;
12531 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012532 final long identity = Binder.clearCallingIdentity();
12533 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012534 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012535 .isPremiumCapabilityAvailableForPurchase(capability);
12536 } finally {
12537 Binder.restoreCallingIdentity(identity);
12538 }
12539 }
12540
12541 /**
12542 * Purchase the given premium capability from the carrier.
12543 *
12544 * @param capability The premium capability to purchase.
12545 * @param callback The result of the purchase request.
12546 * @param subId The subId to purchase the premium capability for.
12547 */
12548 @Override
12549 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12550 log("purchasePremiumCapability: capability="
12551 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12552 + getCurrentPackageName());
12553
12554 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12555 mApp, "purchasePremiumCapability")) {
12556 log("purchasePremiumCapability "
12557 + TelephonyManager.convertPremiumCapabilityToString(capability)
12558 + " failed due to missing permissions.");
12559 throw new SecurityException("purchasePremiumCapability requires permission "
12560 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012561 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12562 mApp, "purchasePremiumCapability")) {
12563 log("purchasePremiumCapability "
12564 + TelephonyManager.convertPremiumCapabilityToString(capability)
12565 + " failed due to missing permissions.");
12566 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012567 }
12568
joonhunshin4ac60942023-11-15 15:23:39 +000012569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12570 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12571
Sarah Chin2ec39f62022-08-31 17:03:26 -070012572 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012573 if (phone == null) {
12574 try {
12575 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12576 callback.accept(result);
12577 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12578 } catch (RemoteException e) {
12579 String logStr = "Purchase premium capability "
12580 + TelephonyManager.convertPremiumCapabilityToString(capability)
12581 + " failed due to RemoteException handling null phone: " + e;
12582 if (DBG) log(logStr);
12583 AnomalyReporter.reportAnomaly(
12584 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12585 }
12586 return;
12587 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012588
12589 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012590 try {
Jack Yube3fa442024-09-16 14:39:45 -070012591 if (mFeatureFlags.hsumPackageManager()) {
12592 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12593 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12594 } else {
12595 callingProcess = mApp.getPackageManager().getApplicationInfo(
12596 getCurrentPackageName(), 0).processName;
12597 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012598 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012599 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012600 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012601
12602 boolean isVisible = false;
12603 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12604 if (am != null) {
12605 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12606 if (processes != null) {
12607 for (ActivityManager.RunningAppProcessInfo process : processes) {
12608 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012609 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012610 if (process.processName.equals(callingProcess) && process.importance
12611 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12612 isVisible = true;
12613 break;
12614 }
12615 }
12616 }
12617 }
12618
12619 if (!isVisible) {
12620 try {
12621 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12622 callback.accept(result);
12623 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12624 } catch (RemoteException e) {
12625 String logStr = "Purchase premium capability "
12626 + TelephonyManager.convertPremiumCapabilityToString(capability)
12627 + " failed due to RemoteException handling background application: " + e;
12628 if (DBG) log(logStr);
12629 AnomalyReporter.reportAnomaly(
12630 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12631 }
12632 return;
12633 }
12634
Sarah Chin71b3a852022-09-28 15:54:19 -070012635 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012636 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012637 }
12638
12639 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012640 * Register an IMS connection state callback
12641 */
12642 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012643 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12644 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012645 if (feature == ImsFeature.FEATURE_MMTEL) {
12646 // ImsMmTelManager
12647 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12648 TelephonyPermissions
12649 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12650 mApp, subId, "registerImsStateCallback");
12651 } else if (feature == ImsFeature.FEATURE_RCS) {
12652 // ImsRcsManager or SipDelegateManager
12653 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12654 Binder.getCallingUid(), "registerImsStateCallback",
12655 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12656 Manifest.permission.READ_PRECISE_PHONE_STATE,
12657 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12658 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12659 }
12660
12661 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12663 "IMS not available on device.");
12664 }
12665
12666 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12667 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12668 }
12669
12670 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12671 if (controller == null) {
12672 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12673 "IMS not available on device.");
12674 }
12675
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012676 if (callingPackage == null) {
12677 callingPackage = getCurrentPackageName();
12678 }
12679
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012680 final long token = Binder.clearCallingIdentity();
12681 try {
12682 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012683 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012684 } catch (ImsException e) {
12685 throw new ServiceSpecificException(e.getCode());
12686 } finally {
12687 Binder.restoreCallingIdentity(token);
12688 }
12689 }
12690
12691 /**
12692 * Unregister an IMS connection state callback
12693 */
12694 @Override
12695 public void unregisterImsStateCallback(IImsStateCallback cb) {
12696 final long token = Binder.clearCallingIdentity();
12697 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12698 if (controller == null) {
12699 return;
12700 }
12701 try {
12702 controller.unregisterImsStateCallback(cb);
12703 } finally {
12704 Binder.restoreCallingIdentity(token);
12705 }
12706 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012707
12708 /**
12709 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12710 *
12711 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012712 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012713 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012714 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012715 * If there is current registered network this value will be same as the registered cell
12716 * identity. If the device goes out of service the previous cell identity is cached and
12717 * will be returned. If the cache age of the Cell identity is more than 24 hours
12718 * it will be cleared and null will be returned.
12719 *
12720 */
12721 @Override
12722 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12723 String callingFeatureId) {
12724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12725 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12726 LocationAccessPolicy.checkLocationPermission(mApp,
12727 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12728 .setCallingPackage(callingPackage)
12729 .setCallingFeatureId(callingFeatureId)
12730 .setCallingPid(Binder.getCallingPid())
12731 .setCallingUid(Binder.getCallingUid())
12732 .setMethod("getLastKnownCellIdentity")
12733 .setLogAsInfo(true)
12734 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12735 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12736 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12737 .build());
12738
12739 boolean hasFinePermission =
12740 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12741 if (!hasFinePermission
12742 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12743 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012744 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012745 }
12746
12747 final long identity = Binder.clearCallingIdentity();
12748 try {
Ling Mac28f0212023-03-24 16:07:15 -070012749 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012750 if (sst == null) return null;
12751 return sst.getLastKnownCellIdentity();
12752 } finally {
12753 Binder.restoreCallingIdentity(identity);
12754 }
12755 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012756
jimsun3b9ccac2021-10-26 15:01:23 +080012757 /**
12758 * Sets the modem service class Name that Telephony will bind to.
12759 *
12760 * @param serviceName The class name of the modem service.
12761 * @return true if the operation is succeed, otherwise false.
12762 */
12763 public boolean setModemService(String serviceName) {
12764 Log.d(LOG_TAG, "setModemService - " + serviceName);
12765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012767 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12768 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012769 return mPhoneConfigurationManager.setModemService(serviceName);
12770 }
12771
12772 /**
12773 * Return the class name of the currently bounded modem service.
12774 *
12775 * @return the class name of the modem service.
12776 */
12777 public String getModemService() {
12778 String result;
12779 Log.d(LOG_TAG, "getModemService");
12780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12781 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012782 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012783 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12784 "getModemService");
12785 result = mPhoneConfigurationManager.getModemService();
12786 Log.d(LOG_TAG, "result = " + result);
12787 return result;
12788 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012789
Hakjun Choi3ee81112023-12-19 15:40:58 +000012790 /**
12791 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12792 * including carrier config, entitlement server, and config update.
12793 *
12794 * @param subId subId The subscription ID of the carrier.
12795 *
12796 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12797 * be returned.
12798 *
12799 * @throws SecurityException if the caller doesn't have the required permission.
12800 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012801 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12802 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012803 final long identity = Binder.clearCallingIdentity();
12804 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012805 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012806 } finally {
12807 Binder.restoreCallingIdentity(identity);
12808 }
12809 }
12810
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012811 @Override
12812 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12813 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12814 mApp.enforceCallingOrSelfPermission(
12815 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12816 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12817
12818 final long identity = Binder.clearCallingIdentity();
12819 try {
12820 Phone phone = getPhone(subId);
12821 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012822 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12823 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012824 phone.setVoiceServiceStateOverride(hasService);
12825 } finally {
12826 Binder.restoreCallingIdentity(identity);
12827 }
12828 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012829
12830 /**
12831 * set removable eSIM as default eUICC.
12832 *
12833 * @hide
12834 */
12835 @Override
12836 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12837 enforceModifyPermission();
12838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12839
12840 final long identity = Binder.clearCallingIdentity();
12841 try {
12842 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12843 } finally {
12844 Binder.restoreCallingIdentity(identity);
12845 }
12846 }
12847
12848 /**
12849 * Returns whether the removable eSIM is default eUICC or not.
12850 *
12851 * @hide
12852 */
12853 @Override
12854 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12855 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12856 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12857
12858 final long identity = Binder.clearCallingIdentity();
12859 try {
12860 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12861 } finally {
12862 Binder.restoreCallingIdentity(identity);
12863 }
12864 }
12865
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012866 /**
12867 * Get the component name of the default app to direct respond-via-message intent for the
12868 * user associated with this subscription, update the cache if there is no respond-via-message
12869 * application currently configured for this user.
12870 * @return component name of the app and class to direct Respond Via Message intent to, or
12871 * {@code null} if the functionality is not supported.
12872 * @hide
12873 */
12874 @Override
12875 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12876 boolean updateIfNeeded) {
12877 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012878
joonhunshin4ac60942023-11-15 15:23:39 +000012879 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12880 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12881 "getDefaultRespondViaMessageApplication");
12882
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012883 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12884
Grant Menkeb0372492024-09-19 18:01:29 -070012885 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12886 UserHandle mainUser = null;
12887 Context userContext = null;
12888 final long identity = Binder.clearCallingIdentity();
12889 try {
12890 mainUser = mUserManager.getMainUser();
12891 userContext = context.createContextAsUser(mainUser, 0);
12892 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12893 } finally {
12894 Binder.restoreCallingIdentity(identity);
12895 }
12896 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12897 updateIfNeeded, mainUser);
12898 } else {
12899 UserHandle userHandle = null;
12900 final long identity = Binder.clearCallingIdentity();
12901 try {
12902 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12903 } finally {
12904 Binder.restoreCallingIdentity(identity);
12905 }
12906 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12907 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012908 }
Grant Menkeb0372492024-09-19 18:01:29 -070012909
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012910 }
Jack Yuf5badd92022-12-08 00:50:53 -080012911
12912 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012913 * Set whether the device is able to connect with null ciphering or integrity
12914 * algorithms. This is a global setting and will apply to all active subscriptions
12915 * and all new subscriptions after this.
12916 *
12917 * @param enabled when true, null cipher and integrity algorithms are allowed.
12918 * @hide
12919 */
12920 @Override
12921 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12922 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12923 enforceModifyPermission();
12924 checkForNullCipherAndIntegritySupport();
12925
12926 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12927 // for listening to these preference changes and applying them immediately.
12928 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12929 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12930 editor.apply();
12931
12932 for (Phone phone: PhoneFactory.getPhones()) {
12933 phone.handleNullCipherEnabledChange();
12934 }
12935 }
12936
12937
12938 /**
12939 * Get whether the device is able to connect with null ciphering or integrity
12940 * algorithms. Note that this retrieves the phone-global preference and not
12941 * the state of the radio.
12942 *
12943 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12944 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12945 * version for this feature.
12946 * @hide
12947 */
12948 @Override
12949 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12950 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12951 enforceReadPermission();
12952 checkForNullCipherAndIntegritySupport();
12953 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12954 }
12955
12956 private void checkForNullCipherAndIntegritySupport() {
12957 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12958 throw new UnsupportedOperationException(
12959 "Null cipher and integrity operations require HAL 2.1 or above");
12960 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012961 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12962 throw new UnsupportedOperationException(
12963 "Null cipher and integrity operations unsupported by modem");
12964 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012965 }
12966
Gil Cukierman06403e12023-11-29 16:33:03 +000012967 private void checkForIdentifierDisclosureNotificationSupport() {
12968 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12969 throw new UnsupportedOperationException(
12970 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12971 + "above");
12972 }
12973 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12974 throw new UnsupportedOperationException(
12975 "Cellular identifier disclosure transparency operations unsupported by modem");
12976 }
12977 }
12978
Michael Groover826b71d2023-12-21 22:08:06 -060012979 private void checkForNullCipherNotificationSupport() {
12980 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12981 throw new UnsupportedOperationException(
12982 "Null cipher notification operations require HAL 2.2 or above");
12983 }
12984 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12985 throw new UnsupportedOperationException(
12986 "Null cipher notification operations unsupported by modem");
12987 }
12988 }
12989
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012990 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012991 * Get the SIM state for the slot index.
12992 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12993 *
12994 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12995 */
12996 @Override
12997 @SimState
12998 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012999 if (!mApp.getResources().getBoolean(
13000 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13002 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13003 }
joonhunshin4ac60942023-11-15 15:23:39 +000013004
Jack Yuf5badd92022-12-08 00:50:53 -080013005 IccCardConstants.State simState;
13006 if (slotIndex < 0) {
13007 simState = IccCardConstants.State.UNKNOWN;
13008 } else {
13009 Phone phone = null;
13010 try {
13011 phone = PhoneFactory.getPhone(slotIndex);
13012 } catch (IllegalStateException e) {
13013 // ignore
13014 }
13015 if (phone == null) {
13016 simState = IccCardConstants.State.UNKNOWN;
13017 } else {
13018 IccCard icc = phone.getIccCard();
13019 if (icc == null) {
13020 simState = IccCardConstants.State.UNKNOWN;
13021 } else {
13022 simState = icc.getState();
13023 }
13024 }
13025 }
13026 return simState.ordinal();
13027 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013028
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013029 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13030 boolean enableLogcat,
13031 long logcatStartTimestampMillis, boolean enableTelecomDump,
13032 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013033 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013034 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13035 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13036 ecdDataBuilder
13037 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13038 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013039 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013040 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013041 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013042 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13043 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013044 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13045 Executors.newCachedThreadPool(), db,
13046 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013047 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013048 }
13049
13050 /**
13051 * Request telephony to persist state for debugging emergency call failures.
13052 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013053 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013054 * @param enableLogcat whether to collect logcat output
13055 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13056 * @param enableTelecomDump whether to collect telecom dumpsys
13057 * @param enableTelephonyDump whether to collect telephony dumpsys
13058 */
13059 @Override
13060 @RequiresPermission(android.Manifest.permission.DUMP)
13061 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13062 long logcatStartTimestampMillis, boolean enableTelecomDump,
13063 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013064 // Verify that the caller has READ_DROPBOX_DATA permission.
13065 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13066 && Flags.enableReadDropboxPermission()) {
13067 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13068 "persistEmergencyCallDiagnosticData");
13069 } else {
13070 // Otherwise, enforce legacy permission.
13071 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13072 "persistEmergencyCallDiagnosticData");
13073 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013074 final long identity = Binder.clearCallingIdentity();
13075 try {
13076 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13077 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13078
13079 } finally {
13080 Binder.restoreCallingIdentity(identity);
13081 }
13082 }
13083
Hui Wang9b5793a2022-12-05 14:38:06 -060013084 /**
13085 * Get current cell broadcast ranges.
13086 */
13087 @Override
13088 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13089 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13090 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13091 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013092
13093 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13094 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13095
Hui Wang9b5793a2022-12-05 14:38:06 -060013096 final long identity = Binder.clearCallingIdentity();
13097 try {
13098 return getPhone(subId).getCellBroadcastIdRanges();
13099 } finally {
13100 Binder.restoreCallingIdentity(identity);
13101 }
13102 }
13103
13104 /**
13105 * Set reception of cell broadcast messages with the list of the given ranges
13106 *
13107 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13108 */
13109 @Override
13110 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13111 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13112 @Nullable IIntegerConsumer callback) {
13113 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13114 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013115
13116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13117 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13118
Hui Wang9b5793a2022-12-05 14:38:06 -060013119 final long identity = Binder.clearCallingIdentity();
13120 try {
13121 Phone phone = getPhoneFromSubId(subId);
13122 if (DBG) {
13123 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13124 }
13125 phone.setCellBroadcastIdRanges(ranges, result -> {
13126 if (callback != null) {
13127 try {
13128 callback.accept(result);
13129 } catch (RemoteException e) {
13130 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13131 }
13132 }
13133 });
13134 } finally {
13135 Binder.restoreCallingIdentity(identity);
13136 }
13137 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013138
13139 /**
13140 * Returns whether the device supports the domain selection service.
13141 *
13142 * @return {@code true} if the device supports the domain selection service.
13143 */
13144 @Override
13145 public boolean isDomainSelectionSupported() {
13146 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13147 "isDomainSelectionSupported");
13148
13149 final long identity = Binder.clearCallingIdentity();
13150 try {
13151 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13152 } finally {
13153 Binder.restoreCallingIdentity(identity);
13154 }
13155 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013156
13157 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013158 * Returns whether the AOSP domain selection service is supported.
13159 *
13160 * @return {@code true} if the AOSP domain selection service is supported,
13161 * {@code false} otherwise.
13162 */
13163 @Override
13164 public boolean isAospDomainSelectionService() {
13165 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13166 "isAospDomainSelectionService");
13167
13168 final long identity = Binder.clearCallingIdentity();
13169 try {
13170 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13171 String dssComponentName = mApp.getResources().getString(
13172 R.string.config_domain_selection_service_component_name);
13173 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13174 TelephonyDomainSelectionService.class.getName());
13175 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13176 + ", aosp=" + componentName.flattenToString());
13177 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13178 }
13179 } finally {
13180 Binder.restoreCallingIdentity(identity);
13181 }
13182 return false;
13183 }
13184
13185 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013186 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13187 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13188 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013189 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013190 * @param enableSatellite {@code true} to enable the satellite modem and
13191 * {@code false} to disable.
13192 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013193 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013194 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013195 *
13196 * @throws SecurityException if the caller doesn't have the required permission.
13197 */
13198 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013199 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013200 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013201 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013202 final long identity = Binder.clearCallingIdentity();
13203 try {
13204 if (enableSatellite) {
youngtaecha3a9c8a62024-11-01 20:46:08 +000013205 String caller = "PIM:requestSatelliteEnabled";
Hyosun322782b2024-10-24 11:37:59 +000013206 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13207 @Override
13208 protected void onReceiveResult(int resultCode, Bundle resultData) {
13209 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13210 + ", resultData=" + resultData);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013211 mSatelliteController.decrementResultReceiverCount(caller);
13212
Hyosun322782b2024-10-24 11:37:59 +000013213 boolean isAllowed = false;
13214 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13215 callback::accept);
13216 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13217 if (resultData != null
13218 && resultData.containsKey(
13219 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13220 isAllowed = resultData.getBoolean(
13221 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13222 } else {
13223 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13224 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013225 } else {
Hyosun322782b2024-10-24 11:37:59 +000013226 result.accept(resultCode);
13227 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013228 }
Hyosun322782b2024-10-24 11:37:59 +000013229 if (isAllowed) {
Duke Lee8852e512024-10-06 12:55:43 +090013230 if (mFeatureFlags.carrierRoamingNbIotNtn()
13231 && !mSatelliteAccessController.getSatelliteDisallowedReasons()
13232 .isEmpty()) {
13233 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13234 } else {
13235 mSatelliteController.requestSatelliteEnabled(
13236 enableSatellite, enableDemoMode, isEmergency, callback);
13237 }
Hyosun322782b2024-10-24 11:37:59 +000013238 } else {
13239 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13240 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013241 }
Hyosun322782b2024-10-24 11:37:59 +000013242 };
13243 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13244 resultReceiver, true);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013245 mSatelliteController.incrementResultReceiverCount(caller);
Hyosun322782b2024-10-24 11:37:59 +000013246 } else {
13247 // No need to check if satellite is allowed at current location when disabling
13248 // satellite
13249 mSatelliteController.requestSatelliteEnabled(
13250 enableSatellite, enableDemoMode, isEmergency, callback);
13251 }
13252 } finally {
13253 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013254 }
Sarah Chin503828c2023-02-01 23:54:20 -080013255 }
13256
13257 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013258 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013259 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013260 * @param result The result receiver that returns whether the satellite modem is enabled
13261 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013262 *
13263 * @throws SecurityException if the caller doesn't have the required permission.
13264 */
13265 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013266 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013267 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013268 final long identity = Binder.clearCallingIdentity();
13269 try {
13270 mSatelliteController.requestIsSatelliteEnabled(result);
13271 } finally {
13272 Binder.restoreCallingIdentity(identity);
13273 }
Sarah Chin503828c2023-02-01 23:54:20 -080013274 }
13275
13276 /**
Sarah Chin43457982023-02-15 17:50:38 -080013277 * Request to get whether the satellite service demo mode is enabled.
13278 *
Sarah Chin43457982023-02-15 17:50:38 -080013279 * @param result The result receiver that returns whether the satellite demo mode is enabled
13280 * if the request is successful or an error code if the request failed.
13281 *
13282 * @throws SecurityException if the caller doesn't have the required permission.
13283 */
13284 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013285 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013286 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013287 final long identity = Binder.clearCallingIdentity();
13288 try {
13289 mSatelliteController.requestIsDemoModeEnabled(result);
13290 } finally {
13291 Binder.restoreCallingIdentity(identity);
13292 }
Sarah Chin43457982023-02-15 17:50:38 -080013293 }
13294
13295 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013296 * Request to get whether the satellite service is enabled with emergency mode.
13297 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013298 * @param result The result receiver that returns whether the satellite emergency mode is
13299 * enabled if the request is successful or an error code if the request failed.
13300 *
13301 * @throws SecurityException if the caller doesn't have the required permission.
13302 */
13303 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013304 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013305 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013306 final long identity = Binder.clearCallingIdentity();
13307 try {
13308 mSatelliteController.requestIsEmergencyModeEnabled(result);
13309 } finally {
13310 Binder.restoreCallingIdentity(identity);
13311 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013312 }
13313
13314 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013315 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013316 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013317 * @param result The result receiver that returns whether the satellite service is supported on
13318 * the device if the request is successful or an error code if the request failed.
Hyosun322782b2024-10-24 11:37:59 +000013319 *
13320 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chin503828c2023-02-01 23:54:20 -080013321 */
13322 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013323 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013324 enforceSatelliteCommunicationPermission("requestIsSatelliteSupported");
13325 final long identity = Binder.clearCallingIdentity();
13326 try {
13327 mSatelliteController.requestIsSatelliteSupported(result);
13328 } finally {
13329 Binder.restoreCallingIdentity(identity);
13330 }
Sarah Chin503828c2023-02-01 23:54:20 -080013331 }
13332
13333 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013334 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013335 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013336 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13337 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013338 *
13339 * @throws SecurityException if the caller doesn't have required permission.
13340 */
13341 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013342 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013343 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013344 final long identity = Binder.clearCallingIdentity();
13345 try {
13346 mSatelliteController.requestSatelliteCapabilities(result);
13347 } finally {
13348 Binder.restoreCallingIdentity(identity);
13349 }
Sarah Chin503828c2023-02-01 23:54:20 -080013350 }
13351
13352 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013353 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013354 * This can be called by the pointing UI when the user starts pointing to the satellite.
13355 * Modem should continue to report the pointing input as the device or satellite moves.
13356 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013357 * @param resultCallback The callback to get the result of the request.
13358 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013359 *
13360 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013361 */
13362 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013363 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013364 @NonNull IIntegerConsumer resultCallback,
13365 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13366 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013367 final long identity = Binder.clearCallingIdentity();
13368 try {
13369 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13370 } finally {
13371 Binder.restoreCallingIdentity(identity);
13372 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013373 }
13374
13375 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013376 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013377 * This can be called by the pointing UI when the user stops pointing to the satellite.
13378 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013379 * @param resultCallback The callback to get the result of the request.
13380 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013381 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013382 *
13383 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013384 */
13385 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013386 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013387 @NonNull IIntegerConsumer resultCallback,
13388 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13389 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013390 final long identity = Binder.clearCallingIdentity();
13391 try {
13392 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13393 } finally {
13394 Binder.restoreCallingIdentity(identity);
13395 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013396 }
13397
13398 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 * Register the subscription with a satellite provider.
13400 * This is needed to register the subscription if the provider allows dynamic registration.
13401 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013402 * @param token The token to be used as a unique identifier for provisioning with satellite
13403 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013404 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013405 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013406 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013407 * @return The signal transport used by the caller to cancel the provision request,
13408 * or {@code null} if the request failed.
13409 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013410 * @throws SecurityException if the caller doesn't have the required permission.
13411 */
13412 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013413 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013414 @NonNull String token, @NonNull byte[] provisionData,
13415 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013416 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013417 final long identity = Binder.clearCallingIdentity();
13418 try {
13419 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013420 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013421 } finally {
13422 Binder.restoreCallingIdentity(identity);
13423 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013424 }
13425
13426 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013427 * Unregister the device/subscription with the satellite provider.
13428 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013429 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013430 * should report as deprovisioned.
13431 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013432 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013433 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013434 *
13435 * @throws SecurityException if the caller doesn't have the required permission.
13436 */
13437 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013438 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013439 @NonNull String token, @NonNull IIntegerConsumer callback) {
13440 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013441 final long identity = Binder.clearCallingIdentity();
13442 try {
13443 mSatelliteController.deprovisionSatelliteService(token, callback);
13444 } finally {
13445 Binder.restoreCallingIdentity(identity);
13446 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013447 }
13448
13449 /**
Sarah Chin43457982023-02-15 17:50:38 -080013450 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013451 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013452 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013453 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013454 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013455 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013456 * @throws SecurityException if the caller doesn't have the required permission.
13457 */
13458 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013459 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013460 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013461 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013462 final long identity = Binder.clearCallingIdentity();
13463 try {
13464 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13465 } finally {
13466 Binder.restoreCallingIdentity(identity);
13467 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013468 }
13469
13470 /**
Sarah Chin43457982023-02-15 17:50:38 -080013471 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013472 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013473 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013474 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013475 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013476 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013477 * @throws SecurityException if the caller doesn't have the required permission.
13478 */
13479 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013480 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013481 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013482 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013483 final long identity = Binder.clearCallingIdentity();
13484 try {
13485 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13486 } finally {
13487 Binder.restoreCallingIdentity(identity);
13488 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013489 }
13490
13491 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013492 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013493 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013494 * @param result The result receiver that returns whether the device is provisioned with a
13495 * satellite provider if the request is successful or an error code if the
13496 * request failed.
13497 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013498 * @throws SecurityException if the caller doesn't have the required permission.
13499 */
13500 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013501 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013502 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013503 final long identity = Binder.clearCallingIdentity();
13504 try {
13505 mSatelliteController.requestIsSatelliteProvisioned(result);
13506 } finally {
13507 Binder.restoreCallingIdentity(identity);
13508 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013509 }
13510
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013511 /**
Sarah Chin43457982023-02-15 17:50:38 -080013512 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013513 *
Sarah Chin43457982023-02-15 17:50:38 -080013514 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013515 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013516 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013517 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013518 * @throws SecurityException if the caller doesn't have the required permission.
13519 */
13520 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013521 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013522 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013523 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013524 final long identity = Binder.clearCallingIdentity();
13525 try {
13526 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13527 } finally {
13528 Binder.restoreCallingIdentity(identity);
13529 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013530 }
13531
13532 /**
Sarah Chin43457982023-02-15 17:50:38 -080013533 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013534 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013535 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013536 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013537 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013538 *
13539 * @throws SecurityException if the caller doesn't have the required permission.
13540 */
13541 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013542 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013543 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013544 final long identity = Binder.clearCallingIdentity();
13545 try {
13546 mSatelliteController.unregisterForModemStateChanged(callback);
13547 } finally {
13548 Binder.restoreCallingIdentity(identity);
13549 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013550 }
13551
13552 /**
13553 * Register to receive incoming datagrams over satellite.
13554 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013555 * @param callback The callback to handle incoming datagrams over satellite.
13556 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013557 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013558 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013559 * @throws SecurityException if the caller doesn't have the required permission.
13560 */
13561 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013562 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013563 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013564 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013565 final long identity = Binder.clearCallingIdentity();
13566 try {
13567 return mSatelliteController.registerForIncomingDatagram(callback);
13568 } finally {
13569 Binder.restoreCallingIdentity(identity);
13570 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013571 }
13572
13573 /**
13574 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013575 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013576 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013577 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013578 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013579 *
13580 * @throws SecurityException if the caller doesn't have the required permission.
13581 */
13582 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013583 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013584 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013585 final long identity = Binder.clearCallingIdentity();
13586 try {
13587 mSatelliteController.unregisterForIncomingDatagram(callback);
13588 } finally {
13589 Binder.restoreCallingIdentity(identity);
13590 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013591 }
13592
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013593 /**
13594 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013595 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013596 * This method requests modem to check if there are any pending datagrams to be received over
13597 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013598 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013599 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013600 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013601 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013602 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013603 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013604 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013605 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013606 final long identity = Binder.clearCallingIdentity();
13607 try {
13608 mSatelliteController.pollPendingDatagrams(callback);
13609 } finally {
13610 Binder.restoreCallingIdentity(identity);
13611 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013612 }
13613
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013614 /**
13615 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013616 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013617 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13618 * input to this method. Datagram received here will be passed down to modem without any
13619 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013620 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013621 * @param datagramType datagram type indicating whether the datagram is of type
13622 * SOS_SMS or LOCATION_SHARING.
13623 * @param datagram encoded gateway datagram which is encrypted by the caller.
13624 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013625 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13626 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013627 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013628 *
13629 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013630 */
13631 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013632 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013633 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13634 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013635 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013636 final long identity = Binder.clearCallingIdentity();
13637 try {
13638 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13639 callback);
13640 } finally {
13641 Binder.restoreCallingIdentity(identity);
13642 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013643 }
13644
Sarah Chindf715ec2023-02-13 13:46:24 -080013645 /**
Duke Lee8852e512024-10-06 12:55:43 +090013646 * Returns integer array of disallowed reasons of satellite.
13647 *
13648 * @return Integer array of disallowed reasons of satellite.
13649 *
13650 * @throws SecurityException if the caller doesn't have the required permission.
13651 */
13652 @NonNull public int[] getSatelliteDisallowedReasons() {
13653 enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons");
13654 final long identity = Binder.clearCallingIdentity();
13655 try {
13656 return mSatelliteAccessController.getSatelliteDisallowedReasons()
13657 .stream().mapToInt(Integer::intValue).toArray();
13658 } finally {
13659 Binder.restoreCallingIdentity(identity);
13660 }
13661 }
13662
13663 /**
13664 * Registers for disallowed reasons change event from satellite service.
13665 *
13666 * @param callback The callback to handle disallowed reasons changed event.
13667 *
13668 * @throws SecurityException if the caller doesn't have the required permission.
13669 */
13670 @Override
13671 public void registerForSatelliteDisallowedReasonsChanged(
13672 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13673 enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged");
13674 final long identity = Binder.clearCallingIdentity();
13675 try {
13676 mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback);
13677 } finally {
13678 Binder.restoreCallingIdentity(identity);
13679 }
13680 }
13681
13682 /**
13683 * Unregisters for disallowed reasons change event from satellite service.
13684 * If callback was not registered before, the request will be ignored.
13685 *
13686 * @param callback The callback to handle disallowed reasons changed event.
13687 * {@link #registerForSatelliteDisallowedReasonsChanged(
13688 * ISatelliteDisallowedReasonsCallback)}.
13689 * @throws SecurityException if the caller doesn't have the required permission.
13690 */
13691 @Override
13692 public void unregisterForSatelliteDisallowedReasonsChanged(
13693 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13694 enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged");
13695 final long identity = Binder.clearCallingIdentity();
13696 try {
13697 mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback);
13698 } finally {
13699 Binder.restoreCallingIdentity(identity);
13700 }
13701 }
13702
13703 /**
Sarah Chindf715ec2023-02-13 13:46:24 -080013704 * Request to get whether satellite communication is allowed for the current location.
13705 *
13706 * @param subId The subId of the subscription to check whether satellite communication is
13707 * allowed for the current location for.
13708 * @param result The result receiver that returns whether satellite communication is allowed
13709 * for the current location if the request is successful or an error code
13710 * if the request failed.
13711 *
13712 * @throws SecurityException if the caller doesn't have the required permission.
13713 */
13714 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013715 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013716 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013717 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013718 final long identity = Binder.clearCallingIdentity();
13719 try {
13720 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13721 false);
13722 } finally {
13723 Binder.restoreCallingIdentity(identity);
13724 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013725 }
13726
13727 /**
youngtaechaedc8a1c2024-10-15 09:07:25 +000013728 * Request to get satellite access configuration for the current location.
13729 *
13730 * @param result The result receiver that returns the satellite access configuration
13731 * for the current location if the request is successful or an error code
13732 * if the request failed.
13733 *
13734 * @throws SecurityException if the caller doesn't have the required permission.
13735 */
13736 @Override
13737 public void requestSatelliteAccessConfigurationForCurrentLocation(
13738 @NonNull ResultReceiver result) {
13739 enforceSatelliteCommunicationPermission(
13740 "requestSatelliteAccessConfigurationForCurrentLocation");
13741 final long identity = Binder.clearCallingIdentity();
13742 try {
13743 mSatelliteAccessController
13744 .requestSatelliteAccessConfigurationForCurrentLocation(result);
13745 } finally {
13746 Binder.restoreCallingIdentity(identity);
13747 }
13748 }
13749
13750 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013751 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013752 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013753 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013754 * be visible if the request is successful or an error code if the request failed.
13755 *
13756 * @throws SecurityException if the caller doesn't have the required permission.
13757 */
13758 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013759 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013760 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013761 final long identity = Binder.clearCallingIdentity();
13762 try {
13763 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13764 } finally {
13765 Binder.restoreCallingIdentity(identity);
13766 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013767 }
13768
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013769 /**
Daniel Banta99cc7532024-11-15 02:31:08 +000013770 * Request to get the currently selected satellite subscription id.
13771 *
13772 * @param result The result receiver that returns the currently selected satellite subscription
13773 * id if the request is successful or an error code if the request failed.
13774 *
13775 * @throws SecurityException if the caller doesn't have the required permission.
13776 */
13777 @Override
13778 public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) {
13779 enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId");
13780 final long identity = Binder.clearCallingIdentity();
13781 try {
13782 mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result);
13783 } finally {
13784 Binder.restoreCallingIdentity(identity);
13785 }
13786 }
13787
13788 /**
joonhunshin59104152024-09-11 09:55:35 +000013789 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013790 *
joonhunshin59104152024-09-11 09:55:35 +000013791 * @param isAligned {@code true} Device is aligned with the satellite.
13792 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013793 *
13794 * @throws SecurityException if the caller doesn't have required permission.
13795 */
13796 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13797
joonhunshin83da7cd2024-08-22 08:53:35 +000013798 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013799 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13800 final long identity = Binder.clearCallingIdentity();
13801 try {
13802 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13803 } finally {
13804 Binder.restoreCallingIdentity(identity);
13805 }
Hakjun Choiae365972023-04-25 11:00:31 +000013806 }
13807
13808 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013809 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13810 * by modem.
13811 *
13812 * @param subId The subId of the subscription to request for.
13813 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013814 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013815 * operation.
13816 *
13817 * @throws SecurityException if the caller doesn't have required permission.
13818 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013819 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013820 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13821 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013822 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013823 final long identity = Binder.clearCallingIdentity();
13824 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013825 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013826 } finally {
13827 Binder.restoreCallingIdentity(identity);
13828 }
13829 }
13830
13831 /**
13832 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13833 * by modem.
13834 *
13835 * @param subId The subId of the subscription to request for.
13836 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013837 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013838 * operation.
13839 *
13840 * @throws SecurityException if the caller doesn't have required permission.
13841 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013842 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013843 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13844 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013845 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013846 final long identity = Binder.clearCallingIdentity();
13847 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013848 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013849 } finally {
13850 Binder.restoreCallingIdentity(identity);
13851 }
13852 }
13853
13854 /**
13855 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013856 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013857 *
13858 * @param subId The subId of the subscription to request for.
13859 *
13860 * @return Integer array of reasons for disallowing satellite communication.
13861 *
13862 * @throws SecurityException if the caller doesn't have the required permission.
13863 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013864 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013865 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013866 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013867 final long identity = Binder.clearCallingIdentity();
13868 try {
13869 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013870 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013871 return reasonSet.stream().mapToInt(i->i).toArray();
13872 } finally {
13873 Binder.restoreCallingIdentity(identity);
13874 }
13875 }
13876
13877 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013878 * Request to get the signal strength of the satellite connection.
13879 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013880 * @param result Result receiver to get the error code of the request and the current signal
13881 * strength of the satellite connection.
13882 *
13883 * @throws SecurityException if the caller doesn't have required permission.
13884 */
13885 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013886 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013887 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13888 final long identity = Binder.clearCallingIdentity();
13889 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013890 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013891 } finally {
13892 Binder.restoreCallingIdentity(identity);
13893 }
13894 }
13895
13896 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013897 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13898 * is not successful, a {@link ServiceSpecificException} that contains
13899 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013900 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013901 * @param callback The callback to handle the NTN signal strength changed event. If the
13902 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13903 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13904 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13905 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013906 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013907 * @throws SecurityException If the caller doesn't have the required permission.
13908 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013909 */
13910 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013911 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013912 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013913 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13914 final long identity = Binder.clearCallingIdentity();
13915 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013916 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013917 } finally {
13918 Binder.restoreCallingIdentity(identity);
13919 }
13920 }
13921
13922 /**
13923 * Unregisters for NTN signal strength changed from satellite modem.
13924 * If callback was not registered before, the request will be ignored.
13925 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013926 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013927 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013928 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013929 *
13930 * @throws SecurityException if the caller doesn't have the required permission.
13931 */
13932 @Override
13933 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013934 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013935 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13936 final long identity = Binder.clearCallingIdentity();
13937 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013938 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013939 } finally {
13940 Binder.restoreCallingIdentity(identity);
13941 }
13942 }
13943
13944 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013945 * Registers for satellite capabilities change event from the satellite service.
13946 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013947 * @param callback The callback to handle the satellite capabilities changed event.
13948 *
13949 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13950 *
13951 * @throws SecurityException if the caller doesn't have required permission.
13952 */
13953 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013954 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013955 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013956 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013957 final long identity = Binder.clearCallingIdentity();
13958 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013959 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013960 } finally {
13961 Binder.restoreCallingIdentity(identity);
13962 }
13963 }
13964
13965 /**
13966 * Unregisters for satellite capabilities change event from the satellite service.
13967 * If callback was not registered before, the request will be ignored.
13968 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013969 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013970 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013971 *
13972 * @throws SecurityException if the caller doesn't have required permission.
13973 */
13974 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013975 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013976 @NonNull ISatelliteCapabilitiesCallback callback) {
13977 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013978 final long identity = Binder.clearCallingIdentity();
13979 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013980 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013981 } finally {
13982 Binder.restoreCallingIdentity(identity);
13983 }
13984 }
13985
13986 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013987 * Registers for the satellite supported state changed.
13988 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013989 * @param callback The callback to handle the satellite supported state changed event.
13990 *
13991 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13992 *
13993 * @throws SecurityException if the caller doesn't have the required permission.
13994 */
13995 @Override
13996 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013997 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013998 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013999 final long identity = Binder.clearCallingIdentity();
14000 try {
14001 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
14002 } finally {
14003 Binder.restoreCallingIdentity(identity);
14004 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014005 }
14006
14007 /**
14008 * Unregisters for the satellite supported state changed.
14009 * If callback was not registered before, the request will be ignored.
14010 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014011 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014012 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000014013 *
14014 * @throws SecurityException if the caller doesn't have the required permission.
14015 */
14016 @Override
14017 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014018 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014019 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014020 final long identity = Binder.clearCallingIdentity();
14021 try {
14022 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
14023 } finally {
14024 Binder.restoreCallingIdentity(identity);
14025 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014026 }
14027
14028 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014029 * This API can be used by only CTS to update satellite vendor service package name.
14030 *
14031 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000014032 * @param provisioned Whether satellite should be provisioned or not.
14033 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014034 * @return {@code true} if the satellite vendor service is set successfully,
14035 * {@code false} otherwise.
14036 */
Hakjun Choic3393242024-06-26 18:02:08 +000014037 public boolean setSatelliteServicePackageName(String servicePackageName,
14038 String provisioned) {
14039 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
14040 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014041 TelephonyPermissions.enforceShellOnly(
14042 Binder.getCallingUid(), "setSatelliteServicePackageName");
14043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14044 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14045 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014046 final long identity = Binder.clearCallingIdentity();
14047 try {
14048 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
14049 provisioned);
14050 } finally {
14051 Binder.restoreCallingIdentity(identity);
14052 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014053 }
14054
14055 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014056 * This API can be used by only CTS to update satellite gateway service package name.
14057 *
14058 * @param servicePackageName The package name of the satellite gateway service.
14059 * @return {@code true} if the satellite gateway service is set successfully,
14060 * {@code false} otherwise.
14061 */
14062 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
14063 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
14064 TelephonyPermissions.enforceShellOnly(
14065 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
14066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14067 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14068 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014069 final long identity = Binder.clearCallingIdentity();
14070 try {
14071 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
14072 } finally {
14073 Binder.restoreCallingIdentity(identity);
14074 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014075 }
14076
14077 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070014078 * This API can be used by only CTS to update satellite pointing UI app package and class names.
14079 *
14080 * @param packageName The package name of the satellite pointing UI app.
14081 * @param className The class name of the satellite pointing UI app.
14082 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
14083 * {@code false} otherwise.
14084 */
14085 public boolean setSatellitePointingUiClassName(
14086 @Nullable String packageName, @Nullable String className) {
14087 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
14088 + ", className=" + className);
14089 TelephonyPermissions.enforceShellOnly(
14090 Binder.getCallingUid(), "setSatellitePointingUiClassName");
14091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14092 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014093 "setSatellitePointingUiClassName");
14094 final long identity = Binder.clearCallingIdentity();
14095 try {
14096 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
14097 } finally {
14098 Binder.restoreCallingIdentity(identity);
14099 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070014100 }
14101
14102 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014103 * This API can be used by only CTS to update the timeout duration in milliseconds that
14104 * satellite should stay at listening mode to wait for the next incoming page before disabling
14105 * listening mode.
14106 *
14107 * @param timeoutMillis The timeout duration in millisecond.
14108 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14109 */
14110 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14111 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14112 TelephonyPermissions.enforceShellOnly(
14113 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14115 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14116 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014117 final long identity = Binder.clearCallingIdentity();
14118 try {
14119 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14120 } finally {
14121 Binder.restoreCallingIdentity(identity);
14122 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014123 }
14124
14125 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014126 * This API can be used by only CTS to control ingoring cellular service state event.
14127 *
14128 * @param enabled Whether to enable boolean config.
14129 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14130 */
14131 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014132 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014133 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014134 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14136 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014137 "setSatelliteIgnoreCellularServiceState");
14138 final long identity = Binder.clearCallingIdentity();
14139 try {
14140 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14141 } finally {
14142 Binder.restoreCallingIdentity(identity);
14143 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014144 }
14145
14146 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014147 * This API can be used by only CTS to override the timeout durations used by the
14148 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014149 *
14150 * @param timeoutMillis The timeout duration in millisecond.
14151 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14152 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014153 public boolean setDatagramControllerTimeoutDuration(
14154 boolean reset, int timeoutType, long timeoutMillis) {
14155 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14156 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014157 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014158 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14160 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014161 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014162 final long identity = Binder.clearCallingIdentity();
14163 try {
14164 return mSatelliteController.setDatagramControllerTimeoutDuration(
14165 reset, timeoutType, timeoutMillis);
14166 } finally {
14167 Binder.restoreCallingIdentity(identity);
14168 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014169 }
14170
14171 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014172 * This API can be used by only CTS to override the boolean configs used by the
14173 * DatagramController module.
14174 *
14175 * @param enable Whether to enable or disable boolean config.
14176 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14177 */
14178 public boolean setDatagramControllerBooleanConfig(
14179 boolean reset, int booleanType, boolean enable) {
14180 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14181 + ", reset=" + reset + ", enable=" + enable);
14182 TelephonyPermissions.enforceShellOnly(
14183 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14185 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14186 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014187 final long identity = Binder.clearCallingIdentity();
14188 try {
14189 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14190 enable);
14191 } finally {
14192 Binder.restoreCallingIdentity(identity);
14193 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014194 }
14195
14196
14197 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014198 * This API can be used by only CTS to override the timeout durations used by the
14199 * SatelliteController module.
14200 *
14201 * @param timeoutMillis The timeout duration in millisecond.
14202 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14203 */
14204 public boolean setSatelliteControllerTimeoutDuration(
14205 boolean reset, int timeoutType, long timeoutMillis) {
14206 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14207 + reset + ", timeoutMillis=" + timeoutMillis);
14208 TelephonyPermissions.enforceShellOnly(
14209 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14211 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14212 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014213 final long identity = Binder.clearCallingIdentity();
14214 try {
14215 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14216 reset, timeoutType, timeoutMillis);
14217 } finally {
14218 Binder.restoreCallingIdentity(identity);
14219 }
Hakjun Choiae365972023-04-25 11:00:31 +000014220 }
14221
14222 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014223 * This API can be used in only testing to override connectivity status in monitoring emergency
14224 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14225 *
14226 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14227 * of the following values to enable the override:
14228 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14229 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14230 * To disable the override, use -1 for handoverType.
14231 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14232 * delaySeconds after the emergency call starts.
14233 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14234 */
14235 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14236 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14237 TelephonyPermissions.enforceShellOnly(
14238 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14240 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14241 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014242 final long identity = Binder.clearCallingIdentity();
14243 try {
14244 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14245 handoverType, delaySeconds);
14246 } finally {
14247 Binder.restoreCallingIdentity(identity);
14248 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014249 }
14250
14251 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014252 * This API can be used in only testing to override oem-enabled satellite provision status.
14253 *
14254 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14255 * otherwise.
14256 * @param isProvisioned The overriding provision status.
14257 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14258 */
14259 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14260 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14261 + ", isProvisioned=" + isProvisioned);
14262 TelephonyPermissions.enforceShellOnly(
14263 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14265 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14266 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014267 final long identity = Binder.clearCallingIdentity();
14268 try {
14269 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14270 } finally {
14271 Binder.restoreCallingIdentity(identity);
14272 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014273 }
14274
14275 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014276 * This API should be used by only CTS tests to forcefully set telephony country codes.
14277 *
14278 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14279 */
14280 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14281 Map cachedNetworkCountryCodes, String locationCountryCode,
14282 long locationCountryCodeTimestampNanos) {
14283 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14284 + String.join(", ", currentNetworkCountryCodes)
14285 + ", locationCountryCode=" + locationCountryCode
14286 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14287 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14288 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014291 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14292 final long identity = Binder.clearCallingIdentity();
14293 try {
14294 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14295 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14296 cachedNetworkCountryCodes, locationCountryCode,
14297 locationCountryCodeTimestampNanos);
14298 } finally {
14299 Binder.restoreCallingIdentity(identity);
14300 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014301 }
14302
14303 /**
14304 * This API should be used by only CTS tests to override the overlay configs of satellite
14305 * access controller.
14306 *
14307 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14308 * otherwise.
14309 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14310 */
14311 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14312 String s2CellFile, long locationFreshDurationNanos,
14313 List<String> satelliteCountryCodes) {
14314 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14315 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14316 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14317 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
14318 ? String.join(", ", satelliteCountryCodes) : null));
14319 TelephonyPermissions.enforceShellOnly(
14320 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14322 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14323 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014324 final long identity = Binder.clearCallingIdentity();
14325 try {
14326 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
14327 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
14328 } finally {
14329 Binder.restoreCallingIdentity(identity);
14330 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014331 }
14332
14333 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014334 * This API can be used by only CTS to override the cached value for the device overlay config
14335 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14336 * outgoing satellite datagrams should be sent to modem in demo mode.
14337 *
14338 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14339 * satellite modem or not.
14340 *
14341 * @return {@code true} if the operation is successful, {@code false} otherwise.
14342 */
14343 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14344 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14345 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14346 + "disabled");
14347 return false;
14348 }
14349 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14350 TelephonyPermissions.enforceShellOnly(
14351 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14353 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14354 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014355 final long identity = Binder.clearCallingIdentity();
14356 try {
14357 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14358 shouldSendToModemInDemoMode);
14359 } finally {
14360 Binder.restoreCallingIdentity(identity);
14361 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014362 }
14363
14364 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014365 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14366 *
14367 * @param state a state indicates whether satellite access allowed state should be cached and
14368 * the allowed state.
14369 * @return {@code true} if the setting is successful, {@code false} otherwise.
14370 */
14371 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14372 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14373 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14374 + "oemEnabledSatelliteFlag is disabled");
14375 return false;
14376 }
14377
14378 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14379 + "state=" + state);
14380 TelephonyPermissions.enforceShellOnly(
14381 Binder.getCallingUid(),
14382 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14384 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14385 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014386 final long identity = Binder.clearCallingIdentity();
14387 try {
14388 return mSatelliteAccessController
14389 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14390 } finally {
14391 Binder.restoreCallingIdentity(identity);
14392 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014393 }
14394
14395 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014396 * Sets the service defined in ComponentName to be bound.
14397 *
14398 * This should only be used for testing.
14399 * @return {@code true} if the DomainSelectionService to bind to was set,
14400 * {@code false} otherwise.
14401 */
14402 @Override
14403 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14404 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14405
14406 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14407 "setDomainSelectionServiceOverride");
14408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14409 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14410
14411 final long identity = Binder.clearCallingIdentity();
14412 try {
14413 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14414 return DomainSelectionResolver.getInstance()
14415 .setDomainSelectionServiceOverride(componentName);
14416 }
14417 } finally {
14418 Binder.restoreCallingIdentity(identity);
14419 }
14420 return false;
14421 }
14422
14423 /**
14424 * Clears the DomainSelectionService override.
14425 *
14426 * This should only be used for testing.
14427 * @return {@code true} if the DomainSelectionService override was cleared,
14428 * {@code false} otherwise.
14429 */
14430 @Override
14431 public boolean clearDomainSelectionServiceOverride() {
14432 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14433
14434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14435 "clearDomainSelectionServiceOverride");
14436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14437 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14438
14439 final long identity = Binder.clearCallingIdentity();
14440 try {
14441 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14442 return DomainSelectionResolver.getInstance()
14443 .clearDomainSelectionServiceOverride();
14444 }
14445 } finally {
14446 Binder.restoreCallingIdentity(identity);
14447 }
14448 return false;
14449 }
14450
14451 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014452 * Enable or disable notifications sent for cellular identifier disclosure events.
14453 *
14454 * Disclosure events are defined as instances where a device has sent a cellular identifier
14455 * on the Non-access stratum (NAS) before a security context is established. As a result the
14456 * identifier is sent in the clear, which has privacy implications for the user.
14457 *
14458 * @param enable if notifications about disclosure events should be enabled
14459 * @throws SecurityException if the caller does not have the required privileges
14460 * @throws UnsupportedOperationException if the modem does not support this feature.
14461 */
14462 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014463 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014464 enforceModifyPermission();
14465 checkForIdentifierDisclosureNotificationSupport();
14466
14467 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14468 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14469 editor.apply();
14470
14471 // Each phone instance is responsible for updating its respective modem immediately
14472 // after we've made a preference change.
14473 for (Phone phone : PhoneFactory.getPhones()) {
14474 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14475 }
14476 }
14477
14478 /**
14479 * Get whether or not cellular identifier disclosure notifications are enabled.
14480 *
14481 * @throws SecurityException if the caller does not have the required privileges
14482 * @throws UnsupportedOperationException if the modem does not support this feature.
14483 */
14484 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014485 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014486 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14487 checkForIdentifierDisclosureNotificationSupport();
14488 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14489 }
14490
14491 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014492 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14493 * are in use by the cellular modem.
14494 *
14495 * @throws IllegalStateException if the Telephony process is not currently available
14496 * @throws SecurityException if the caller does not have the required privileges
14497 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14498 * and integrity algorithms in use
14499 * @hide
14500 */
14501 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014502 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014503 enforceModifyPermission();
14504 checkForNullCipherNotificationSupport();
14505
14506 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14507 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14508 editor.apply();
14509
14510 // Each phone instance is responsible for updating its respective modem immediately
14511 // after a preference change.
14512 for (Phone phone : PhoneFactory.getPhones()) {
14513 phone.handleNullCipherNotificationPreferenceChanged();
14514 }
14515 }
14516
14517 /**
14518 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14519 * cellular modem.
14520 *
14521 * @throws IllegalStateException if the Telephony process is not currently available
14522 * @throws SecurityException if the caller does not have the required privileges
14523 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14524 * and integrity algorithms in use
14525 * @hide
14526 */
14527 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14528 public boolean isNullCipherNotificationsEnabled() {
14529 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14530 checkForNullCipherNotificationSupport();
14531 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14532 }
14533
14534 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014535 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14536 *
14537 * <p>This method behaves in one of the following ways:
14538 * <ul>
14539 * <li>return true : if the calling package has the appop permission {@link
14540 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14541 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14542 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14543 * Owner device identifier access check, or the calling package has carrier privileges</>
14544 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14545 * </ul>
14546 */
14547 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14548 String callingPackage, @Nullable String callingFeatureId, String message) {
14549 for (Phone phone : PhoneFactory.getPhones()) {
14550 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14551 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14552 return true;
14553 }
14554 }
14555 return false;
14556 }
arunvoddud7401012022-12-15 16:08:12 +000014557
14558 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014559 * @return The subscription manager service instance.
14560 */
14561 public SubscriptionManagerService getSubscriptionManagerService() {
14562 return SubscriptionManagerService.getInstance();
14563 }
14564
14565 /**
arunvoddud7401012022-12-15 16:08:12 +000014566 * Class binds the consumer[callback] and carrierId.
14567 */
14568 private static class CallerCallbackInfo {
14569 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014570 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014571
Steve Statia28b7cb32024-03-11 23:58:50 +000014572 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014573 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014574 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014575 }
14576
14577 public Consumer<Integer> getConsumer() {
14578 return mConsumer;
14579 }
14580
Steve Statia28b7cb32024-03-11 23:58:50 +000014581 public Set<Integer> getCarrierIds() {
14582 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014583 }
14584 }
joonhunshin4ac60942023-11-15 15:23:39 +000014585
14586 /*
14587 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14588 * But the context that is passed in is unused if the phone app is already alive.
14589 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14590 */
14591 @VisibleForTesting
14592 public void setPackageManager(PackageManager packageManager) {
14593 mPackageManager = packageManager;
14594 }
14595
14596 /*
Nate Myren453c3472024-03-13 11:28:11 -070014597 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14598 * But the context that is passed in is unused if the phone app is already alive.
14599 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14600 */
14601 @VisibleForTesting
14602 public void setAppOpsManager(AppOpsManager appOps) {
14603 mAppOps = appOps;
14604 }
14605
14606 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014607 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14608 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14609 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14610 */
14611 @VisibleForTesting
14612 public void setFeatureFlags(FeatureFlags featureFlags) {
14613 mFeatureFlags = featureFlags;
14614 }
14615
14616 /**
14617 * Make sure the device has required telephony feature
14618 *
14619 * @throws UnsupportedOperationException if the device does not have required telephony feature
14620 */
14621 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14622 @NonNull String telephonyFeature, @NonNull String methodName) {
14623 if (callingPackage == null || mPackageManager == null) {
14624 return;
14625 }
14626
14627 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14628 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014629 Binder.getCallingUserHandle())
14630 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14631 // Skip to check associated telephony feature,
14632 // if compatibility change is not enabled for the current process or
14633 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014634 return;
14635 }
14636
14637 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14638 throw new UnsupportedOperationException(
14639 methodName + " is unsupported without " + telephonyFeature);
14640 }
14641 }
youngtaecha5d483d52024-04-29 17:05:45 +000014642
14643 /**
14644 * Registers for the satellite communication allowed state changed.
14645 *
14646 * @param subId The subId of the subscription to register for the satellite communication
14647 * allowed state changed.
14648 * @param callback The callback to handle the satellite communication allowed
14649 * state changed event.
14650 *
14651 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14652 *
14653 * @throws SecurityException if the caller doesn't have the required permission.
14654 */
14655 @Override
14656 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14657 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14658 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014659 final long identity = Binder.clearCallingIdentity();
14660 try {
14661 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14662 subId, callback);
14663 } finally {
14664 Binder.restoreCallingIdentity(identity);
14665 }
youngtaecha5d483d52024-04-29 17:05:45 +000014666 }
14667
14668 /**
14669 * Unregisters for the satellite communication allowed state changed.
14670 * If callback was not registered before, the request will be ignored.
14671 *
14672 * @param subId The subId of the subscription to unregister for the satellite communication
14673 * allowed state changed.
14674 * @param callback The callback that was passed to
14675 * {@link #registerForCommunicationAllowedStateChanged(int,
14676 * ISatelliteCommunicationAllowedStateCallback)}. *
14677 * @throws SecurityException if the caller doesn't have the required permission.
14678 */
14679 @Override
14680 public void unregisterForCommunicationAllowedStateChanged(
14681 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14682 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014683 final long identity = Binder.clearCallingIdentity();
14684 try {
14685 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14686 callback);
14687 } finally {
14688 Binder.restoreCallingIdentity(identity);
14689 }
youngtaecha5d483d52024-04-29 17:05:45 +000014690 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014691
14692 /**
14693 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14694 *
14695 * @param subId The subId of the subscription to the satellite session stats for.
14696 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14697 * if the request is successful or an error code if the request failed.
14698 *
14699 * @throws SecurityException if the caller doesn't have required permission.
14700 */
14701 @Override
14702 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14703 enforceModifyPermission();
14704 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014705 final long identity = Binder.clearCallingIdentity();
14706 try {
14707 mSatelliteController.requestSatelliteSessionStats(subId, result);
14708 } finally {
14709 Binder.restoreCallingIdentity(identity);
14710 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014711 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014712
14713 /**
14714 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14715 *
14716 * @param result The result receiver, which returns the list of prioritized satellite tokens
14717 * to be used for provision if the request is successful or an error code if the request failed.
14718 *
14719 * @throws SecurityException if the caller doesn't have the required permission.
14720 */
14721 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014722 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14723 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014724 final long identity = Binder.clearCallingIdentity();
14725 try {
14726 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14727 } finally {
14728 Binder.restoreCallingIdentity(identity);
14729 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014730 }
14731
14732 /**
14733 * Deliver the list of provisioned satellite subscriber ids.
14734 *
14735 * @param list List of provisioned satellite subscriber ids.
14736 * @param result The result receiver that returns whether deliver success or fail.
14737 *
14738 * @throws SecurityException if the caller doesn't have the required permission.
14739 */
14740 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014741 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014742 @NonNull ResultReceiver result) {
14743 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014744 final long identity = Binder.clearCallingIdentity();
14745 try {
14746 mSatelliteController.provisionSatellite(list, result);
14747 } finally {
14748 Binder.restoreCallingIdentity(identity);
14749 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014750 }
Hyosund6aaf062024-08-23 23:02:10 +000014751
14752 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014753 * Deliver the list of deprovisioned satellite subscriber ids.
14754 *
14755 * @param list List of deprovisioned satellite subscriber ids.
14756 * @param result The result receiver that returns whether deliver success or fail.
14757 *
14758 * @throws SecurityException if the caller doesn't have the required permission.
14759 */
14760 @Override
14761 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14762 @NonNull ResultReceiver result) {
14763 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14764 final long identity = Binder.clearCallingIdentity();
14765 try {
14766 mSatelliteController.deprovisionSatellite(list, result);
14767 } finally {
14768 Binder.restoreCallingIdentity(identity);
14769 }
14770 }
14771
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014772
14773 /**
14774 * Inform whether application supports NTN SMS in satellite mode.
14775 *
14776 * This method is used by default messaging application to inform framework whether it supports
14777 * NTN SMS or not.
14778 *
14779 * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}.
14780 *
14781 * @throws SecurityException if the caller doesn't have required permission.
14782 */
14783 @Override
14784 public void setNtnSmsSupported(boolean ntnSmsSupported) {
14785 enforceSatelliteCommunicationPermission("setNtnSmsSupported");
14786 enforceSendSmsPermission();
14787 mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
14788 }
14789
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014790 /**
Hyosund6aaf062024-08-23 23:02:10 +000014791 * This API can be used by only CTS to override the cached value for the device overlay config
14792 * value :
14793 * config_satellite_gateway_service_package and
14794 * config_satellite_carrier_roaming_esos_provisioned_class.
14795 * These values are set before sending an intent to broadcast there are any change to list of
14796 * subscriber informations.
14797 *
14798 * @param name the name is one of the following that constitute an intent.
14799 * Component package name, or component class name.
14800 * @return {@code true} if the setting is successful, {@code false} otherwise.
14801 */
14802 @Override
14803 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14804 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14805 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14806 + " carrierRoamingNbIotNtn is disabled");
14807 return false;
14808 }
14809 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14810 TelephonyPermissions.enforceShellOnly(
14811 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14813 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14814 "setSatelliteSubscriberIdListChangedIntentComponent");
14815 final long identity = Binder.clearCallingIdentity();
14816 try {
14817 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14818 } finally {
14819 Binder.restoreCallingIdentity(identity);
14820 }
14821 }
Jack Yu26735292024-09-25 14:33:49 -070014822
14823 /**
14824 * This API can be used by only CTS to override the Euicc UI component.
14825 *
14826 * @param componentName ui component to be launched for testing. {@code null} to reset.
14827 *
14828 * @hide
14829 */
14830 @Override
14831 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14832 enforceModifyPermission();
14833 log("setTestEuiccUiComponent: " + componentName);
14834 mTestEuiccUiComponent = componentName;
14835 }
14836
14837 /**
14838 * This API can be used by only CTS to retrieve the Euicc UI component.
14839 *
14840 * @return Euicc UI component. {@code null} if not available.
14841 * @hide
14842 */
14843 @Override
14844 @Nullable
14845 public ComponentName getTestEuiccUiComponent() {
14846 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14847 return mTestEuiccUiComponent;
14848 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014849
14850 /**
14851 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14852 *
14853 * @param state to update Ntn Eligibility.
14854 * @param resetRequired to reset the overridden flag in satellite controller.
14855 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14856 */
14857 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14858 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014859 final long identity = Binder.clearCallingIdentity();
14860 try {
14861 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14862 resetRequired);
14863 } finally {
14864 Binder.restoreCallingIdentity(identity);
14865 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014866 }
Jack Yufa8ed012023-02-11 15:42:28 -080014867}