blob: bb88426a47d7a848deb8ffe904c545e334b0d7ec [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);
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008598
Rambo Wang71f6aa62024-02-23 20:16:22 +00008599 setDataRoamingEnabled(subId, phone == null ? false
8600 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008601 getPhone(subId).resetCarrierKeysForImsiEncryption(true);
Svet Ganovcc087f82015-05-12 20:35:54 -07008602 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008603 // There has been issues when Sms raw table somehow stores orphan
8604 // fragments. They lead to garbled message when new fragments come
8605 // in and combined with those stale ones. In case this happens again,
8606 // user can reset all network settings which will clean up this table.
8607 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008608 // Clean up IMS settings as well here.
8609 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008610 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008611 ImsManager.getInstance(mApp, slotId).factoryReset();
8612 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008613
Kai Shif70f46f2021-03-03 13:59:46 -08008614 if (defaultPhone == null) {
8615 return;
8616 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008617 // Erase modem config if erase modem on network setting is enabled.
8618 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8619 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8620 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008621 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008622 }
Kai Shif70f46f2021-03-03 13:59:46 -08008623
8624 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008625 } finally {
8626 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008627 }
8628 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008629
SongFerngWangfd89b102021-05-27 22:44:54 +08008630 @VisibleForTesting
8631 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8632 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8633 return;
8634 }
8635 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8636 RILConstants.PREFERRED_NETWORK_MODE);
8637 SubscriptionManager.setSubscriptionProperty(subId,
8638 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8639 "user=" + defaultNetworkType);
8640 phone.loadAllowedNetworksFromSubscriptionDatabase();
8641 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8642 defaultNetworkType, null);
8643 }
8644
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008645 private void cleanUpSmsRawTable(Context context) {
8646 ContentResolver resolver = context.getContentResolver();
8647 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8648 resolver.delete(uri, null, null);
8649 }
8650
Narayan Kamath1c496c22015-04-16 14:40:19 +01008651 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008652 public String getSimLocaleForSubscriber(int subId) {
8653 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008654
8655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8657
chen xu5d3637b2019-01-21 23:31:38 -08008658 final Phone phone = getPhone(subId);
8659 if (phone == null) {
8660 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008661 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663 final long identity = Binder.clearCallingIdentity();
8664 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008665 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8666 phone.getContext().getOpPackageName(),
8667 phone.getContext().getAttributionTag());
8668 if (info == null) {
8669 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8670 return null;
chen xu6291c472019-02-04 12:55:53 -08008671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672 // Try and fetch the locale from the carrier properties or from the SIM language
8673 // preferences (EF-PL and EF-LI)...
8674 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008676 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8677 if (localeFromDefaultSim != null) {
8678 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8679 if (DBG) log("Using locale from subId: " + subId + " locale: "
8680 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008681 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008682 } else {
8683 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008684 }
8685 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 // The SIM language preferences only store a language (e.g. fr = French), not an
8688 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8689 // the SIM and carrier preferences does not include a country we add the country
8690 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008691 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008692 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008693 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008694 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695 }
8696
8697 if (DBG) log("No locale found - returning null");
8698 return null;
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008702 }
8703
tom hsu0b59d292022-09-29 23:49:21 +08008704 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008705 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008706 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008707 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008708 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008709 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8710 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008711 Locale.forLanguageTag(localeTag).getCountry())) {
8712 return localeTag;
8713 }
8714 }
8715 return inputLocale.toLanguageTag();
8716 }
8717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008718 /**
8719 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8720 */
8721 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008722 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008723 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008724 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008725
Gary Jian3aa9a762022-01-24 16:41:19 +08008726 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8727 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008728
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008729 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008730 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8731 * representing the state of the modem.
8732 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008733 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8734 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008735 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008736 */
8737 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008738 public void requestModemActivityInfo(ResultReceiver result) {
8739 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008740
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008741 if (!mApp.getResources().getBoolean(
8742 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8744 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8745 }
joonhunshin4ac60942023-11-15 15:23:39 +00008746
vagdeviaf9a5b92018-08-15 16:01:53 -07008747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008748
8749 final long identity = Binder.clearCallingIdentity();
8750 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008751 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752 } finally {
8753 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008754 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008755 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008756
Gary Jian76280a42022-12-07 16:18:33 +08008757 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008758 // less than total activity duration.
8759 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8760 if (info == null) {
8761 return false;
8762 }
8763 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008764 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008765 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8766
Hall Liu49656c02020-10-09 19:00:11 -07008767 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8768
Siddharth Rayb8114062018-06-17 15:02:38 -07008769 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008770 && (info.getSleepTimeMillis() <= activityDurationMs)
8771 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008772 }
8773
Gary Jian3aa9a762022-01-24 16:41:19 +08008774 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8775 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8776 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8777 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8778
8779 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8780 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8781 }
8782
8783 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8784 mLastModemActivityInfo.setReceiveTimeMillis(
8785 rat,
8786 freq,
8787 info.getReceiveTimeMillis(rat, freq)
8788 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8789 }
8790
8791 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8792 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8793 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8794 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8795
8796 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8797 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8798 }
8799 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8800 mLastModemActivityInfo.setReceiveTimeMillis(
8801 rat,
8802 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8803 }
8804
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008805 /**
8806 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8807 * @param info recent ModemActivityInfo
8808 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008809 private void mergeModemActivityInfo(ModemActivityInfo info) {
8810 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008811 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008812 boolean matched;
8813 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8814 matched = false;
8815 int rat = info.getSpecificInfoRat(i);
8816 int freq = info.getSpecificInfoFrequencyRange(i);
8817 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8818 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8819 //if it already exists
8820 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8821 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8822 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8823 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8824 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8825 updateLastModemActivityInfo(info, rat, freq);
8826 matched = true;
8827 }
8828 } else {
8829 updateLastModemActivityInfo(info, rat);
8830 matched = true;
8831 }
8832 }
8833 }
8834
8835 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008836 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008837 new ActivityStatsTechSpecificInfo(
8838 rat,
8839 freq,
8840 info.getTransmitTimeMillis(rat, freq),
8841 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008842 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008843 }
8844 }
8845 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8846 mLastModemActivitySpecificInfo =
8847 new ActivityStatsTechSpecificInfo[merged.size()];
8848 merged.toArray(mLastModemActivitySpecificInfo);
8849
8850 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8851 mLastModemActivityInfo.setSleepTimeMillis(
8852 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008853 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008854 mLastModemActivityInfo.setIdleTimeMillis(
8855 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008856 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008857
8858 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008859 new ModemActivityInfo(
8860 mLastModemActivityInfo.getTimestampMillis(),
8861 mLastModemActivityInfo.getSleepTimeMillis(),
8862 mLastModemActivityInfo.getIdleTimeMillis(),
8863 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008864 }
8865
8866 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8867 ActivityStatsTechSpecificInfo[] info) {
8868 int infoSize = info.length;
8869 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8870 for (int i = 0; i < infoSize; i++) {
8871 ret[i] = new ActivityStatsTechSpecificInfo(
8872 info[i].getRat(), info[i].getFrequencyRange(),
8873 info[i].getTransmitTimeMillis(),
8874 (int) info[i].getReceiveTimeMillis());
8875 }
8876 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008877 }
8878
Jack Yu85bd38a2015-11-09 11:34:32 -08008879 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008880 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008881 */
8882 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008883 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8884 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8885 Phone phone = PhoneFactory.getPhone(slotIndex);
8886 if (phone == null) {
8887 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8888 return null;
8889 }
8890
8891 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008894 return null;
8895 }
8896
joonhunshin4ac60942023-11-15 15:23:39 +00008897 enforceTelephonyFeatureWithException(callingPackage,
8898 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8899
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008900 boolean hasFinePermission = false;
8901 boolean hasCoarsePermission = false;
8902 if (!renounceFineLocationAccess) {
8903 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8904 LocationAccessPolicy.checkLocationPermission(mApp,
8905 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8906 .setCallingPackage(callingPackage)
8907 .setCallingFeatureId(callingFeatureId)
8908 .setCallingPid(Binder.getCallingPid())
8909 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008910 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008911 .setLogAsInfo(true)
8912 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8913 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8914 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8915 .build());
8916 hasFinePermission =
8917 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8918 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008919
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008920 if (!renounceCoarseLocationAccess) {
8921 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8922 LocationAccessPolicy.checkLocationPermission(mApp,
8923 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8924 .setCallingPackage(callingPackage)
8925 .setCallingFeatureId(callingFeatureId)
8926 .setCallingPid(Binder.getCallingPid())
8927 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008928 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008929 .setLogAsInfo(true)
8930 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8931 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8932 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8933 .build());
8934 hasCoarsePermission =
8935 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8936 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008937
Jordan Liu0f2bc442020-11-18 16:47:37 -08008938 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008939 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008940 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8941 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008942 if (subInfo != null && !subInfo.isActive()) {
8943 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008944 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008945 }
8946
Hall Liuf19c44f2018-11-27 14:38:17 -08008947 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008948 boolean isCallingPackageDataService = phone.getDataServicePackages()
8949 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008950
8951 // Scrub out the location info in ServiceState depending on what level of access
8952 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008953 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008954 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8955 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 } finally {
8957 Binder.restoreCallingIdentity(identity);
8958 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008960
8961 /**
8962 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8963 *
8964 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8965 * voicemail ringtone.
8966 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8967 * PhoneAccount.
8968 */
8969 @Override
8970 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8972 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8977 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008978 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008985 }
8986
8987 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 * Sets the per-account voicemail ringtone.
8989 *
8990 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8991 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8992 *
8993 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8994 * voicemail ringtone.
8995 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8996 * PhoneAccount.
8997 */
8998 @Override
8999 public void setVoicemailRingtoneUri(String callingPackage,
9000 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009001 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009003 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9004 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9006 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9007 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009
joonhunshin4ac60942023-11-15 15:23:39 +00009010 enforceTelephonyFeatureWithException(callingPackage,
9011 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009017 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018 }
9019 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9020 } finally {
9021 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009022 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009023 }
9024
9025 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009026 * Returns whether vibration is set for voicemail notification in Phone settings.
9027 *
9028 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9029 * voicemail vibration setting.
9030 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9031 */
9032 @Override
9033 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9035 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9040 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009041 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009048 }
9049
Youhan Wange64578a2016-05-02 15:32:42 -07009050 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009051 * Sets the per-account voicemail vibration.
9052 *
9053 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9054 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9055 *
9056 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9057 * voicemail vibration setting.
9058 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9059 * specific PhoneAccount.
9060 */
9061 @Override
9062 public void setVoicemailVibrationEnabled(String callingPackage,
9063 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009064 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009066 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9067 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9069 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9070 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009071 }
9072
joonhunshin4ac60942023-11-15 15:23:39 +00009073 enforceTelephonyFeatureWithException(callingPackage,
9074 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009080 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009081 }
9082 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9083 } finally {
9084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009086 }
9087
9088 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009089 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9090 *
9091 * @throws SecurityException if the caller does not have the required permission
9092 */
arunvoddud7401012022-12-15 16:08:12 +00009093 @VisibleForTesting
9094 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009095 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009096 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009097 }
9098
9099 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009100 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9101 * permission.
9102 *
9103 * @throws SecurityException if the caller does not have the required permission
9104 */
9105 private void enforceSendSmsPermission() {
9106 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9107 }
9108
9109 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009110 * Make sure either called from same process as self (phone) or IPC caller has interact across
9111 * users permission.
9112 *
9113 * @throws SecurityException if the caller does not have the required permission
9114 */
9115 private void enforceInteractAcrossUsersPermission(String message) {
9116 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9117 }
9118
9119 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009120 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009121 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009122 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009123 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009124 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125 final long identity = Binder.clearCallingIdentity();
9126 try {
9127 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009128 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129 if (componentName == null) {
9130 throw new SecurityException(
9131 "Caller not current active visual voicemail package[null]");
9132 }
9133 String vvmPackage = componentName.getPackageName();
9134 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009135 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136 }
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009139 }
9140 }
9141
9142 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009143 * Return the application ID for the app type.
9144 *
9145 * @param subId the subscription ID that this request applies to.
9146 * @param appType the uicc app type.
9147 * @return Application ID for specificied app type, or null if no uicc.
9148 */
9149 @Override
9150 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009151 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009152
9153 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9154 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9155
Youhan Wange64578a2016-05-02 15:32:42 -07009156 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009157
9158 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009159 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009160 if (phone == null) {
9161 return null;
9162 }
9163 String aid = null;
9164 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009165 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166 .getApplicationByType(appType).getAid();
9167 } catch (Exception e) {
9168 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9169 }
9170 return aid;
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009173 }
Youhan Wange64578a2016-05-02 15:32:42 -07009174 }
9175
Youhan Wang4001d252016-05-11 10:29:41 -07009176 /**
9177 * Return the Electronic Serial Number.
9178 *
9179 * @param subId the subscription ID that this request applies to.
9180 * @return ESN or null if error.
9181 */
9182 @Override
9183 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009184 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009185 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186
9187 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009188 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009189 if (phone == null) {
9190 return null;
9191 }
9192 String esn = null;
9193 try {
9194 esn = phone.getEsn();
9195 } catch (Exception e) {
9196 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9197 }
9198 return esn;
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009201 }
Youhan Wang4001d252016-05-11 10:29:41 -07009202 }
9203
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009204 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009205 * Return the Preferred Roaming List Version.
9206 *
9207 * @param subId the subscription ID that this request applies to.
9208 * @return PRLVersion or null if error.
9209 */
9210 @Override
9211 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009212 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009213
9214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9215 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9216
Youhan Wang66ad5d72016-07-18 17:56:58 -07009217 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009218
9219 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009220 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221 if (phone == null) {
9222 return null;
9223 }
9224 String cdmaPrlVersion = null;
9225 try {
9226 cdmaPrlVersion = phone.getCdmaPrlVersion();
9227 } catch (Exception e) {
9228 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9229 }
9230 return cdmaPrlVersion;
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009233 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009234 }
9235
9236 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009237 * Get snapshot of Telephony histograms
9238 * @return List of Telephony histograms
9239 * @hide
9240 */
9241 @Override
9242 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9244 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 return RIL.getTelephonyRILTimingHistograms();
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009252 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009253
9254 /**
9255 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009256 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9257 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009258 * Require system privileges. In the future we may add this to carrier APIs.
9259 *
Michele Berionne482f8202018-11-27 18:57:59 -08009260 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009261 */
9262 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009263 @TelephonyManager.SetCarrierRestrictionResult
9264 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009265 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009266
9267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9268 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9269
vagdeviaf9a5b92018-08-15 16:01:53 -07009270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009271
Michele Berionne482f8202018-11-27 18:57:59 -08009272 if (carrierRestrictionRules == null) {
9273 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009274 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 final long identity = Binder.clearCallingIdentity();
9277 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009278 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009279 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280 } finally {
9281 Binder.restoreCallingIdentity(identity);
9282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009283 }
9284
9285 /**
9286 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009287 * Get the allowed carrier list and the excluded carrier list, including the priority between
9288 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009289 * Require system privileges. In the future we may add this to carrier APIs.
9290 *
Michele Berionne482f8202018-11-27 18:57:59 -08009291 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009292 */
9293 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009294 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009295 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009296
9297 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9298 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9299
vagdeviaf9a5b92018-08-15 16:01:53 -07009300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009301
9302 final long identity = Binder.clearCallingIdentity();
9303 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009304 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9305 if (response instanceof CarrierRestrictionRules) {
9306 return (CarrierRestrictionRules) response;
9307 }
9308 // Response is an Exception of some kind,
9309 // which is signalled to the user as a NULL retval
9310 return null;
9311 } catch (Exception e) {
9312 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9313 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009317 }
9318
fionaxu59545b42016-05-25 15:53:37 -07009319 /**
arunvoddud7401012022-12-15 16:08:12 +00009320 * Fetches the carrier restriction status of the device and sends the status to the caller
9321 * through the callback.
9322 *
9323 * @param callback The callback that will be used to send the result.
9324 * @throws SecurityException if the caller does not have the required permission/privileges or
9325 * the caller is not allowlisted.
9326 */
9327 @Override
9328 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009329 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009330 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009331 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9332 try {
9333 mApp.enforceCallingOrSelfPermission(
9334 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9335 functionName);
9336 } catch (SecurityException e) {
9337 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9338 functionName);
9339 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009340 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9341 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009342 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9343 throw new SecurityException("Not an authorized caller");
9344 }
9345 final long identity = Binder.clearCallingIdentity();
9346 try {
9347 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009348 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009349 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9350 } finally {
9351 Binder.restoreCallingIdentity(identity);
9352 }
9353 }
9354
arunvoddu567f2b42023-04-25 17:22:00 +00009355 @Override
9356 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9357 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9358 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9359 return allowListInfo.getShaIdList(pkgName, carrierId);
9360 }
9361
arunvoddud7401012022-12-15 16:08:12 +00009362 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009363 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009364 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009365 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009366 }
9367
9368 /**
fionaxu59545b42016-05-25 15:53:37 -07009369 * Action set from carrier signalling broadcast receivers to enable/disable radio
9370 * @param subId the subscription ID that this action applies to.
9371 * @param enabled control enable or disable radio.
9372 * {@hide}
9373 */
9374 @Override
9375 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9376 enforceModifyPermission();
9377 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009378
9379 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009380 if (phone == null) {
9381 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9382 return;
9383 }
9384 try {
9385 phone.carrierActionSetRadioEnabled(enabled);
9386 } catch (Exception e) {
9387 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009388 } finally {
9389 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009390 }
9391 }
9392
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009393 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009394 * Enable or disable Voice over NR (VoNR)
9395 * @param subId the subscription ID that this action applies to.
9396 * @param enabled enable or disable VoNR.
9397 * @return operation result.
9398 */
9399 @Override
9400 public int setVoNrEnabled(int subId, boolean enabled) {
9401 enforceModifyPermission();
9402 final Phone phone = getPhone(subId);
9403
9404 final long identity = Binder.clearCallingIdentity();
9405 if (phone == null) {
9406 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9407 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9408 }
9409
9410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9411 try {
9412 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9413 workSource);
9414 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009415
9416 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9417 if (DBG) {
9418 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9419 }
9420 SubscriptionManager.setSubscriptionProperty(
9421 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9422 (enabled ? "1" : "0"));
9423 }
9424
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009425 return result;
9426 } finally {
9427 Binder.restoreCallingIdentity(identity);
9428 }
9429 }
9430
9431 /**
9432 * Is voice over NR enabled
9433 * @return true if VoNR is enabled else false
9434 */
9435 @Override
9436 public boolean isVoNrEnabled(int subId) {
9437 enforceReadPrivilegedPermission("isVoNrEnabled");
9438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9439 final long identity = Binder.clearCallingIdentity();
9440 try {
9441 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9442 null, subId, workSource);
9443 if (DBG) log("isVoNrEnabled: " + isEnabled);
9444 return isEnabled;
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
9450 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009451 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9452 * network status based on which carrier apps could apply actions accordingly,
9453 * enable/disable default url handler for example.
9454 *
9455 * @param subId the subscription ID that this action applies to.
9456 * @param report control start/stop reporting the default network status.
9457 * {@hide}
9458 */
9459 @Override
9460 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9461 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009462
9463 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9464 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9465 "carrierActionReportDefaultNetworkStatus");
9466
fionaxu8da9cb12017-05-23 15:02:46 -07009467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468
9469 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009470 if (phone == null) {
9471 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9472 return;
9473 }
9474 try {
9475 phone.carrierActionReportDefaultNetworkStatus(report);
9476 } catch (Exception e) {
9477 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009478 } finally {
9479 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009480 }
9481 }
9482
9483 /**
fionaxud9622282017-07-17 17:51:30 -07009484 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9485 * @param subId the subscription ID that this action applies to.
9486 * {@hide}
9487 */
9488 @Override
9489 public void carrierActionResetAll(int subId) {
9490 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009491
9492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9493 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9494
fionaxud9622282017-07-17 17:51:30 -07009495 final Phone phone = getPhone(subId);
9496 if (phone == null) {
9497 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9498 return;
9499 }
9500 try {
9501 phone.carrierActionResetAll();
9502 } catch (Exception e) {
9503 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9504 }
9505 }
9506
9507 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009508 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9509 * bug report is being generated.
9510 */
9511 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009512 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009513 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9514 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009515 writer.println("Permission Denial: can't dump Phone from pid="
9516 + Binder.getCallingPid()
9517 + ", uid=" + Binder.getCallingUid()
9518 + "without permission "
9519 + android.Manifest.permission.DUMP);
9520 return;
9521 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009522 try {
9523 DumpsysHandler.dump(mApp, fd, writer, args);
9524 } catch (Exception e) {
9525 writer.println("Failed to dump phone information: " + e);
9526 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009527 }
Jack Yueb89b242016-06-22 13:27:47 -07009528
Brad Ebingerdac2f002018-04-03 15:17:52 -07009529 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009530 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9531 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9532 @NonNull String[] args) {
9533 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9534 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009535 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009536 }
9537
Jack Yueb89b242016-06-22 13:27:47 -07009538 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009539 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009540 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009541 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009542 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009543 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009544 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009545 */
9546 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009547 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009548 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009549 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9550 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9551 try {
9552 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009553 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009554 } catch (SecurityException se) {
9555 enforceModifyPermission();
9556 }
9557 } else {
9558 enforceModifyPermission();
9559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009560
joonhunshin4ac60942023-11-15 15:23:39 +00009561 enforceTelephonyFeatureWithException(callingPackage,
9562 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9563
Nate Myren116695d2024-02-09 09:36:01 -08009564 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009565 final long identity = Binder.clearCallingIdentity();
9566 try {
Nate Myren116695d2024-02-09 09:36:01 -08009567 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9568 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009569 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009570 callingUid, callingPackage, null, null);
9571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009572 Phone phone = getPhone(subId);
9573 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009574 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9575 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009576 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009577 phone.getDataSettingsManager().setDataEnabled(
9578 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009580 }
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009583 }
9584 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009585
9586 /**
9587 * Get Client request stats
9588 * @return List of Client Request Stats
9589 * @hide
9590 */
9591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009592 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9593 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009595 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009596 return null;
9597 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009598 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009600 final long identity = Binder.clearCallingIdentity();
9601 try {
9602 if (phone != null) {
9603 return phone.getClientRequestStats();
9604 }
9605
9606 return null;
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009610 }
9611
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009612 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009613 PackageManager pm;
9614 if (mFeatureFlags.hsumPackageManager()) {
9615 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9616 .getPackageManager();
9617 } else {
9618 pm = mApp.getPackageManager();
9619 }
9620
9621 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009622 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009623 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9624 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9625 // exception. ROOT_UID seems not to have a valid package name returned by
9626 // PackageManager, so just fake it here to avoid issues when running telephony shell
9627 // commands that plumb through the RIL as root, like so:
9628 // $ adb root
9629 // $ adb shell cmd phone ...
9630 packageName = "root";
9631 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009632 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009633 }
Jack Yueb4124c2017-02-16 15:32:43 -08009634
9635 /**
Grace Chen70990072017-03-24 17:21:30 -07009636 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009637 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009638 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009639 * @param state State of SIM (power down, power up, pass through)
9640 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9641 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9642 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009643 *
9644 **/
9645 @Override
Grace Chen70990072017-03-24 17:21:30 -07009646 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009647 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009648
9649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9650 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9651
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009652 Phone phone = PhoneFactory.getPhone(slotIndex);
9653
vagdeviaf9a5b92018-08-15 16:01:53 -07009654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009659 phone.setSimPowerState(state, null, workSource);
9660 }
9661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 /**
9667 * Set SIM card power state.
9668 *
9669 * @param slotIndex SIM slot id.
9670 * @param state State of SIM (power down, power up, pass through)
9671 * @param callback callback to trigger after success or failure
9672 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9674 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9675 *
9676 **/
9677 @Override
9678 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9679 IIntegerConsumer callback) {
9680 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009681
9682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9683 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9684 "setSimPowerStateForSlotWithCallback");
9685
Jordan Liu109698e2020-11-24 14:50:34 -08009686 Phone phone = PhoneFactory.getPhone(slotIndex);
9687
9688 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9689
9690 final long identity = Binder.clearCallingIdentity();
9691 try {
9692 if (phone != null) {
9693 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9694 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009695 }
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009698 }
9699 }
Shuo Qiandd210312017-04-12 22:11:33 +00009700
Tyler Gunn65d45c22017-06-05 11:22:26 -07009701 private boolean isUssdApiAllowed(int subId) {
9702 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009703 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009704 if (configManager == null) {
9705 return false;
9706 }
9707 PersistableBundle pb = configManager.getConfigForSubId(subId);
9708 if (pb == null) {
9709 return false;
9710 }
9711 return pb.getBoolean(
9712 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9713 }
9714
Shuo Qiandd210312017-04-12 22:11:33 +00009715 /**
Ling Mac28f0212023-03-24 16:07:15 -07009716 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009717 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009718 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009719 */
goneil9c5f4872017-12-05 14:07:56 -08009720 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009721 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009722 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009723
9724 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9725 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009727 final long identity = Binder.clearCallingIdentity();
9728 try {
Ling Mac28f0212023-03-24 16:07:15 -07009729 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009730 } finally {
9731 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009732 }
9733 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009734
9735 /**
9736 * Get the current signal strength information for the given subscription.
9737 * Because this information is not updated when the device is in a low power state
9738 * it should not be relied-upon to be current.
9739 * @param subId Subscription index
9740 * @return the most recent cached signal strength info from the modem
9741 */
9742 @Override
9743 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9745 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 Phone p = getPhone(subId);
9750 if (p == null) {
9751 return null;
9752 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009754 return p.getSignalStrength();
9755 } finally {
9756 Binder.restoreCallingIdentity(identity);
9757 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009758 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009759
Pengquan Meng77b7f132018-08-22 14:49:57 -07009760 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009761 * Get the current modem radio state for the given slot.
9762 * @param slotIndex slot index.
9763 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009764 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009765 * @return the current radio power state from the modem
9766 */
9767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009768 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009769 Phone phone = PhoneFactory.getPhone(slotIndex);
9770 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9772 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009773 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9774 }
9775
joonhunshin4ac60942023-11-15 15:23:39 +00009776 enforceTelephonyFeatureWithException(callingPackage,
9777 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9778
Chen Xuf792fd62018-10-17 17:54:36 +00009779 final long identity = Binder.clearCallingIdentity();
9780 try {
9781 return phone.getRadioPowerState();
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9787 }
9788
9789 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009790 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9791 *
9792 * <p>Requires one of the following permissions:
9793 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009794 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009795 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9796 * privileges.
9797 *
9798 * @param subId subscription id
9799 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9800 * {@code false}.
9801 */
9802 @Override
9803 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009804 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009805 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009806 try {
9807 mApp.enforceCallingOrSelfPermission(
9808 android.Manifest.permission.ACCESS_NETWORK_STATE,
9809 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009810 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009811 mApp.enforceCallingOrSelfPermission(
9812 permission.READ_BASIC_PHONE_STATE, functionName);
9813 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009814 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009815 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009816 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009817 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009818
joonhunshin4ac60942023-11-15 15:23:39 +00009819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9820 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9821
Pengquan Menga1bb6272018-09-06 09:59:22 -07009822 boolean isEnabled = false;
9823 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009824 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009825 Phone phone = getPhone(subId);
9826 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009827 } finally {
9828 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009829 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009830 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009831 }
9832
9833
9834 /**
9835 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9836 *
9837 * <p> Requires permission:
9838 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9839 * privileges.
9840 *
9841 * @param subId subscription id
9842 * @param isEnabled {@code true} means enable, {@code false} means disable.
9843 */
9844 @Override
9845 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9847 mApp, subId, "setDataRoamingEnabled");
9848
joonhunshin4ac60942023-11-15 15:23:39 +00009849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9850 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9851
Pengquan Menga1bb6272018-09-06 09:59:22 -07009852 final long identity = Binder.clearCallingIdentity();
9853 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009854 Phone phone = getPhone(subId);
9855 if (phone != null) {
9856 phone.setDataRoamingEnabled(isEnabled);
9857 }
9858 } finally {
9859 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009860 }
9861 }
9862
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009863 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009864 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009865 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009866 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009867 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009868
joonhunshin4ac60942023-11-15 15:23:39 +00009869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9870 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9871
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009872 boolean isAllowed = true;
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009875 Phone phone = getPhone(subId);
9876 if (phone != null) {
9877 isAllowed = phone.isCspPlmnEnabled();
9878 }
9879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 return isAllowed;
9883 }
9884
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009885 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9886 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009887 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009888 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009890 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9891 if (phone == null) {
9892 return false;
9893 }
9894 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9895 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9896 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009897 }
9898
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009899 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009900 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009901 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009902 mApp.getSystemService(AppOpsManager.class)
9903 .checkPackage(Binder.getCallingUid(), callingPackage);
9904
Jordan Liu1e142fc2019-04-22 15:10:43 -07009905 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009906 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009907 try {
9908 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009909 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009910 } catch (SecurityException e) {
9911 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9912 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009913 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009914 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009915 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009916 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009917 }
joonhunshin4ac60942023-11-15 15:23:39 +00009918
9919 enforceTelephonyFeatureWithException(callingPackage,
9920 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9921
sandeepjsb6c87872021-09-27 15:34:44 +00009922 // checking compatibility, if calling app's target SDK is T and beyond.
9923 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9924 Binder.getCallingUid())) {
9925 isIccIdAccessRestricted = true;
9926 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009927 final long identity = Binder.clearCallingIdentity();
9928 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009929 UiccController uiccController = UiccController.getInstance();
9930 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009931 if (hasReadPermission) {
9932 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009933 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009934
9935 // Remove private info if the caller doesn't have access
9936 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9937 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009938 //setting the value after compatibility check
9939 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009940 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9941 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009942 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009943 if (card == null) {
9944 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009945 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009946 continue;
9947 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009948 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9949 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009950 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009951 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009952 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009953 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9954 for (UiccPortInfo portInfo : portInfos) {
9955 UiccPort port = uiccController.getUiccPortForSlot(
9956 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9957 if (port == null) {
9958 // assume no access if port is null
9959 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9960 continue;
9961 }
9962 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9963 uiccPortInfos.add(portInfo);
9964 } else {
9965 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9966 }
9967 }
9968 filteredInfos.add(new UiccCardInfo(
9969 cardInfo.isEuicc(),
9970 cardInfo.getCardId(),
9971 null,
9972 cardInfo.getPhysicalSlotIndex(),
9973 cardInfo.isRemovable(),
9974 cardInfo.isMultipleEnabledProfilesSupported(),
9975 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009976 }
9977 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009978 } finally {
9979 Binder.restoreCallingIdentity(identity);
9980 }
9981 }
9982
sandeepjsb6c87872021-09-27 15:34:44 +00009983 /**
9984 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9985 * generally private and require carrier privileges to view.
9986 *
9987 * @hide
9988 */
9989 @NonNull
9990 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9991 List<UiccPortInfo> portinfo = new ArrayList<>();
9992 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9993 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9994 }
9995 return new UiccCardInfo(
9996 cardInfo.isEuicc(),
9997 cardInfo.getCardId(),
9998 null,
9999 cardInfo.getPhysicalSlotIndex(),
10000 cardInfo.isRemovable(),
10001 cardInfo.isMultipleEnabledProfilesSupported(),
10002 portinfo
10003 );
10004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010005
sandeepjsb6c87872021-09-27 15:34:44 +000010006 /**
10007 * @hide
10008 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10009 * These values are generally private and require carrier privileges to view.
10010 */
10011 @NonNull
10012 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10013 return new UiccPortInfo(
10014 UiccPortInfo.ICCID_REDACTED,
10015 portInfo.getPortIndex(),
10016 portInfo.getLogicalSlotIndex(),
10017 portInfo.isActive()
10018 );
10019 }
10020 @Override
10021 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010022 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010023 mApp.getSystemService(AppOpsManager.class)
10024 .checkPackage(Binder.getCallingUid(), callingPackage);
10025
sandeepjsb6c87872021-09-27 15:34:44 +000010026 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010027
Aman Guptaf3c90b32022-03-17 04:54:16 +000010028 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10029 // we are reading iccId which is PII data.
10030 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010031
joonhunshin4ac60942023-11-15 15:23:39 +000010032 enforceTelephonyFeatureWithException(callingPackage,
10033 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10034
sandeepjsb6c87872021-09-27 15:34:44 +000010035 // checking compatibility, if calling app's target SDK is T and beyond.
10036 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10037 Binder.getCallingUid())) {
10038 isLogicalSlotAccessRestricted = true;
10039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010040 final long identity = Binder.clearCallingIdentity();
10041 try {
10042 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010043 if (slots == null || slots.length == 0) {
10044 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010045 return null;
10046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010047 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10048 for (int i = 0; i < slots.length; i++) {
10049 UiccSlot slot = slots[i];
10050 if (slot == null) {
10051 continue;
10052 }
10053
Jordan Liu7be7e652019-05-06 18:55:02 +000010054 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010055 UiccCard card = slot.getUiccCard();
10056 if (card != null) {
10057 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010058 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010059 cardId = slot.getEid();
10060 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010061 // If cardId is null, use iccId of default port as cardId.
10062 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010064 }
10065
Jordan Liu857451f2019-05-09 16:35:35 -070010066 if (cardId != null) {
10067 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10068 // if cardId is an EID, it's all digits so this is fine
10069 cardId = IccUtils.stripTrailingFs(cardId);
10070 }
10071
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010072 int cardState = 0;
10073 switch (slot.getCardState()) {
10074 case CARDSTATE_ABSENT:
10075 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10076 break;
10077 case CARDSTATE_PRESENT:
10078 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10079 break;
10080 case CARDSTATE_ERROR:
10081 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10082 break;
10083 case CARDSTATE_RESTRICTED:
10084 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10085 break;
10086 default:
10087 break;
10088
10089 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010090 List<UiccPortInfo> portInfos = new ArrayList<>();
10091 int[] portIndexes = slot.getPortList();
10092 for (int portIdx : portIndexes) {
10093 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010094 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010095 portInfos.add(new UiccPortInfo(iccId, portIdx,
10096 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010098 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010099 slot.isEuicc(),
10100 cardId,
10101 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010102 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010103 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010104 //setting the value after compatibility check
10105 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010106 }
10107 return infos;
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010110 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010111 }
10112
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010113 /* Returns null if doesn't have read permission or carrier privilege access. */
10114 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10115 boolean hasReadPermission) {
10116 String iccId = slot.getIccId(portIndex);
10117 if (hasReadPermission) { // if has read permission
10118 return iccId;
10119 } else {
10120 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10121 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10122 // if no read permission, checking carrier privilege access
10123 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10124 return iccId;
10125 }
10126 }
10127 }
10128 // No read permission or carrier privilege access.
10129 return UiccPortInfo.ICCID_REDACTED;
10130 }
10131
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010132 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010133 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010134 public boolean switchSlots(int[] physicalSlots) {
10135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010136
joonhunshin4ac60942023-11-15 15:23:39 +000010137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10138 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10139
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010140 final long identity = Binder.clearCallingIdentity();
10141 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010142 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10143 for (int i = 0; i < physicalSlots.length; i++) {
10144 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10145 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10146 physicalSlots[i], i));
10147 }
10148 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010149 } finally {
10150 Binder.restoreCallingIdentity(identity);
10151 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010152 }
Jack Yu4c988042018-02-27 15:30:01 -080010153
10154 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010155 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10156 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10157 enforceModifyPermission();
10158
joonhunshin4ac60942023-11-15 15:23:39 +000010159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10160 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10161
sandeepjsb6c87872021-09-27 15:34:44 +000010162 final long identity = Binder.clearCallingIdentity();
10163 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010164 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010171 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010172 enforceTelephonyFeatureWithException(callingPackage,
10173 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10174
Jordan Liu7de49fa2018-12-06 14:48:49 -080010175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 return UiccController.getInstance().getCardIdForDefaultEuicc();
10178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
10182
Pengquan Meng85728fb2018-03-12 16:31:21 -070010183 /**
goneil47ffb6e2018-04-06 15:40:58 -070010184 * A test API to reload the UICC profile.
10185 *
10186 * <p>Requires that the calling app has permission
10187 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10188 * @hide
10189 */
10190 @Override
10191 public void refreshUiccProfile(int subId) {
10192 enforceModifyPermission();
10193
10194 final long identity = Binder.clearCallingIdentity();
10195 try {
10196 Phone phone = getPhone(subId);
10197 if (phone == null) {
10198 return;
10199 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010200 UiccPort uiccPort = phone.getUiccPort();
10201 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010202 return;
10203 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010204 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010205 if (uiccProfile == null) {
10206 return;
10207 }
10208 uiccProfile.refresh();
10209 } finally {
10210 Binder.restoreCallingIdentity(identity);
10211 }
10212 }
10213
10214 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010215 * Returns false if the mobile data is disabled by default, otherwise return true.
10216 */
10217 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010218 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010219 }
10220
10221 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010222 * Returns the default network type for the given {@code subId}, if the default network type is
10223 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10224 */
10225 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010226 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010227 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010228 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10229 return list.get(phoneId);
10230 }
10231 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010232 }
fionaxua13278b2018-03-21 00:08:13 -070010233
10234 @Override
10235 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010236 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 final Phone phone = getPhone(subId);
10242 if (phone == null) {
10243 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10244 return;
10245 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010246 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10247 if (cpt != null) {
10248 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10249 }
10250 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010251 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10252 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010253 if (carrierPrivilegeRules == null) {
10254 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10255 } else {
10256 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010258 } finally {
10259 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010260 }
fionaxua13278b2018-03-21 00:08:13 -070010261 }
10262
10263 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010264 public void setCarrierServicePackageOverride(
10265 int subId, String carrierServicePackage, String callingPackage) {
10266 TelephonyPermissions.enforceShellOnly(
10267 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10268
Benedict Wong66477622023-02-03 23:30:57 +000010269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 final Phone phone = getPhone(subId);
10272 if (phone == null || phone.getSubId() != subId) {
10273 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10274 throw new IllegalArgumentException("No phone for subid");
10275 }
10276 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10277 if (cpt == null) {
10278 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10279 throw new IllegalStateException("No CPT for phone");
10280 }
10281 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
10284 }
10285 }
10286
10287 @Override
fionaxua13278b2018-03-21 00:08:13 -070010288 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010289 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010290
10291 final long identity = Binder.clearCallingIdentity();
10292 try {
10293 final Phone phone = getPhone(subId);
10294 if (phone == null) {
10295 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10296 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10297 }
10298 return phone.getCarrierIdListVersion();
10299 } finally {
10300 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010301 }
fionaxua13278b2018-03-21 00:08:13 -070010302 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010303
10304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010305 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10306 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010308 mApp, subId, callingPackage, callingFeatureId,
10309 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010310 return -1;
10311 }
10312
10313 final long identity = Binder.clearCallingIdentity();
10314 try {
10315 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010320
10321 @Override
10322 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010325 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010326
joonhunshin4ac60942023-11-15 15:23:39 +000010327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10328 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10329
Pengquan Menga1bb6272018-09-06 09:59:22 -070010330 final long identity = Binder.clearCallingIdentity();
10331 try {
10332 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10333 } finally {
10334 Binder.restoreCallingIdentity(identity);
10335 }
10336 }
10337
10338 @Override
10339 public boolean setCdmaRoamingMode(int subId, int mode) {
10340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10341 mApp, subId, "setCdmaRoamingMode");
10342
joonhunshin4ac60942023-11-15 15:23:39 +000010343 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10344 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10345
Pengquan Menga1bb6272018-09-06 09:59:22 -070010346 final long identity = Binder.clearCallingIdentity();
10347 try {
10348 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010355 public int getCdmaSubscriptionMode(int subId) {
10356 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010357 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010358 mApp, subId, "getCdmaSubscriptionMode");
10359
joonhunshin4ac60942023-11-15 15:23:39 +000010360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10361 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10362
Sarah Chinbaab1432020-10-28 13:46:24 -070010363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010372 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10374 mApp, subId, "setCdmaSubscriptionMode");
10375
joonhunshin4ac60942023-11-15 15:23:39 +000010376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10377 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10378
Pengquan Menga1bb6272018-09-06 09:59:22 -070010379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010386
sqianc5eccab2018-10-19 18:46:41 -070010387 @Override
sqian8c685422019-02-22 15:55:18 -080010388 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010389 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010391 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10392 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010393 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10394 }
joonhunshin4ac60942023-11-15 15:23:39 +000010395
10396 enforceTelephonyFeatureWithException(callingPackage,
10397 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10398
sqian11b7a0e2018-12-05 18:48:28 -080010399 final long identity = Binder.clearCallingIdentity();
10400 try {
sqian854d44b2018-12-12 16:48:18 -080010401 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10402 for (Phone phone: PhoneFactory.getPhones()) {
10403 if (phone.getEmergencyNumberTracker() != null
10404 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10405 emergencyNumberListInternal.put(
10406 phone.getSubId(),
10407 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10408 }
sqian11b7a0e2018-12-05 18:48:28 -080010409 }
sqian854d44b2018-12-12 16:48:18 -080010410 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
sqianc5eccab2018-10-19 18:46:41 -070010414 }
10415
10416 @Override
sqian8c685422019-02-22 15:55:18 -080010417 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010418 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010419 if (!exactMatch) {
10420 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010421 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010422 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010423 }
joonhunshin4ac60942023-11-15 15:23:39 +000010424
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010425 if (!mApp.getResources().getBoolean(
10426 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10428 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10429 }
joonhunshin4ac60942023-11-15 15:23:39 +000010430
sqian11b7a0e2018-12-05 18:48:28 -080010431 final long identity = Binder.clearCallingIdentity();
10432 try {
sqian854d44b2018-12-12 16:48:18 -080010433 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010434 //Note: we ignore passed in param exactMatch. We can remove it once
10435 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010436 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010437 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010438 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010439 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010440 }
sqian11b7a0e2018-12-05 18:48:28 -080010441 }
10442 return false;
10443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 }
10447
sqianf4ca7ed2019-01-15 18:32:07 -080010448 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010449 * Start emergency callback mode for GsmCdmaPhone for testing.
10450 */
10451 @Override
10452 public void startEmergencyCallbackMode() {
10453 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10454 "startEmergencyCallbackMode");
10455 enforceModifyPermission();
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 for (Phone phone : PhoneFactory.getPhones()) {
10459 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10460 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10461 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10462 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10463 gsmCdmaPhone.obtainMessage(
10464 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10465 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10466 }
10467 }
10468 } finally {
10469 Binder.restoreCallingIdentity(identity);
10470 }
10471 }
10472
10473 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010474 * Update emergency number list for test mode.
10475 */
10476 @Override
10477 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10479 "updateEmergencyNumberListTestMode");
10480
10481 final long identity = Binder.clearCallingIdentity();
10482 try {
10483 for (Phone phone: PhoneFactory.getPhones()) {
10484 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10485 if (tracker != null) {
10486 tracker.executeEmergencyNumberTestModeCommand(action, num);
10487 }
10488 }
10489 } finally {
10490 Binder.restoreCallingIdentity(identity);
10491 }
10492 }
10493
10494 /**
10495 * Get the full emergency number list for test mode.
10496 */
10497 @Override
10498 public List<String> getEmergencyNumberListTestMode() {
10499 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10500 "getEmergencyNumberListTestMode");
10501
10502 final long identity = Binder.clearCallingIdentity();
10503 try {
10504 Set<String> emergencyNumbers = new HashSet<>();
10505 for (Phone phone: PhoneFactory.getPhones()) {
10506 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10507 if (tracker != null) {
10508 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10509 emergencyNumbers.add(num.getNumber());
10510 }
10511 }
10512 }
10513 return new ArrayList<>(emergencyNumbers);
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
chen xud6b45bd2018-10-30 22:27:10 -070010519 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010520 public int getEmergencyNumberDbVersion(int subId) {
10521 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10522
joonhunshin4ac60942023-11-15 15:23:39 +000010523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10524 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10525
Shuo Qian3b6ee772019-11-13 17:43:31 -080010526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 final Phone phone = getPhone(subId);
10529 if (phone == null) {
10530 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10531 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10532 }
10533 return phone.getEmergencyNumberDbVersion();
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
10538
10539 @Override
10540 public void notifyOtaEmergencyNumberDbInstalled() {
10541 enforceModifyPermission();
10542
joonhunshin4ac60942023-11-15 15:23:39 +000010543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10544 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10545
Shuo Qian3b6ee772019-11-13 17:43:31 -080010546 final long identity = Binder.clearCallingIdentity();
10547 try {
10548 for (Phone phone: PhoneFactory.getPhones()) {
10549 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10550 if (tracker != null) {
10551 tracker.updateOtaEmergencyNumberDatabase();
10552 }
10553 }
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010560 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010561 enforceActiveEmergencySessionPermission();
10562
joonhunshin4ac60942023-11-15 15:23:39 +000010563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10564 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10565
Shuo Qian3b6ee772019-11-13 17:43:31 -080010566 final long identity = Binder.clearCallingIdentity();
10567 try {
10568 for (Phone phone: PhoneFactory.getPhones()) {
10569 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10570 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010571 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10572 }
10573 }
10574 } finally {
10575 Binder.restoreCallingIdentity(identity);
10576 }
10577 }
10578
10579 @Override
10580 public void resetOtaEmergencyNumberDbFilePath() {
10581 enforceActiveEmergencySessionPermission();
10582
joonhunshin4ac60942023-11-15 15:23:39 +000010583 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10584 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10585
Shuo Qianc373f112020-03-05 17:55:34 -080010586 final long identity = Binder.clearCallingIdentity();
10587 try {
10588 for (Phone phone: PhoneFactory.getPhones()) {
10589 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10590 if (tracker != null) {
10591 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010592 }
10593 }
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010600 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10601 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10602 Phone phone = getPhone(subId);
10603 if (phone == null) {
10604 return null;
10605 }
10606 final long identity = Binder.clearCallingIdentity();
10607 try {
10608 UiccProfile profile = UiccController.getInstance()
10609 .getUiccProfileForPhone(phone.getPhoneId());
10610 if (profile != null) {
10611 return profile.getCertsFromCarrierPrivilegeAccessRules();
10612 }
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 return null;
10617 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010618
10619 /**
10620 * Enable or disable a modem stack.
10621 */
10622 @Override
10623 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10624 enforceModifyPermission();
10625
joonhunshin4ac60942023-11-15 15:23:39 +000010626 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10627 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10628
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010629 final long identity = Binder.clearCallingIdentity();
10630 try {
10631 Phone phone = PhoneFactory.getPhone(slotIndex);
10632 if (phone == null) {
10633 return false;
10634 } else {
10635 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10636 }
10637 } finally {
10638 Binder.restoreCallingIdentity(identity);
10639 }
10640 }
Michelecea4cf22018-12-21 15:00:11 -080010641
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010642 /**
10643 * Whether a modem stack is enabled or not.
10644 */
10645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010646 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10647 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010648 Phone phone = PhoneFactory.getPhone(slotIndex);
10649 if (phone == null) return false;
10650
10651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010652 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10653 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010654 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10655 }
10656
joonhunshin4ac60942023-11-15 15:23:39 +000010657 enforceTelephonyFeatureWithException(callingPackage,
10658 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10659
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010660 final long identity = Binder.clearCallingIdentity();
10661 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010662 try {
10663 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10664 } catch (NoSuchElementException ex) {
10665 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10666 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010667 } finally {
10668 Binder.restoreCallingIdentity(identity);
10669 }
10670 }
10671
Michelecea4cf22018-12-21 15:00:11 -080010672 @Override
Michele0ea7d782019-03-19 14:58:42 -070010673 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010674 enforceModifyPermission();
10675
joonhunshin4ac60942023-11-15 15:23:39 +000010676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10677 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10678
Michelecea4cf22018-12-21 15:00:11 -080010679 final long identity = Binder.clearCallingIdentity();
10680 try {
10681 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010682 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010683 .commit();
10684 } finally {
10685 Binder.restoreCallingIdentity(identity);
10686 }
10687 }
10688
10689 @Override
Michele0ea7d782019-03-19 14:58:42 -070010690 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010691 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010693 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10694 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010695 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010696 }
Michelecea4cf22018-12-21 15:00:11 -080010697
joonhunshin4ac60942023-11-15 15:23:39 +000010698 enforceTelephonyFeatureWithException(callingPackage,
10699 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10700
Michelecea4cf22018-12-21 15:00:11 -080010701 final long identity = Binder.clearCallingIdentity();
10702 try {
Michele0ea7d782019-03-19 14:58:42 -070010703 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010704 } finally {
10705 Binder.restoreCallingIdentity(identity);
10706 }
10707 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010708
Michele0ea7d782019-03-19 14:58:42 -070010709 @TelephonyManager.IsMultiSimSupportedResult
10710 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010711 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10712 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10713 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010714 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10715 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010716 }
10717 // Check if the hardware supports multisim functionality. If usage of multisim is not
10718 // supported by the modem, indicate that it is restricted.
10719 PhoneCapability staticCapability =
10720 mPhoneConfigurationManager.getStaticPhoneCapability();
10721 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010722 loge("isMultiSimSupportedInternal: no static configuration available");
10723 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010724 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010725 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010726 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10727 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010728 }
10729 // Check if support of multiple SIMs is restricted by carrier
10730 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010731 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010732 }
10733
Michele0ea7d782019-03-19 14:58:42 -070010734 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010735 }
10736
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010737 /**
10738 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010739 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10740 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10741 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010742 * @param numOfSims number of active sims we want to switch to
10743 */
10744 @Override
10745 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010746 if (numOfSims == 1) {
10747 enforceModifyPermission();
10748 } else {
10749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10750 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10751 }
joonhunshin4ac60942023-11-15 15:23:39 +000010752
10753 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10754 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10755
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010756 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010757
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010758 try {
Michele30b57b22019-03-01 12:01:14 -080010759 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010760 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010761 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10762 return;
10763 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010764 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10765 } finally {
10766 Binder.restoreCallingIdentity(identity);
10767 }
10768 }
10769
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010770 @Override
10771 public boolean isApplicationOnUicc(int subId, int appType) {
10772 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010773
10774 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10775 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10776
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010777 Phone phone = getPhone(subId);
10778 if (phone == null) {
10779 return false;
10780 }
10781 final long identity = Binder.clearCallingIdentity();
10782 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010783 UiccPort uiccPort = phone.getUiccPort();
10784 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010785 return false;
10786 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010787 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010788 if (uiccProfile == null) {
10789 return false;
10790 }
10791 if (TelephonyManager.APPTYPE_SIM <= appType
10792 && appType <= TelephonyManager.APPTYPE_ISIM) {
10793 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10794 }
10795 return false;
10796 } finally {
10797 Binder.restoreCallingIdentity(identity);
10798 }
10799 }
10800
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010801 /**
chen xub4baa772019-04-03 10:23:41 -070010802 * Get whether making changes to modem configurations will trigger reboot.
10803 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010804 */
10805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010806 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10807 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010809 mApp, subId, callingPackage, callingFeatureId,
10810 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010811 return false;
10812 }
joonhunshin4ac60942023-11-15 15:23:39 +000010813
10814 enforceTelephonyFeatureWithException(callingPackage,
10815 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10816 "doesSwitchMultiSimConfigTriggerReboot");
10817
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
Nathan Harold29f5f052019-02-15 13:41:57 -080010826 private void updateModemStateMetrics() {
10827 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10828 // TODO: check the state for each modem if the api is ready.
10829 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10830 }
10831
Pengquan Meng3889a572019-01-23 11:16:29 -080010832 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010833 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010834 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010835 // Verify that the callingPackage belongs to the calling UID
10836 mApp.getSystemService(AppOpsManager.class)
10837 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010838
10839 enforceTelephonyFeatureWithException(callingPackage,
10840 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10841
Pengquan Meng3889a572019-01-23 11:16:29 -080010842 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010843 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010844 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010845 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10846 if (slotInfos != null) {
10847 for (int i = 0; i < slotInfos.length; i++) {
10848 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10849 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10850 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10851 portInfo.getLogicalSlotIndex()));
10852 }
10853 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010854 }
10855 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010856 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010857 } finally {
10858 Binder.restoreCallingIdentity(identity);
10859 }
10860 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010861
10862 /**
10863 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010864 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010865 */
jimsunf9ec1622022-09-13 21:18:43 +080010866 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010867 @Override
10868 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010869 return getHalVersion(HAL_SERVICE_RADIO);
10870 }
10871
10872 /**
10873 * Get the HAL Version of a specific service
10874 */
10875 @Override
10876 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010877 Phone phone = getDefaultPhone();
10878 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010879 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010880 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10881 return hv.major * 100 + hv.minor;
10882 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010883
10884 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010885 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010886 *
10887 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010888 */
10889 @Override
sangyun097dcf72024-01-04 10:35:49 +090010890 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010891 if (mFeatureFlags.hsumPackageManager()) {
10892 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10893 Binder.getCallingUserHandle(), 0).getPackageManager();
10894 if (pm == null) return null;
10895 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10896 return (callingUids == null) ? null : callingUids[0];
10897 }
10898 if (mPackageManager == null) return null;
10899 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10900 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010901 }
10902
10903 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010904 * @return The calling package name or "phone" if the caller is the phone process. This is done
10905 * because multiple Phone has multiple packages in it and the first element in the array is not
10906 * actually always the caller.
10907 * Note: This is for logging purposes only and should not be used for security checks.
10908 */
10909 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010910 PackageManager pm;
10911 if (mFeatureFlags.hsumPackageManager()) {
10912 pm = mApp.getBaseContext().createContextAsUser(
10913 Binder.getCallingUserHandle(), 0).getPackageManager();
10914 } else {
10915 pm = mApp.getPackageManager();
10916 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010917 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10918 if (uidName != null && !uidName.isEmpty()) return uidName;
10919 return getCurrentPackageName();
10920 }
10921
10922 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010923 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10924 * corresponding network requests on a subId.
10925 *
10926 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010927 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010928 * 2) APN is un-metered for this subscription, or
10929 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010930 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010931 *
10932 * @return whether data is allowed for a apn type.
10933 *
10934 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010935 */
10936 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010937 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010938 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10939 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010940
joonhunshin4ac60942023-11-15 15:23:39 +000010941 enforceTelephonyFeatureWithException(callingPackage,
10942 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10943
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010944 // Now that all security checks passes, perform the operation as ourselves.
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 Phone phone = getPhone(subId);
10948 if (phone == null) return false;
10949
Jack Yu27422a52022-03-21 10:38:05 -070010950 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010951 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010952 isMetered = phone.getDataNetworkController().getDataConfigManager()
10953 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10954 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010955 isDataEnabled = (phone.getDataSettingsManager() != null)
10956 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010957 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010964 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010965 enforceReadPrivilegedPermission("isApnMetered");
10966
joonhunshin4ac60942023-11-15 15:23:39 +000010967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10968 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10969
Malcolm Chene5ad5792019-04-18 13:51:02 -070010970 // Now that all security checks passes, perform the operation as ourselves.
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
10973 Phone phone = getPhone(subId);
10974 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010975 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10976 DataUtils.apnTypeToNetworkCapability(apnType),
10977 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010978 } finally {
10979 Binder.restoreCallingIdentity(identity);
10980 }
10981 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010982
10983 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010984 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10985 int subscriptionId, IBooleanConsumer resultCallback) {
10986 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010987
10988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10989 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10990
Hall Liu73f5d362020-01-20 13:42:00 -080010991 long token = Binder.clearCallingIdentity();
10992 try {
10993 Phone phone = getPhone(subscriptionId);
10994 if (phone == null) {
10995 try {
10996 if (resultCallback != null) {
10997 resultCallback.accept(false);
10998 }
10999 } catch (RemoteException e) {
11000 // ignore
11001 }
11002 return;
11003 }
11004 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11005 Pair.create(specifiers, (x) -> {
11006 try {
11007 if (resultCallback != null) {
11008 resultCallback.accept(x);
11009 }
11010 } catch (RemoteException e) {
11011 // ignore
11012 }
11013 });
11014 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11015 } finally {
11016 Binder.restoreCallingIdentity(token);
11017 }
11018 }
11019
11020 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011021 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11022 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011023 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011024 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011025
11026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11027 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11028
Sarah Chin679c08a2020-11-18 13:39:35 -080011029 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11030 final long identity = Binder.clearCallingIdentity();
11031 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011032 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11033 if (result instanceof IllegalStateException) {
11034 throw (IllegalStateException) result;
11035 }
11036 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011037 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11038 return specifiers;
11039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
11043
11044 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011045 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011046 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011047
11048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11049 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11050
Jack Yu8b766fc2022-03-21 09:42:33 -070011051 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011052 }
11053
11054 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011055 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11056 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011057 if (callingPackage == null) {
11058 callingPackage = getCurrentPackageName();
11059 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011060 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11061 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011062 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11063 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011064 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11065 }
11066 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11067 Intent intent = new Intent();
11068 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11069 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11070 // Bring up choose default SMS subscription dialog right now
11071 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11072 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011073 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011074 }
chen xud5ca2d52019-05-28 15:20:57 -070011075
11076 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011077 public void showSwitchToManagedProfileDialog() {
11078 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011079 try {
11080 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11081 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11082 // for work telephony.
11083 Intent intent = new Intent(Intent.ACTION_SENDTO);
11084 intent.setData(Uri.parse("smsto:"));
11085 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011086 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011087 } catch (ActivityNotFoundException e) {
11088 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11089 Intent intent = new Intent();
11090 intent.setClass(mApp, ErrorDialogActivity.class);
11091 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011092 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011093 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011094 }
11095
11096 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011097 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11099 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11100
chen xud5ca2d52019-05-28 15:20:57 -070011101 //TODO investigate if this API should require proper permission check in R b/133791609
11102 final long identity = Binder.clearCallingIdentity();
11103 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011104 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11105 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11106 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11107 return carrierUAProfUrl;
11108 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011109 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11110 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011111 } finally {
11112 Binder.restoreCallingIdentity(identity);
11113 }
11114 }
11115
11116 @Override
11117 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11119 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11120
chen xud5ca2d52019-05-28 15:20:57 -070011121 //TODO investigate if this API should require proper permission check in R b/133791609
11122 final long identity = Binder.clearCallingIdentity();
11123 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011124 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11125 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11126 if (!TextUtils.isEmpty(carrierUserAgent)) {
11127 return carrierUserAgent;
11128 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011129 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11130 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011131 } finally {
11132 Binder.restoreCallingIdentity(identity);
11133 }
11134 }
Jack Yub07d4972019-05-28 16:12:25 -070011135
11136 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011137 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11138 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011139
joonhunshin4ac60942023-11-15 15:23:39 +000011140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11141 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11142
Jack Yub07d4972019-05-28 16:12:25 -070011143 final long identity = Binder.clearCallingIdentity();
11144 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011145 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011146 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011147
Ling Maf188d502022-09-16 15:22:36 -070011148 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011149 } finally {
11150 Binder.restoreCallingIdentity(identity);
11151 }
11152 }
11153
11154 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011155 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011156 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011157 enforceModifyPermission();
11158
joonhunshin4ac60942023-11-15 15:23:39 +000011159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11160 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11161
changbettyd5c246e2019-12-24 15:40:37 +080011162 final long identity = Binder.clearCallingIdentity();
11163 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011164 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011165 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011166
Ling Maf188d502022-09-16 15:22:36 -070011167 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011168 } finally {
11169 Binder.restoreCallingIdentity(identity);
11170 }
11171 }
11172
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011173 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011174 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011175 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11176 * otherwise.
11177 */
11178 @Override
11179 public void setCepEnabled(boolean isCepEnabled) {
11180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11181
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11185 for (Phone phone : PhoneFactory.getPhones()) {
11186 Phone defaultPhone = phone.getImsPhone();
11187 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11188 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11189 ImsPhoneCallTracker imsPhoneCallTracker =
11190 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11191 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11192 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11193 + imsPhone.getMsisdn());
11194 }
11195 }
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
allenwtsu46dcc572020-01-08 18:24:03 +080011200
11201 /**
11202 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11203 *
11204 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11205 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11206 * before being read.
11207 */
11208 @Override
11209 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11210 isCompressed) {
11211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11212 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011213 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11214 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11215 }
joonhunshin4ac60942023-11-15 15:23:39 +000011216
11217 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11218 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11219 Binder.getCallingUserHandle())) {
11220 if (!isImsAvailableOnDevice()) {
11221 // ProvisioningManager can not handle ServiceSpecificException.
11222 // Throw the IllegalStateException and annotate ProvisioningManager.
11223 throw new IllegalStateException("IMS not available on device.");
11224 }
11225 } else {
11226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11227 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11228 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011229 }
11230
11231 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011232 try {
Hui Wang761a6682020-10-31 05:12:53 +000011233 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11234 } finally {
11235 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011236 }
11237 }
zoey chene02881a2019-12-30 16:11:23 +080011238
11239 @Override
11240 public boolean isIccLockEnabled(int subId) {
11241 enforceReadPrivilegedPermission("isIccLockEnabled");
11242
joonhunshin4ac60942023-11-15 15:23:39 +000011243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11244 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11245
zoey chene02881a2019-12-30 16:11:23 +080011246 // Now that all security checks passes, perform the operation as ourselves.
11247 final long identity = Binder.clearCallingIdentity();
11248 try {
11249 Phone phone = getPhone(subId);
11250 if (phone != null && phone.getIccCard() != null) {
11251 return phone.getIccCard().getIccLockEnabled();
11252 } else {
11253 return false;
11254 }
11255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
11259
11260 /**
11261 * Set the ICC pin lock enabled or disabled.
11262 *
11263 * @return an integer representing the status of IccLock enabled or disabled in the following
11264 * three cases:
11265 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11266 * successfully.
11267 * - Positive number and zero for remaining password attempts.
11268 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11269 *
11270 */
11271 @Override
11272 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11273 enforceModifyPermission();
11274
joonhunshin4ac60942023-11-15 15:23:39 +000011275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11276 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11277
zoey chene02881a2019-12-30 16:11:23 +080011278 Phone phone = getPhone(subId);
11279 if (phone == null) {
11280 return 0;
11281 }
11282 // Now that all security checks passes, perform the operation as ourselves.
11283 final long identity = Binder.clearCallingIdentity();
11284 try {
11285 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11286 new Pair<Boolean, String>(enabled, password), phone, null);
11287 return attemptsRemaining;
11288
11289 } catch (Exception e) {
11290 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 return 0;
11295 }
11296
11297 /**
11298 * Change the ICC password used in ICC pin lock.
11299 *
11300 * @return an integer representing the status of IccLock changed in the following three cases:
11301 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11302 * - Positive number and zero for remaining password attempts.
11303 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11304 *
11305 */
11306 @Override
11307 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11308 enforceModifyPermission();
11309
joonhunshin4ac60942023-11-15 15:23:39 +000011310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11311 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11312
zoey chene02881a2019-12-30 16:11:23 +080011313 Phone phone = getPhone(subId);
11314 if (phone == null) {
11315 return 0;
11316 }
11317 // Now that all security checks passes, perform the operation as ourselves.
11318 final long identity = Binder.clearCallingIdentity();
11319 try {
11320 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11321 new Pair<String, String>(oldPassword, newPassword), phone, null);
11322 return attemptsRemaining;
11323
11324 } catch (Exception e) {
11325 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11326 } finally {
11327 Binder.restoreCallingIdentity(identity);
11328 }
11329 return 0;
11330 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011331
11332 /**
11333 * Request for receiving user activity notification
11334 */
11335 @Override
11336 public void requestUserActivityNotification() {
11337 if (!mNotifyUserActivity.get()
11338 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11339 mNotifyUserActivity.set(true);
11340 }
11341 }
11342
11343 /**
11344 * Called when userActivity is signalled in the power manager.
11345 * This is safe to call from any thread, with any window manager locks held or not.
11346 */
11347 @Override
11348 public void userActivity() {
11349 // ***************************************
11350 // * Inherited from PhoneWindowManager *
11351 // ***************************************
11352 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11353 // WITH ITS LOCKS HELD.
11354 //
11355 // This code must be VERY careful about the locks
11356 // it acquires.
11357 // In fact, the current code acquires way too many,
11358 // and probably has lurking deadlocks.
11359
Jack Yu86374492024-09-16 13:05:44 -070011360 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011361 throw new SecurityException("Only the OS may call notifyUserActivity()");
11362 }
11363
11364 if (mNotifyUserActivity.getAndSet(false)) {
11365 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11366 USER_ACTIVITY_NOTIFICATION_DELAY);
11367 }
11368 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011369
11370 @Override
11371 public boolean canConnectTo5GInDsdsMode() {
11372 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11373 }
Jack Yud10cdd42020-09-28 20:28:01 -070011374
11375 @Override
11376 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11377 String callingFeatureId) {
11378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11379 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11380 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11381 }
11382
joonhunshin4ac60942023-11-15 15:23:39 +000011383 enforceTelephonyFeatureWithException(callingPackage,
11384 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11385
Jack Yud10cdd42020-09-28 20:28:01 -070011386 Phone phone = getPhone(subId);
11387 if (phone == null) {
11388 throw new RuntimeException("phone is not available");
11389 }
11390 // Now that all security checks passes, perform the operation as ourselves.
11391 final long identity = Binder.clearCallingIdentity();
11392 try {
11393 return phone.getEquivalentHomePlmns();
11394 } finally {
11395 Binder.restoreCallingIdentity(identity);
11396 }
11397 }
Daniel Bright59e67312020-11-13 11:49:37 -080011398
11399 @Override
11400 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011401 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011402 if (!mApp.getResources().getBoolean(
11403 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11405 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11406 "isRadioInterfaceCapabilitySupported");
11407 }
joonhunshin4ac60942023-11-15 15:23:39 +000011408
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011409 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011410 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011411 if (radioInterfaceCapabilities == null) {
11412 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011413 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011414 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011415 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011416
Hui Wang641e81c2020-10-12 12:14:23 -070011417 @Override
11418 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11419 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011420 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11421 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11422 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11423 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11424 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011425
11426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11427 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11428
Hui Wang641e81c2020-10-12 12:14:23 -070011429 if (DBG) {
11430 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11431 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11432 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11433 }
11434
11435 if (!SubscriptionManager.isValidSubscriptionId(subId)
11436 || appType < TelephonyManager.APPTYPE_UNKNOWN
11437 || appType > TelephonyManager.APPTYPE_ISIM
11438 || nafUrl == null || securityProtocol == null || callback == null) {
11439 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11440 if (callback != null) {
11441 try {
11442 callback.onAuthenticationFailure(
11443 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11444 } catch (RemoteException exception) {
11445 log("Fail to notify onAuthenticationFailure due to " + exception);
11446 }
11447 return;
11448 }
11449 }
11450
11451 final long token = Binder.clearCallingIdentity();
11452 try {
11453 getGbaManager(subId).bootstrapAuthenticationRequest(
11454 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011455 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011456 } finally {
11457 Binder.restoreCallingIdentity(token);
11458 }
11459 }
11460
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011461 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011462 * Attempts to set the radio power state for all phones for thermal reason.
11463 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011464 * requested radio power state will actually be set. See {@link
11465 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11466 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 * @param enable {@code true} if trying to turn radio on.
11468 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11469 * false}.
11470 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011471 private boolean setRadioPowerForThermal(boolean enable) {
11472 boolean isPhoneAvailable = false;
11473 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11474 Phone phone = PhoneFactory.getPhone(i);
11475 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011476 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011477 isPhoneAvailable = true;
11478 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011479 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011480
11481 // return true if successfully informed the phone object about the thermal radio power
11482 // request.
11483 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011484 }
11485
11486 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011487 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011488 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11489 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11490 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11491 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11492 throw new IllegalArgumentException("modem does not support data throttling");
11493 }
11494
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011495 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11496 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011497 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11499 }
11500
Sarah Chinecc78c42022-03-31 21:16:48 -070011501 setDataEnabledForReason(
11502 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011503
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011504 if (isDataThrottlingSupported) {
11505 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011507 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11508 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11509 } else if (thermalMitigationResult
11510 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011511 log("Modem likely does not support data throttling on secondary carrier. Data " +
11512 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11513 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011514 }
11515 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011516 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011517
11518 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 }
11520
Jack Nudelman644b91a2021-03-12 14:09:48 -080011521 private static List<String> getThermalMitigationAllowlist(Context context) {
11522 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11523 for (String pckg : context.getResources()
11524 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11525 sThermalMitigationAllowlistedPackages.add(pckg);
11526 }
11527 }
11528
11529 return sThermalMitigationAllowlistedPackages;
11530 }
11531
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011532 private boolean isAnyPhoneInEmergencyState() {
11533 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11534 if (tm.isInEmergencyCall()) {
11535 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11536 return true;
11537 }
11538 for (Phone phone : PhoneFactory.getPhones()) {
11539 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11540 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011541 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11542 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011543 return true;
11544 }
11545 }
11546
11547 return false;
11548 }
11549
Jack Nudelman644b91a2021-03-12 14:09:48 -080011550 /**
11551 * Used by shell commands to add an authorized package name for thermal mitigation.
11552 * @param packageName name of package to be allowlisted
11553 * @param context
11554 */
11555 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11556 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11557 sThermalMitigationAllowlistedPackages.add(packageName);
11558 }
11559
11560 /**
11561 * Used by shell commands to remove an authorized package name for thermal mitigation.
11562 * @param packageName name of package to remove from allowlist
11563 * @param context
11564 */
11565 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11566 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11567 sThermalMitigationAllowlistedPackages.remove(packageName);
11568 }
11569
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011570 /**
11571 * Thermal mitigation request to control functionalities at modem.
11572 *
11573 * @param subId the id of the subscription.
11574 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011575 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011576 *
11577 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11578 */
11579 @Override
11580 @ThermalMitigationResult
11581 public int sendThermalMitigationRequest(
11582 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011583 ThermalMitigationRequest thermalMitigationRequest,
11584 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011585 enforceModifyPermission();
11586
Jack Nudelman644b91a2021-03-12 14:09:48 -080011587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011588
11589 enforceTelephonyFeatureWithException(callingPackage,
11590 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11591
Jack Nudelman644b91a2021-03-12 14:09:48 -080011592 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11593 .contains(callingPackage)) {
11594 throw new SecurityException("Calling package must be configured in the device config. "
11595 + "calling package: " + callingPackage);
11596 }
11597
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11599 final long identity = Binder.clearCallingIdentity();
11600
11601 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11602 try {
11603 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11604 switch (thermalMitigationAction) {
11605 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11606 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011607 handleDataThrottlingRequest(subId,
11608 thermalMitigationRequest.getDataThrottlingRequest(),
11609 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011610 break;
11611 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11612 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11613 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11614 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11615 }
11616
11617 // Ensure that radio is on. If not able to power on due to phone being
11618 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011619 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011620 thermalMitigationResult =
11621 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11622 break;
11623 }
11624
11625 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011626 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011627 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11628 break;
11629 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11630 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11631 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11632 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11633 }
11634
11635 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11636 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011637 Phone phone = getPhone(subId);
11638 if (phone == null) {
11639 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011640 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011641 break;
11642 }
11643
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011644 TelephonyConnectionService service =
11645 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011646 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011647 Log.e(LOG_TAG, "An emergency call is pending");
11648 thermalMitigationResult =
11649 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11650 break;
11651 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011652 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011653 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011654 break;
11655 }
11656 } else {
11657 thermalMitigationResult =
11658 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11659 break;
11660 }
11661
11662 // Turn radio off. If not able to power off due to phone being unavailable,
11663 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011664 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011665 thermalMitigationResult =
11666 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11667 break;
11668 }
11669 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011670 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011671 break;
11672 default:
11673 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11674 + "not exist. Requested action: " + thermalMitigationAction);
11675 }
11676 } catch (IllegalArgumentException e) {
11677 throw e;
11678 } catch (Exception e) {
11679 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11680 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11681 } finally {
11682 Binder.restoreCallingIdentity(identity);
11683 }
11684
11685 if (DBG) {
11686 log("thermalMitigationRequest returning with thermalMitigationResult: "
11687 + thermalMitigationResult);
11688 }
11689
11690 return thermalMitigationResult;
11691 }
Hui Wang641e81c2020-10-12 12:14:23 -070011692
11693 /**
11694 * Set the GbaService Package Name that Telephony will bind to.
11695 *
11696 * @param subId The sim that the GbaService is associated with.
11697 * @param packageName The name of the package to be replaced with.
11698 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11699 */
11700 @Override
11701 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11702 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011703 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011704 final long identity = Binder.clearCallingIdentity();
11705 try {
Jack Yu02533f12024-10-03 18:44:32 -070011706 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011707 } finally {
11708 Binder.restoreCallingIdentity(identity);
11709 }
11710 }
11711
11712 /**
11713 * Return the package name of the currently bound GbaService.
11714 *
11715 * @param subId The sim that the GbaService is associated with.
11716 * @return the package name of the GbaService configuration, null if GBA is not supported.
11717 */
11718 @Override
11719 public String getBoundGbaService(int subId) {
11720 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11721
11722 final long identity = Binder.clearCallingIdentity();
11723 try {
11724 return getGbaManager(subId).getServicePackage();
11725 } finally {
11726 Binder.restoreCallingIdentity(identity);
11727 }
11728 }
11729
11730 /**
11731 * Set the release time for telephony to unbind GbaService.
11732 *
11733 * @param subId The sim that the GbaService is associated with.
11734 * @param interval The release time to unbind GbaService by millisecond.
11735 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11736 */
11737 @Override
11738 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11739 enforceModifyPermission();
11740
11741 final long identity = Binder.clearCallingIdentity();
11742 try {
11743 return getGbaManager(subId).overrideReleaseTime(interval);
11744 } finally {
11745 Binder.restoreCallingIdentity(identity);
11746 }
11747 }
11748
11749 /**
11750 * Return the release time for telephony to unbind GbaService.
11751 *
11752 * @param subId The sim that the GbaService is associated with.
11753 * @return The release time to unbind GbaService by millisecond.
11754 */
11755 @Override
11756 public int getGbaReleaseTime(int subId) {
11757 enforceReadPrivilegedPermission("getGbaReleaseTime");
11758
11759 final long identity = Binder.clearCallingIdentity();
11760 try {
11761 return getGbaManager(subId).getReleaseTime();
11762 } finally {
11763 Binder.restoreCallingIdentity(identity);
11764 }
11765 }
11766
11767 private GbaManager getGbaManager(int subId) {
11768 GbaManager instance = GbaManager.getInstance(subId);
11769 if (instance == null) {
11770 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11771 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11772 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11773 }
11774 return instance;
11775 }
Hui Wang761a6682020-10-31 05:12:53 +000011776
11777 /**
11778 * indicate whether the device and the carrier can support
11779 * RCS VoLTE single registration.
11780 */
11781 @Override
11782 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011783 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11784 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11785 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11786 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011787
11788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11790 }
11791
11792 final long identity = Binder.clearCallingIdentity();
11793 try {
11794 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11795 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011796 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11797 if (isCapable != null) {
11798 return isCapable;
11799 }
Hui Wang761a6682020-10-31 05:12:53 +000011800 }
Hui Wang67af90e2021-06-04 16:57:15 -070011801 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11802 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011803 } finally {
11804 Binder.restoreCallingIdentity(identity);
11805 }
11806 }
11807
11808 /**
11809 * Register RCS provisioning callback.
11810 */
11811 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011812 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011813 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011814 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011815 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011816 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11817 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011818
11819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11820 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11821 }
joonhunshin4ac60942023-11-15 15:23:39 +000011822 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11823 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11824 Binder.getCallingUserHandle())) {
11825 if (!isImsAvailableOnDevice()) {
11826 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11827 "IMS not available on device.");
11828 }
11829 } else {
11830 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11831 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011832 }
11833
11834 final long identity = Binder.clearCallingIdentity();
11835 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011836 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011837 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011838 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11839 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011840 }
Hui Wang761a6682020-10-31 05:12:53 +000011841 } finally {
11842 Binder.restoreCallingIdentity(identity);
11843 }
11844 }
11845
11846 /**
11847 * Unregister RCS provisioning callback.
11848 */
11849 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011850 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011851 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011852 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011853 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011854 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11855 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011856
11857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11859 }
joonhunshin4ac60942023-11-15 15:23:39 +000011860
11861 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11862 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11863 Binder.getCallingUserHandle())) {
11864 if (!isImsAvailableOnDevice()) {
11865 // operation failed silently
11866 Rlog.w(LOG_TAG, "IMS not available on device.");
11867 return;
11868 }
11869 } else {
11870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11871 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11872 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011873 }
11874
11875 final long identity = Binder.clearCallingIdentity();
11876 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011877 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011878 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011879 } finally {
11880 Binder.restoreCallingIdentity(identity);
11881 }
11882 }
11883
11884 /**
11885 * trigger RCS reconfiguration.
11886 */
11887 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011888 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11889 "triggerRcsReconfiguration",
11890 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011891
11892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11893 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11894 }
joonhunshin4ac60942023-11-15 15:23:39 +000011895 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11896 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11897 Binder.getCallingUserHandle())) {
11898 if (!isImsAvailableOnDevice()) {
11899 // ProvisioningManager can not handle ServiceSpecificException.
11900 // Throw the IllegalStateException and annotate ProvisioningManager.
11901 throw new IllegalStateException("IMS not available on device.");
11902 }
11903 } else {
11904 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11905 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011906 }
11907
11908 final long identity = Binder.clearCallingIdentity();
11909 try {
11910 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11911 } finally {
11912 Binder.restoreCallingIdentity(identity);
11913 }
11914 }
11915
11916 /**
11917 * Provide the client configuration parameters of the RCS application.
11918 */
11919 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011920 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11921 "setRcsClientConfiguration",
11922 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011923
11924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11925 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11926 }
joonhunshin4ac60942023-11-15 15:23:39 +000011927 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11928 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11929 Binder.getCallingUserHandle())) {
11930 if (!isImsAvailableOnDevice()) {
11931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11932 "IMS not available on device.");
11933 }
11934 } else {
11935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11936 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011937 }
11938
11939 final long identity = Binder.clearCallingIdentity();
11940
11941 try {
11942 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11943 if (configBinder == null) {
11944 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011945 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11946 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011947 } else {
11948 configBinder.setRcsClientConfiguration(rcc);
11949 }
joonhunshin3e154242021-09-17 06:33:39 +000011950
11951 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11952 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011953 } catch (RemoteException e) {
11954 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011955 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11956 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011957 } finally {
11958 Binder.restoreCallingIdentity(identity);
11959 }
11960 }
11961
11962 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011963 * Enables or disables the test mode for RCS VoLTE single registration.
11964 */
11965 @Override
11966 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11968 "setRcsSingleRegistrationTestModeEnabled");
11969
11970 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11971 }
11972
11973 /**
11974 * Gets the test mode for RCS VoLTE single registration.
11975 */
11976 @Override
11977 public boolean getRcsSingleRegistrationTestModeEnabled() {
11978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11979 "getRcsSingleRegistrationTestModeEnabled");
11980
11981 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11982 }
11983
11984 /**
Hui Wang761a6682020-10-31 05:12:53 +000011985 * Overrides the config of RCS VoLTE single registration enabled for the device.
11986 */
11987 @Override
11988 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11990 "setDeviceSingleRegistrationEnabledOverride");
11991 enforceModifyPermission();
11992
11993 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11994 : Boolean.parseBoolean(enabledStr);
11995 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011996 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011997 }
11998
11999 /**
Tyler Gunn92479152021-01-20 16:30:10 -080012000 * Sends a device to device communication message. Only usable via shell.
12001 * @param message message to send.
12002 * @param value message value.
12003 */
12004 @Override
12005 public void sendDeviceToDeviceMessage(int message, int value) {
12006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012007 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012008 enforceModifyPermission();
12009
12010 final long identity = Binder.clearCallingIdentity();
12011 try {
12012 TelephonyConnectionService service =
12013 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12014 if (service == null) {
12015 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12016 return;
12017 }
12018 service.sendTestDeviceToDeviceMessage(message, value);
12019 } finally {
12020 Binder.restoreCallingIdentity(identity);
12021 }
12022 }
12023
Tyler Gunnbabbda02021-02-10 11:05:02 -080012024 /**
12025 * Sets the specified device to device transport active.
12026 * @param transport The transport to set active.
12027 */
12028 @Override
12029 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12031 "setActiveDeviceToDeviceTransport");
12032 enforceModifyPermission();
12033
12034 final long identity = Binder.clearCallingIdentity();
12035 try {
12036 TelephonyConnectionService service =
12037 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12038 if (service == null) {
12039 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12040 return;
12041 }
12042 service.setActiveDeviceToDeviceTransport(transport);
12043 } finally {
12044 Binder.restoreCallingIdentity(identity);
12045 }
12046 }
Tyler Gunn92479152021-01-20 16:30:10 -080012047
Tyler Gunnd4339262021-05-03 14:46:49 -070012048 @Override
12049 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12051 "setDeviceToDeviceForceEnabled");
12052
12053 final long identity = Binder.clearCallingIdentity();
12054 try {
12055 Arrays.stream(PhoneFactory.getPhones()).forEach(
12056 p -> {
12057 Phone thePhone = p.getImsPhone();
12058 if (thePhone != null && thePhone instanceof ImsPhone) {
12059 ImsPhone imsPhone = (ImsPhone) thePhone;
12060 CallTracker tracker = imsPhone.getCallTracker();
12061 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12062 ImsPhoneCallTracker imsPhoneCallTracker =
12063 (ImsPhoneCallTracker) tracker;
12064 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12065 }
12066 }
12067 }
12068 );
12069 } finally {
12070 Binder.restoreCallingIdentity(identity);
12071 }
12072 }
12073
Tyler Gunn92479152021-01-20 16:30:10 -080012074 /**
Hui Wang761a6682020-10-31 05:12:53 +000012075 * Gets the config of RCS VoLTE single registration enabled for the device.
12076 */
12077 @Override
12078 public boolean getDeviceSingleRegistrationEnabled() {
12079 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12080 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12081 }
12082
12083 /**
12084 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12085 */
12086 @Override
12087 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12088 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12089 "setCarrierSingleRegistrationEnabledOverride");
12090 enforceModifyPermission();
12091
12092 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12093 : Boolean.parseBoolean(enabledStr);
12094 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12095 subId, enabled);
12096 }
12097
12098 /**
12099 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12100 */
12101 @Override
12102 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12103 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12104 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12105 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012106
12107 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012108 * Overrides the ims feature validation result
12109 */
12110 @Override
12111 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12112 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12113 "setImsFeatureValidationOverride");
12114
12115 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12116 : Boolean.parseBoolean(enabledStr);
12117 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12118 subId, enabled);
12119 }
12120
12121 /**
12122 * Gets the ims feature validation override value
12123 */
12124 @Override
12125 public boolean getImsFeatureValidationOverride(int subId) {
12126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12127 "getImsFeatureValidationOverride");
12128 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12129 }
12130
12131 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012132 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12133 * their mobile plan.
12134 */
12135 @Override
12136 public String getMobileProvisioningUrl() {
12137 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12138 final long identity = Binder.clearCallingIdentity();
12139 try {
12140 return getDefaultPhone().getMobileProvisioningUrl();
12141 } finally {
12142 Binder.restoreCallingIdentity(identity);
12143 }
12144 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012145
James.cf Linbcdf8b32021-01-14 16:44:13 +080012146 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012147 * Get the EAB contact from the EAB database.
12148 */
12149 @Override
12150 public String getContactFromEab(String contact) {
12151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12152 enforceModifyPermission();
12153 final long identity = Binder.clearCallingIdentity();
12154 try {
12155 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12156 } finally {
12157 Binder.restoreCallingIdentity(identity);
12158 }
12159 }
12160
12161 /**
Calvin Pana1434322021-07-01 19:27:01 +080012162 * Get the EAB capability from the EAB database.
12163 */
12164 @Override
12165 public String getCapabilityFromEab(String contact) {
12166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12167 enforceModifyPermission();
12168 final long identity = Binder.clearCallingIdentity();
12169 try {
12170 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12171 } finally {
12172 Binder.restoreCallingIdentity(identity);
12173 }
12174 }
12175
12176 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012177 * Remove the EAB contacts from the EAB database.
12178 */
12179 @Override
12180 public int removeContactFromEab(int subId, String contacts) {
12181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12182 enforceModifyPermission();
12183 final long identity = Binder.clearCallingIdentity();
12184 try {
12185 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12186 } finally {
12187 Binder.restoreCallingIdentity(identity);
12188 }
12189 }
12190
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012191 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012192 public boolean getDeviceUceEnabled() {
12193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12194 final long identity = Binder.clearCallingIdentity();
12195 try {
12196 return mApp.getDeviceUceEnabled();
12197 } finally {
12198 Binder.restoreCallingIdentity(identity);
12199 }
12200 }
12201
12202 @Override
12203 public void setDeviceUceEnabled(boolean isEnabled) {
12204 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12205 final long identity = Binder.clearCallingIdentity();
12206 try {
12207 mApp.setDeviceUceEnabled(isEnabled);
12208 } finally {
12209 Binder.restoreCallingIdentity(identity);
12210 }
12211 }
12212
Brad Ebinger14d467f2021-02-12 06:18:28 +000012213 /**
12214 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12215 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12216 */
12217 // Used for SHELL command only right now.
12218 @Override
12219 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12220 List<String> featureTags) {
12221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12222 "addUceRegistrationOverrideShell");
12223 final long identity = Binder.clearCallingIdentity();
12224 try {
12225 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12226 new ArraySet<>(featureTags));
12227 } catch (ImsException e) {
12228 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12229 } finally {
12230 Binder.restoreCallingIdentity(identity);
12231 }
12232 }
12233
12234 /**
12235 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12236 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12237 */
12238 // Used for SHELL command only right now.
12239 @Override
12240 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12241 List<String> featureTags) {
12242 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12243 "removeUceRegistrationOverrideShell");
12244 final long identity = Binder.clearCallingIdentity();
12245 try {
12246 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12247 new ArraySet<>(featureTags));
12248 } catch (ImsException e) {
12249 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12250 } finally {
12251 Binder.restoreCallingIdentity(identity);
12252 }
12253 }
12254
12255 /**
12256 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12257 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12258 */
12259 // Used for SHELL command only right now.
12260 @Override
12261 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12263 "clearUceRegistrationOverrideShell");
12264 final long identity = Binder.clearCallingIdentity();
12265 try {
12266 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12267 } catch (ImsException e) {
12268 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12269 } finally {
12270 Binder.restoreCallingIdentity(identity);
12271 }
12272 }
12273
12274 /**
12275 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12276 */
12277 // Used for SHELL command only right now.
12278 @Override
12279 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12281 "getLatestRcsContactUceCapabilityShell");
12282 final long identity = Binder.clearCallingIdentity();
12283 try {
12284 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12285 } catch (ImsException e) {
12286 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12287 } finally {
12288 Binder.restoreCallingIdentity(identity);
12289 }
12290 }
12291
12292 /**
12293 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12294 * device does not have an active PUBLISH.
12295 */
12296 // Used for SHELL command only right now.
12297 @Override
12298 public String getLastUcePidfXmlShell(int subId) {
12299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12300 final long identity = Binder.clearCallingIdentity();
12301 try {
12302 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12303 } catch (ImsException e) {
12304 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12305 } finally {
12306 Binder.restoreCallingIdentity(identity);
12307 }
12308 }
12309
James.cf Line8713a42021-04-29 16:04:26 +080012310 /**
12311 * Remove UCE requests cannot be sent to the network status.
12312 */
12313 // Used for SHELL command only right now.
12314 @Override
12315 public boolean removeUceRequestDisallowedStatus(int subId) {
12316 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12317 final long identity = Binder.clearCallingIdentity();
12318 try {
12319 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12320 } catch (ImsException e) {
12321 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12322 } finally {
12323 Binder.restoreCallingIdentity(identity);
12324 }
12325 }
12326
James.cf Lin18bb9002021-05-25 01:37:38 +080012327 /**
12328 * Remove UCE requests cannot be sent to the network status.
12329 */
12330 // Used for SHELL command only.
12331 @Override
12332 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12333 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12334 final long identity = Binder.clearCallingIdentity();
12335 try {
12336 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12337 } catch (ImsException e) {
12338 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12339 } finally {
12340 Binder.restoreCallingIdentity(identity);
12341 }
12342 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012343
James.cf Lin4b784aa2021-01-31 03:25:15 +080012344 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012345 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12346 String callingPackage) {
12347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12348 mApp, subId, "setSignalStrengthUpdateRequest");
12349
joonhunshin4ac60942023-11-15 15:23:39 +000012350 enforceTelephonyFeatureWithException(callingPackage,
12351 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12352
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012353 final int callingUid = Binder.getCallingUid();
12354 // Verify that tha callingPackage belongs to the calling UID
12355 mApp.getSystemService(AppOpsManager.class)
12356 .checkPackage(callingUid, callingPackage);
12357
Rambo Wang3607f502021-02-01 21:51:40 -080012358 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012359
12360 final long identity = Binder.clearCallingIdentity();
12361 try {
12362 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12363 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12364
12365 if (result instanceof IllegalStateException) {
12366 throw (IllegalStateException) result;
12367 }
12368 } finally {
12369 Binder.restoreCallingIdentity(identity);
12370 }
12371 }
12372
12373 @Override
12374 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12375 String callingPackage) {
12376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12377 mApp, subId, "clearSignalStrengthUpdateRequest");
12378
joonhunshin4ac60942023-11-15 15:23:39 +000012379 enforceTelephonyFeatureWithException(callingPackage,
12380 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12381
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012382 final int callingUid = Binder.getCallingUid();
12383 // Verify that tha callingPackage belongs to the calling UID
12384 mApp.getSystemService(AppOpsManager.class)
12385 .checkPackage(callingUid, callingPackage);
12386
12387 final long identity = Binder.clearCallingIdentity();
12388 try {
12389 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12390 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12391
12392 if (result instanceof IllegalStateException) {
12393 throw (IllegalStateException) result;
12394 }
12395 } finally {
12396 Binder.restoreCallingIdentity(identity);
12397 }
12398 }
12399
Rambo Wang3607f502021-02-01 21:51:40 -080012400 private static void validateSignalStrengthUpdateRequest(Context context,
12401 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012402 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012403 // phone/system process do not have further restriction on request
12404 return;
12405 }
12406
12407 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012408 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012409 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012410 context.enforceCallingOrSelfPermission(
12411 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12412 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012413 }
12414
12415 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012416 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012417 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012418 || info.isEnabled()) {
12419 throw new IllegalArgumentException(
12420 "Only system can set hide fields in SignalThresholdInfo");
12421 }
12422
12423 // Thresholds length for each RAN need in range. This has been validated in
12424 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12425 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12426 final int[] thresholds = info.getThresholds();
12427 Objects.requireNonNull(thresholds);
12428 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12429 || thresholds.length
12430 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12431 throw new IllegalArgumentException(
12432 "thresholds length is out of range: " + thresholds.length);
12433 }
12434 }
12435 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012436
12437 /**
12438 * Gets the current phone capability.
12439 *
12440 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12441 * @return the PhoneCapability which describes the data connection capability of modem.
12442 * It's used to evaluate possible phone config change, for example from single
12443 * SIM device to multi-SIM device.
12444 */
12445 @Override
12446 public PhoneCapability getPhoneCapability() {
12447 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012448
12449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12450 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12451
SongFerngWang8236caa2021-01-17 21:51:44 +080012452 final long identity = Binder.clearCallingIdentity();
12453 try {
12454 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12455 } finally {
12456 Binder.restoreCallingIdentity(identity);
12457 }
12458 }
Michele Berionne5e411512020-11-13 02:36:59 +000012459
12460 /**
12461 * Prepare TelephonyManager for an unattended reboot. The reboot is
12462 * required to be done shortly after the API is invoked.
12463 */
12464 @Override
12465 @TelephonyManager.PrepareUnattendedRebootResult
12466 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012468 enforceRebootPermission();
12469
joonhunshin4ac60942023-11-15 15:23:39 +000012470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12471 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12472
Michele Berionne5e411512020-11-13 02:36:59 +000012473 final long identity = Binder.clearCallingIdentity();
12474 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012475 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012476 } finally {
12477 Binder.restoreCallingIdentity(identity);
12478 }
12479 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012480
12481 /**
12482 * Request to get the current slicing configuration including URSP rules and
12483 * NSSAIs (configured, allowed and rejected).
12484 *
12485 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12486 */
12487 @Override
12488 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012489 TelephonyPermissions
12490 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12491 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012492
joonhunshin4ac60942023-11-15 15:23:39 +000012493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12494 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12495 "getSlicingConfig");
12496
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012497 final long identity = Binder.clearCallingIdentity();
12498 try {
12499 Phone phone = getDefaultPhone();
12500 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12501 } finally {
12502 Binder.restoreCallingIdentity(identity);
12503 }
12504 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012505
12506 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012507 * Check whether the given premium capability is available for purchase from the carrier.
12508 *
12509 * @param capability The premium capability to check.
12510 * @param subId The subId to check the premium capability for.
12511 *
12512 * @return Whether the given premium capability is available to purchase.
12513 */
12514 @Override
12515 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12516 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12517 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12518 log("Premium capability "
12519 + TelephonyManager.convertPremiumCapabilityToString(capability)
12520 + " is not available for purchase due to missing permissions.");
12521 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12522 + "permission READ_BASIC_PHONE_STATE.");
12523 }
12524
joonhunshin4ac60942023-11-15 15:23:39 +000012525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12526 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12527
Sarah Chin2ec39f62022-08-31 17:03:26 -070012528 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012529 if (phone == null) {
12530 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12531 return false;
12532 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012533 final long identity = Binder.clearCallingIdentity();
12534 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012535 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012536 .isPremiumCapabilityAvailableForPurchase(capability);
12537 } finally {
12538 Binder.restoreCallingIdentity(identity);
12539 }
12540 }
12541
12542 /**
12543 * Purchase the given premium capability from the carrier.
12544 *
12545 * @param capability The premium capability to purchase.
12546 * @param callback The result of the purchase request.
12547 * @param subId The subId to purchase the premium capability for.
12548 */
12549 @Override
12550 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12551 log("purchasePremiumCapability: capability="
12552 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12553 + getCurrentPackageName());
12554
12555 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12556 mApp, "purchasePremiumCapability")) {
12557 log("purchasePremiumCapability "
12558 + TelephonyManager.convertPremiumCapabilityToString(capability)
12559 + " failed due to missing permissions.");
12560 throw new SecurityException("purchasePremiumCapability requires permission "
12561 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012562 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12563 mApp, "purchasePremiumCapability")) {
12564 log("purchasePremiumCapability "
12565 + TelephonyManager.convertPremiumCapabilityToString(capability)
12566 + " failed due to missing permissions.");
12567 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012568 }
12569
joonhunshin4ac60942023-11-15 15:23:39 +000012570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12571 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12572
Sarah Chin2ec39f62022-08-31 17:03:26 -070012573 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012574 if (phone == null) {
12575 try {
12576 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12577 callback.accept(result);
12578 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12579 } catch (RemoteException e) {
12580 String logStr = "Purchase premium capability "
12581 + TelephonyManager.convertPremiumCapabilityToString(capability)
12582 + " failed due to RemoteException handling null phone: " + e;
12583 if (DBG) log(logStr);
12584 AnomalyReporter.reportAnomaly(
12585 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12586 }
12587 return;
12588 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012589
12590 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012591 try {
Jack Yube3fa442024-09-16 14:39:45 -070012592 if (mFeatureFlags.hsumPackageManager()) {
12593 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12594 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12595 } else {
12596 callingProcess = mApp.getPackageManager().getApplicationInfo(
12597 getCurrentPackageName(), 0).processName;
12598 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012599 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012600 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012601 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012602
12603 boolean isVisible = false;
12604 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12605 if (am != null) {
12606 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12607 if (processes != null) {
12608 for (ActivityManager.RunningAppProcessInfo process : processes) {
12609 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012610 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012611 if (process.processName.equals(callingProcess) && process.importance
12612 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12613 isVisible = true;
12614 break;
12615 }
12616 }
12617 }
12618 }
12619
12620 if (!isVisible) {
12621 try {
12622 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12623 callback.accept(result);
12624 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12625 } catch (RemoteException e) {
12626 String logStr = "Purchase premium capability "
12627 + TelephonyManager.convertPremiumCapabilityToString(capability)
12628 + " failed due to RemoteException handling background application: " + e;
12629 if (DBG) log(logStr);
12630 AnomalyReporter.reportAnomaly(
12631 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12632 }
12633 return;
12634 }
12635
Sarah Chin71b3a852022-09-28 15:54:19 -070012636 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012637 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012638 }
12639
12640 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012641 * Register an IMS connection state callback
12642 */
12643 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012644 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12645 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012646 if (feature == ImsFeature.FEATURE_MMTEL) {
12647 // ImsMmTelManager
12648 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12649 TelephonyPermissions
12650 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12651 mApp, subId, "registerImsStateCallback");
12652 } else if (feature == ImsFeature.FEATURE_RCS) {
12653 // ImsRcsManager or SipDelegateManager
12654 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12655 Binder.getCallingUid(), "registerImsStateCallback",
12656 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12657 Manifest.permission.READ_PRECISE_PHONE_STATE,
12658 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12659 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12660 }
12661
12662 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12664 "IMS not available on device.");
12665 }
12666
12667 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12668 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12669 }
12670
12671 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12672 if (controller == null) {
12673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12674 "IMS not available on device.");
12675 }
12676
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012677 if (callingPackage == null) {
12678 callingPackage = getCurrentPackageName();
12679 }
12680
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012681 final long token = Binder.clearCallingIdentity();
12682 try {
12683 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012684 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012685 } catch (ImsException e) {
12686 throw new ServiceSpecificException(e.getCode());
12687 } finally {
12688 Binder.restoreCallingIdentity(token);
12689 }
12690 }
12691
12692 /**
12693 * Unregister an IMS connection state callback
12694 */
12695 @Override
12696 public void unregisterImsStateCallback(IImsStateCallback cb) {
12697 final long token = Binder.clearCallingIdentity();
12698 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12699 if (controller == null) {
12700 return;
12701 }
12702 try {
12703 controller.unregisterImsStateCallback(cb);
12704 } finally {
12705 Binder.restoreCallingIdentity(token);
12706 }
12707 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012708
12709 /**
12710 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12711 *
12712 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012713 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012714 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012715 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012716 * If there is current registered network this value will be same as the registered cell
12717 * identity. If the device goes out of service the previous cell identity is cached and
12718 * will be returned. If the cache age of the Cell identity is more than 24 hours
12719 * it will be cleared and null will be returned.
12720 *
12721 */
12722 @Override
12723 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12724 String callingFeatureId) {
12725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12726 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12727 LocationAccessPolicy.checkLocationPermission(mApp,
12728 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12729 .setCallingPackage(callingPackage)
12730 .setCallingFeatureId(callingFeatureId)
12731 .setCallingPid(Binder.getCallingPid())
12732 .setCallingUid(Binder.getCallingUid())
12733 .setMethod("getLastKnownCellIdentity")
12734 .setLogAsInfo(true)
12735 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12736 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12737 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12738 .build());
12739
12740 boolean hasFinePermission =
12741 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12742 if (!hasFinePermission
12743 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12744 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012745 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012746 }
12747
12748 final long identity = Binder.clearCallingIdentity();
12749 try {
Ling Mac28f0212023-03-24 16:07:15 -070012750 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012751 if (sst == null) return null;
12752 return sst.getLastKnownCellIdentity();
12753 } finally {
12754 Binder.restoreCallingIdentity(identity);
12755 }
12756 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012757
jimsun3b9ccac2021-10-26 15:01:23 +080012758 /**
12759 * Sets the modem service class Name that Telephony will bind to.
12760 *
12761 * @param serviceName The class name of the modem service.
12762 * @return true if the operation is succeed, otherwise false.
12763 */
12764 public boolean setModemService(String serviceName) {
12765 Log.d(LOG_TAG, "setModemService - " + serviceName);
12766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012768 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12769 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012770 return mPhoneConfigurationManager.setModemService(serviceName);
12771 }
12772
12773 /**
12774 * Return the class name of the currently bounded modem service.
12775 *
12776 * @return the class name of the modem service.
12777 */
12778 public String getModemService() {
12779 String result;
12780 Log.d(LOG_TAG, "getModemService");
12781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12782 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012783 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012784 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12785 "getModemService");
12786 result = mPhoneConfigurationManager.getModemService();
12787 Log.d(LOG_TAG, "result = " + result);
12788 return result;
12789 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012790
Hakjun Choi3ee81112023-12-19 15:40:58 +000012791 /**
12792 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12793 * including carrier config, entitlement server, and config update.
12794 *
12795 * @param subId subId The subscription ID of the carrier.
12796 *
12797 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12798 * be returned.
12799 *
12800 * @throws SecurityException if the caller doesn't have the required permission.
12801 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012802 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12803 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012804 final long identity = Binder.clearCallingIdentity();
12805 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012806 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012807 } finally {
12808 Binder.restoreCallingIdentity(identity);
12809 }
12810 }
12811
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012812 @Override
12813 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12814 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12815 mApp.enforceCallingOrSelfPermission(
12816 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12817 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12818
12819 final long identity = Binder.clearCallingIdentity();
12820 try {
12821 Phone phone = getPhone(subId);
12822 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012823 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12824 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012825 phone.setVoiceServiceStateOverride(hasService);
12826 } finally {
12827 Binder.restoreCallingIdentity(identity);
12828 }
12829 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012830
12831 /**
12832 * set removable eSIM as default eUICC.
12833 *
12834 * @hide
12835 */
12836 @Override
12837 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12838 enforceModifyPermission();
12839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12840
12841 final long identity = Binder.clearCallingIdentity();
12842 try {
12843 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12844 } finally {
12845 Binder.restoreCallingIdentity(identity);
12846 }
12847 }
12848
12849 /**
12850 * Returns whether the removable eSIM is default eUICC or not.
12851 *
12852 * @hide
12853 */
12854 @Override
12855 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12856 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12857 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12858
12859 final long identity = Binder.clearCallingIdentity();
12860 try {
12861 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12862 } finally {
12863 Binder.restoreCallingIdentity(identity);
12864 }
12865 }
12866
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012867 /**
12868 * Get the component name of the default app to direct respond-via-message intent for the
12869 * user associated with this subscription, update the cache if there is no respond-via-message
12870 * application currently configured for this user.
12871 * @return component name of the app and class to direct Respond Via Message intent to, or
12872 * {@code null} if the functionality is not supported.
12873 * @hide
12874 */
12875 @Override
12876 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12877 boolean updateIfNeeded) {
12878 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012879
joonhunshin4ac60942023-11-15 15:23:39 +000012880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12881 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12882 "getDefaultRespondViaMessageApplication");
12883
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012884 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12885
Grant Menkeb0372492024-09-19 18:01:29 -070012886 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12887 UserHandle mainUser = null;
12888 Context userContext = null;
12889 final long identity = Binder.clearCallingIdentity();
12890 try {
12891 mainUser = mUserManager.getMainUser();
12892 userContext = context.createContextAsUser(mainUser, 0);
12893 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12894 } finally {
12895 Binder.restoreCallingIdentity(identity);
12896 }
12897 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12898 updateIfNeeded, mainUser);
12899 } else {
12900 UserHandle userHandle = null;
12901 final long identity = Binder.clearCallingIdentity();
12902 try {
12903 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12904 } finally {
12905 Binder.restoreCallingIdentity(identity);
12906 }
12907 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12908 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012909 }
Grant Menkeb0372492024-09-19 18:01:29 -070012910
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012911 }
Jack Yuf5badd92022-12-08 00:50:53 -080012912
12913 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012914 * Set whether the device is able to connect with null ciphering or integrity
12915 * algorithms. This is a global setting and will apply to all active subscriptions
12916 * and all new subscriptions after this.
12917 *
12918 * @param enabled when true, null cipher and integrity algorithms are allowed.
12919 * @hide
12920 */
12921 @Override
12922 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12923 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12924 enforceModifyPermission();
12925 checkForNullCipherAndIntegritySupport();
12926
12927 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12928 // for listening to these preference changes and applying them immediately.
12929 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12930 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12931 editor.apply();
12932
12933 for (Phone phone: PhoneFactory.getPhones()) {
12934 phone.handleNullCipherEnabledChange();
12935 }
12936 }
12937
12938
12939 /**
12940 * Get whether the device is able to connect with null ciphering or integrity
12941 * algorithms. Note that this retrieves the phone-global preference and not
12942 * the state of the radio.
12943 *
12944 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12945 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12946 * version for this feature.
12947 * @hide
12948 */
12949 @Override
12950 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12951 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12952 enforceReadPermission();
12953 checkForNullCipherAndIntegritySupport();
12954 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12955 }
12956
12957 private void checkForNullCipherAndIntegritySupport() {
12958 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12959 throw new UnsupportedOperationException(
12960 "Null cipher and integrity operations require HAL 2.1 or above");
12961 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012962 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12963 throw new UnsupportedOperationException(
12964 "Null cipher and integrity operations unsupported by modem");
12965 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012966 }
12967
Gil Cukierman06403e12023-11-29 16:33:03 +000012968 private void checkForIdentifierDisclosureNotificationSupport() {
12969 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12970 throw new UnsupportedOperationException(
12971 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12972 + "above");
12973 }
12974 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12975 throw new UnsupportedOperationException(
12976 "Cellular identifier disclosure transparency operations unsupported by modem");
12977 }
12978 }
12979
Michael Groover826b71d2023-12-21 22:08:06 -060012980 private void checkForNullCipherNotificationSupport() {
12981 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12982 throw new UnsupportedOperationException(
12983 "Null cipher notification operations require HAL 2.2 or above");
12984 }
12985 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12986 throw new UnsupportedOperationException(
12987 "Null cipher notification operations unsupported by modem");
12988 }
12989 }
12990
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012991 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012992 * Get the SIM state for the slot index.
12993 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12994 *
12995 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12996 */
12997 @Override
12998 @SimState
12999 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070013000 if (!mApp.getResources().getBoolean(
13001 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13003 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13004 }
joonhunshin4ac60942023-11-15 15:23:39 +000013005
Jack Yuf5badd92022-12-08 00:50:53 -080013006 IccCardConstants.State simState;
13007 if (slotIndex < 0) {
13008 simState = IccCardConstants.State.UNKNOWN;
13009 } else {
13010 Phone phone = null;
13011 try {
13012 phone = PhoneFactory.getPhone(slotIndex);
13013 } catch (IllegalStateException e) {
13014 // ignore
13015 }
13016 if (phone == null) {
13017 simState = IccCardConstants.State.UNKNOWN;
13018 } else {
13019 IccCard icc = phone.getIccCard();
13020 if (icc == null) {
13021 simState = IccCardConstants.State.UNKNOWN;
13022 } else {
13023 simState = icc.getState();
13024 }
13025 }
13026 }
13027 return simState.ordinal();
13028 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013029
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013030 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13031 boolean enableLogcat,
13032 long logcatStartTimestampMillis, boolean enableTelecomDump,
13033 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013034 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013035 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13036 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13037 ecdDataBuilder
13038 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13039 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013040 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013041 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013042 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013043 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13044 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013045 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13046 Executors.newCachedThreadPool(), db,
13047 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013048 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013049 }
13050
13051 /**
13052 * Request telephony to persist state for debugging emergency call failures.
13053 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013054 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013055 * @param enableLogcat whether to collect logcat output
13056 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13057 * @param enableTelecomDump whether to collect telecom dumpsys
13058 * @param enableTelephonyDump whether to collect telephony dumpsys
13059 */
13060 @Override
13061 @RequiresPermission(android.Manifest.permission.DUMP)
13062 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13063 long logcatStartTimestampMillis, boolean enableTelecomDump,
13064 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013065 // Verify that the caller has READ_DROPBOX_DATA permission.
13066 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13067 && Flags.enableReadDropboxPermission()) {
13068 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13069 "persistEmergencyCallDiagnosticData");
13070 } else {
13071 // Otherwise, enforce legacy permission.
13072 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13073 "persistEmergencyCallDiagnosticData");
13074 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013075 final long identity = Binder.clearCallingIdentity();
13076 try {
13077 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13078 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13079
13080 } finally {
13081 Binder.restoreCallingIdentity(identity);
13082 }
13083 }
13084
Hui Wang9b5793a2022-12-05 14:38:06 -060013085 /**
13086 * Get current cell broadcast ranges.
13087 */
13088 @Override
13089 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13090 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13091 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13092 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013093
13094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13095 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13096
Hui Wang9b5793a2022-12-05 14:38:06 -060013097 final long identity = Binder.clearCallingIdentity();
13098 try {
13099 return getPhone(subId).getCellBroadcastIdRanges();
13100 } finally {
13101 Binder.restoreCallingIdentity(identity);
13102 }
13103 }
13104
13105 /**
13106 * Set reception of cell broadcast messages with the list of the given ranges
13107 *
13108 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13109 */
13110 @Override
13111 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13112 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13113 @Nullable IIntegerConsumer callback) {
13114 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13115 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013116
13117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13118 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13119
Hui Wang9b5793a2022-12-05 14:38:06 -060013120 final long identity = Binder.clearCallingIdentity();
13121 try {
13122 Phone phone = getPhoneFromSubId(subId);
13123 if (DBG) {
13124 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13125 }
13126 phone.setCellBroadcastIdRanges(ranges, result -> {
13127 if (callback != null) {
13128 try {
13129 callback.accept(result);
13130 } catch (RemoteException e) {
13131 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13132 }
13133 }
13134 });
13135 } finally {
13136 Binder.restoreCallingIdentity(identity);
13137 }
13138 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013139
13140 /**
13141 * Returns whether the device supports the domain selection service.
13142 *
13143 * @return {@code true} if the device supports the domain selection service.
13144 */
13145 @Override
13146 public boolean isDomainSelectionSupported() {
13147 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13148 "isDomainSelectionSupported");
13149
13150 final long identity = Binder.clearCallingIdentity();
13151 try {
13152 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13153 } finally {
13154 Binder.restoreCallingIdentity(identity);
13155 }
13156 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013157
13158 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013159 * Returns whether the AOSP domain selection service is supported.
13160 *
13161 * @return {@code true} if the AOSP domain selection service is supported,
13162 * {@code false} otherwise.
13163 */
13164 @Override
13165 public boolean isAospDomainSelectionService() {
13166 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13167 "isAospDomainSelectionService");
13168
13169 final long identity = Binder.clearCallingIdentity();
13170 try {
13171 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13172 String dssComponentName = mApp.getResources().getString(
13173 R.string.config_domain_selection_service_component_name);
13174 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13175 TelephonyDomainSelectionService.class.getName());
13176 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13177 + ", aosp=" + componentName.flattenToString());
13178 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13179 }
13180 } finally {
13181 Binder.restoreCallingIdentity(identity);
13182 }
13183 return false;
13184 }
13185
13186 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013187 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13188 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13189 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013190 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013191 * @param enableSatellite {@code true} to enable the satellite modem and
13192 * {@code false} to disable.
13193 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013194 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013195 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013196 *
13197 * @throws SecurityException if the caller doesn't have the required permission.
13198 */
13199 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013200 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013201 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013202 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013203 final long identity = Binder.clearCallingIdentity();
13204 try {
13205 if (enableSatellite) {
youngtaecha3a9c8a62024-11-01 20:46:08 +000013206 String caller = "PIM:requestSatelliteEnabled";
Hyosun322782b2024-10-24 11:37:59 +000013207 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13208 @Override
13209 protected void onReceiveResult(int resultCode, Bundle resultData) {
13210 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13211 + ", resultData=" + resultData);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013212 mSatelliteController.decrementResultReceiverCount(caller);
13213
Hyosun322782b2024-10-24 11:37:59 +000013214 boolean isAllowed = false;
13215 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13216 callback::accept);
13217 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13218 if (resultData != null
13219 && resultData.containsKey(
13220 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13221 isAllowed = resultData.getBoolean(
13222 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13223 } else {
13224 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13225 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013226 } else {
Hyosun322782b2024-10-24 11:37:59 +000013227 result.accept(resultCode);
13228 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013229 }
Hyosun322782b2024-10-24 11:37:59 +000013230 if (isAllowed) {
Duke Lee8852e512024-10-06 12:55:43 +090013231 if (mFeatureFlags.carrierRoamingNbIotNtn()
13232 && !mSatelliteAccessController.getSatelliteDisallowedReasons()
13233 .isEmpty()) {
13234 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13235 } else {
13236 mSatelliteController.requestSatelliteEnabled(
13237 enableSatellite, enableDemoMode, isEmergency, callback);
13238 }
Hyosun322782b2024-10-24 11:37:59 +000013239 } else {
13240 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13241 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013242 }
Hyosun322782b2024-10-24 11:37:59 +000013243 };
13244 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13245 resultReceiver, true);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013246 mSatelliteController.incrementResultReceiverCount(caller);
Hyosun322782b2024-10-24 11:37:59 +000013247 } else {
13248 // No need to check if satellite is allowed at current location when disabling
13249 // satellite
13250 mSatelliteController.requestSatelliteEnabled(
13251 enableSatellite, enableDemoMode, isEmergency, callback);
13252 }
13253 } finally {
13254 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013255 }
Sarah Chin503828c2023-02-01 23:54:20 -080013256 }
13257
13258 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013259 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013260 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013261 * @param result The result receiver that returns whether the satellite modem is enabled
13262 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013263 *
13264 * @throws SecurityException if the caller doesn't have the required permission.
13265 */
13266 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013267 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013268 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013269 final long identity = Binder.clearCallingIdentity();
13270 try {
13271 mSatelliteController.requestIsSatelliteEnabled(result);
13272 } finally {
13273 Binder.restoreCallingIdentity(identity);
13274 }
Sarah Chin503828c2023-02-01 23:54:20 -080013275 }
13276
13277 /**
Sarah Chin43457982023-02-15 17:50:38 -080013278 * Request to get whether the satellite service demo mode is enabled.
13279 *
Sarah Chin43457982023-02-15 17:50:38 -080013280 * @param result The result receiver that returns whether the satellite demo mode is enabled
13281 * if the request is successful or an error code if the request failed.
13282 *
13283 * @throws SecurityException if the caller doesn't have the required permission.
13284 */
13285 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013286 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013287 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013288 final long identity = Binder.clearCallingIdentity();
13289 try {
13290 mSatelliteController.requestIsDemoModeEnabled(result);
13291 } finally {
13292 Binder.restoreCallingIdentity(identity);
13293 }
Sarah Chin43457982023-02-15 17:50:38 -080013294 }
13295
13296 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013297 * Request to get whether the satellite service is enabled with emergency mode.
13298 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013299 * @param result The result receiver that returns whether the satellite emergency mode is
13300 * enabled if the request is successful or an error code if the request failed.
13301 *
13302 * @throws SecurityException if the caller doesn't have the required permission.
13303 */
13304 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013305 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013306 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013307 final long identity = Binder.clearCallingIdentity();
13308 try {
13309 mSatelliteController.requestIsEmergencyModeEnabled(result);
13310 } finally {
13311 Binder.restoreCallingIdentity(identity);
13312 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013313 }
13314
13315 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013316 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013317 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013318 * @param result The result receiver that returns whether the satellite service is supported on
13319 * the device if the request is successful or an error code if the request failed.
Hyosun322782b2024-10-24 11:37:59 +000013320 *
13321 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chin503828c2023-02-01 23:54:20 -080013322 */
13323 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013324 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013325 enforceSatelliteCommunicationPermission("requestIsSatelliteSupported");
13326 final long identity = Binder.clearCallingIdentity();
13327 try {
13328 mSatelliteController.requestIsSatelliteSupported(result);
13329 } finally {
13330 Binder.restoreCallingIdentity(identity);
13331 }
Sarah Chin503828c2023-02-01 23:54:20 -080013332 }
13333
13334 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013335 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013336 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013337 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13338 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013339 *
13340 * @throws SecurityException if the caller doesn't have required permission.
13341 */
13342 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013343 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013344 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013345 final long identity = Binder.clearCallingIdentity();
13346 try {
13347 mSatelliteController.requestSatelliteCapabilities(result);
13348 } finally {
13349 Binder.restoreCallingIdentity(identity);
13350 }
Sarah Chin503828c2023-02-01 23:54:20 -080013351 }
13352
13353 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013354 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013355 * This can be called by the pointing UI when the user starts pointing to the satellite.
13356 * Modem should continue to report the pointing input as the device or satellite moves.
13357 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013358 * @param resultCallback The callback to get the result of the request.
13359 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013360 *
13361 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013362 */
13363 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013364 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013365 @NonNull IIntegerConsumer resultCallback,
13366 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13367 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013368 final long identity = Binder.clearCallingIdentity();
13369 try {
13370 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13371 } finally {
13372 Binder.restoreCallingIdentity(identity);
13373 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013374 }
13375
13376 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013377 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013378 * This can be called by the pointing UI when the user stops pointing to the satellite.
13379 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013380 * @param resultCallback The callback to get the result of the request.
13381 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013382 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013383 *
13384 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013385 */
13386 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013387 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013388 @NonNull IIntegerConsumer resultCallback,
13389 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13390 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013391 final long identity = Binder.clearCallingIdentity();
13392 try {
13393 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13394 } finally {
13395 Binder.restoreCallingIdentity(identity);
13396 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013397 }
13398
13399 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013400 * Register the subscription with a satellite provider.
13401 * This is needed to register the subscription if the provider allows dynamic registration.
13402 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013403 * @param token The token to be used as a unique identifier for provisioning with satellite
13404 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013405 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013406 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013407 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013408 * @return The signal transport used by the caller to cancel the provision request,
13409 * or {@code null} if the request failed.
13410 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013411 * @throws SecurityException if the caller doesn't have the required permission.
13412 */
13413 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013414 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013415 @NonNull String token, @NonNull byte[] provisionData,
13416 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013417 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013418 final long identity = Binder.clearCallingIdentity();
13419 try {
13420 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013421 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013422 } finally {
13423 Binder.restoreCallingIdentity(identity);
13424 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013425 }
13426
13427 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013428 * Unregister the device/subscription with the satellite provider.
13429 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013430 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013431 * should report as deprovisioned.
13432 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013433 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013434 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013435 *
13436 * @throws SecurityException if the caller doesn't have the required permission.
13437 */
13438 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013439 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013440 @NonNull String token, @NonNull IIntegerConsumer callback) {
13441 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013442 final long identity = Binder.clearCallingIdentity();
13443 try {
13444 mSatelliteController.deprovisionSatelliteService(token, callback);
13445 } finally {
13446 Binder.restoreCallingIdentity(identity);
13447 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013448 }
13449
13450 /**
Sarah Chin43457982023-02-15 17:50:38 -080013451 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013452 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013453 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013454 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013455 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013456 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013457 * @throws SecurityException if the caller doesn't have the required permission.
13458 */
13459 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013460 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013461 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013462 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013463 final long identity = Binder.clearCallingIdentity();
13464 try {
13465 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13466 } finally {
13467 Binder.restoreCallingIdentity(identity);
13468 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013469 }
13470
13471 /**
Sarah Chin43457982023-02-15 17:50:38 -080013472 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013473 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013474 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013475 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013476 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013477 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013478 * @throws SecurityException if the caller doesn't have the required permission.
13479 */
13480 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013481 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013482 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013483 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013484 final long identity = Binder.clearCallingIdentity();
13485 try {
13486 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13487 } finally {
13488 Binder.restoreCallingIdentity(identity);
13489 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013490 }
13491
13492 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013493 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013494 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013495 * @param result The result receiver that returns whether the device is provisioned with a
13496 * satellite provider if the request is successful or an error code if the
13497 * request failed.
13498 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013499 * @throws SecurityException if the caller doesn't have the required permission.
13500 */
13501 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013502 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013503 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013504 final long identity = Binder.clearCallingIdentity();
13505 try {
13506 mSatelliteController.requestIsSatelliteProvisioned(result);
13507 } finally {
13508 Binder.restoreCallingIdentity(identity);
13509 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013510 }
13511
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013512 /**
Sarah Chin43457982023-02-15 17:50:38 -080013513 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013514 *
Sarah Chin43457982023-02-15 17:50:38 -080013515 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013516 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013517 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013518 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013519 * @throws SecurityException if the caller doesn't have the required permission.
13520 */
13521 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013522 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013523 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013524 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013525 final long identity = Binder.clearCallingIdentity();
13526 try {
13527 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13528 } finally {
13529 Binder.restoreCallingIdentity(identity);
13530 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013531 }
13532
13533 /**
Sarah Chin43457982023-02-15 17:50:38 -080013534 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013535 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013536 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013537 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013538 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013539 *
13540 * @throws SecurityException if the caller doesn't have the required permission.
13541 */
13542 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013543 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013544 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013545 final long identity = Binder.clearCallingIdentity();
13546 try {
13547 mSatelliteController.unregisterForModemStateChanged(callback);
13548 } finally {
13549 Binder.restoreCallingIdentity(identity);
13550 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013551 }
13552
13553 /**
13554 * Register to receive incoming datagrams over satellite.
13555 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013556 * @param callback The callback to handle incoming datagrams over satellite.
13557 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013558 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013559 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013560 * @throws SecurityException if the caller doesn't have the required permission.
13561 */
13562 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013563 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013564 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013565 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013566 final long identity = Binder.clearCallingIdentity();
13567 try {
13568 return mSatelliteController.registerForIncomingDatagram(callback);
13569 } finally {
13570 Binder.restoreCallingIdentity(identity);
13571 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013572 }
13573
13574 /**
13575 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013576 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013577 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013578 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013579 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013580 *
13581 * @throws SecurityException if the caller doesn't have the required permission.
13582 */
13583 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013584 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013585 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013586 final long identity = Binder.clearCallingIdentity();
13587 try {
13588 mSatelliteController.unregisterForIncomingDatagram(callback);
13589 } finally {
13590 Binder.restoreCallingIdentity(identity);
13591 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013592 }
13593
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013594 /**
13595 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013596 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013597 * This method requests modem to check if there are any pending datagrams to be received over
13598 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013599 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013600 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013601 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013602 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013603 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013604 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013605 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013606 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013607 final long identity = Binder.clearCallingIdentity();
13608 try {
13609 mSatelliteController.pollPendingDatagrams(callback);
13610 } finally {
13611 Binder.restoreCallingIdentity(identity);
13612 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013613 }
13614
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013615 /**
13616 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013617 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013618 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13619 * input to this method. Datagram received here will be passed down to modem without any
13620 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013621 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013622 * @param datagramType datagram type indicating whether the datagram is of type
13623 * SOS_SMS or LOCATION_SHARING.
13624 * @param datagram encoded gateway datagram which is encrypted by the caller.
13625 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013626 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13627 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013628 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013629 *
13630 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013631 */
13632 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013633 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013634 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13635 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013636 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013637 final long identity = Binder.clearCallingIdentity();
13638 try {
13639 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13640 callback);
13641 } finally {
13642 Binder.restoreCallingIdentity(identity);
13643 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013644 }
13645
Sarah Chindf715ec2023-02-13 13:46:24 -080013646 /**
Duke Lee8852e512024-10-06 12:55:43 +090013647 * Returns integer array of disallowed reasons of satellite.
13648 *
13649 * @return Integer array of disallowed reasons of satellite.
13650 *
13651 * @throws SecurityException if the caller doesn't have the required permission.
13652 */
13653 @NonNull public int[] getSatelliteDisallowedReasons() {
13654 enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons");
13655 final long identity = Binder.clearCallingIdentity();
13656 try {
13657 return mSatelliteAccessController.getSatelliteDisallowedReasons()
13658 .stream().mapToInt(Integer::intValue).toArray();
13659 } finally {
13660 Binder.restoreCallingIdentity(identity);
13661 }
13662 }
13663
13664 /**
13665 * Registers for disallowed reasons change event from satellite service.
13666 *
13667 * @param callback The callback to handle disallowed reasons changed event.
13668 *
13669 * @throws SecurityException if the caller doesn't have the required permission.
13670 */
13671 @Override
13672 public void registerForSatelliteDisallowedReasonsChanged(
13673 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13674 enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged");
13675 final long identity = Binder.clearCallingIdentity();
13676 try {
13677 mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback);
13678 } finally {
13679 Binder.restoreCallingIdentity(identity);
13680 }
13681 }
13682
13683 /**
13684 * Unregisters for disallowed reasons change event from satellite service.
13685 * If callback was not registered before, the request will be ignored.
13686 *
13687 * @param callback The callback to handle disallowed reasons changed event.
13688 * {@link #registerForSatelliteDisallowedReasonsChanged(
13689 * ISatelliteDisallowedReasonsCallback)}.
13690 * @throws SecurityException if the caller doesn't have the required permission.
13691 */
13692 @Override
13693 public void unregisterForSatelliteDisallowedReasonsChanged(
13694 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13695 enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged");
13696 final long identity = Binder.clearCallingIdentity();
13697 try {
13698 mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback);
13699 } finally {
13700 Binder.restoreCallingIdentity(identity);
13701 }
13702 }
13703
13704 /**
Sarah Chindf715ec2023-02-13 13:46:24 -080013705 * Request to get whether satellite communication is allowed for the current location.
13706 *
13707 * @param subId The subId of the subscription to check whether satellite communication is
13708 * allowed for the current location for.
13709 * @param result The result receiver that returns whether satellite communication is allowed
13710 * for the current location if the request is successful or an error code
13711 * if the request failed.
13712 *
13713 * @throws SecurityException if the caller doesn't have the required permission.
13714 */
13715 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013716 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013717 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013718 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013719 final long identity = Binder.clearCallingIdentity();
13720 try {
13721 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13722 false);
13723 } finally {
13724 Binder.restoreCallingIdentity(identity);
13725 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013726 }
13727
13728 /**
youngtaechaedc8a1c2024-10-15 09:07:25 +000013729 * Request to get satellite access configuration for the current location.
13730 *
13731 * @param result The result receiver that returns the satellite access configuration
13732 * for the current location if the request is successful or an error code
13733 * if the request failed.
13734 *
13735 * @throws SecurityException if the caller doesn't have the required permission.
13736 */
13737 @Override
13738 public void requestSatelliteAccessConfigurationForCurrentLocation(
13739 @NonNull ResultReceiver result) {
13740 enforceSatelliteCommunicationPermission(
13741 "requestSatelliteAccessConfigurationForCurrentLocation");
13742 final long identity = Binder.clearCallingIdentity();
13743 try {
13744 mSatelliteAccessController
13745 .requestSatelliteAccessConfigurationForCurrentLocation(result);
13746 } finally {
13747 Binder.restoreCallingIdentity(identity);
13748 }
13749 }
13750
13751 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013752 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013753 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013754 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013755 * be visible if the request is successful or an error code if the request failed.
13756 *
13757 * @throws SecurityException if the caller doesn't have the required permission.
13758 */
13759 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013760 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013761 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013762 final long identity = Binder.clearCallingIdentity();
13763 try {
13764 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13765 } finally {
13766 Binder.restoreCallingIdentity(identity);
13767 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013768 }
13769
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013770 /**
Daniel Banta99cc7532024-11-15 02:31:08 +000013771 * Request to get the currently selected satellite subscription id.
13772 *
13773 * @param result The result receiver that returns the currently selected satellite subscription
13774 * id if the request is successful or an error code if the request failed.
13775 *
13776 * @throws SecurityException if the caller doesn't have the required permission.
13777 */
13778 @Override
13779 public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) {
13780 enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId");
13781 final long identity = Binder.clearCallingIdentity();
13782 try {
13783 mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result);
13784 } finally {
13785 Binder.restoreCallingIdentity(identity);
13786 }
13787 }
13788
13789 /**
joonhunshin59104152024-09-11 09:55:35 +000013790 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013791 *
joonhunshin59104152024-09-11 09:55:35 +000013792 * @param isAligned {@code true} Device is aligned with the satellite.
13793 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013794 *
13795 * @throws SecurityException if the caller doesn't have required permission.
13796 */
13797 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13798
joonhunshin83da7cd2024-08-22 08:53:35 +000013799 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013800 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13801 final long identity = Binder.clearCallingIdentity();
13802 try {
13803 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13804 } finally {
13805 Binder.restoreCallingIdentity(identity);
13806 }
Hakjun Choiae365972023-04-25 11:00:31 +000013807 }
13808
13809 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013810 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13811 * by modem.
13812 *
13813 * @param subId The subId of the subscription to request for.
13814 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013815 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013816 * operation.
13817 *
13818 * @throws SecurityException if the caller doesn't have required permission.
13819 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013820 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013821 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13822 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013823 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013824 final long identity = Binder.clearCallingIdentity();
13825 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013826 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013827 } finally {
13828 Binder.restoreCallingIdentity(identity);
13829 }
13830 }
13831
13832 /**
13833 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13834 * by modem.
13835 *
13836 * @param subId The subId of the subscription to request for.
13837 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013838 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013839 * operation.
13840 *
13841 * @throws SecurityException if the caller doesn't have required permission.
13842 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013843 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013844 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13845 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013846 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013847 final long identity = Binder.clearCallingIdentity();
13848 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013849 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013850 } finally {
13851 Binder.restoreCallingIdentity(identity);
13852 }
13853 }
13854
13855 /**
13856 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013857 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013858 *
13859 * @param subId The subId of the subscription to request for.
13860 *
13861 * @return Integer array of reasons for disallowing satellite communication.
13862 *
13863 * @throws SecurityException if the caller doesn't have the required permission.
13864 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013865 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013866 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013867 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013868 final long identity = Binder.clearCallingIdentity();
13869 try {
13870 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013871 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013872 return reasonSet.stream().mapToInt(i->i).toArray();
13873 } finally {
13874 Binder.restoreCallingIdentity(identity);
13875 }
13876 }
13877
13878 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013879 * Request to get the signal strength of the satellite connection.
13880 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013881 * @param result Result receiver to get the error code of the request and the current signal
13882 * strength of the satellite connection.
13883 *
13884 * @throws SecurityException if the caller doesn't have required permission.
13885 */
13886 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013887 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013888 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13889 final long identity = Binder.clearCallingIdentity();
13890 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013891 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013892 } finally {
13893 Binder.restoreCallingIdentity(identity);
13894 }
13895 }
13896
13897 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013898 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13899 * is not successful, a {@link ServiceSpecificException} that contains
13900 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013901 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013902 * @param callback The callback to handle the NTN signal strength changed event. If the
13903 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13904 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13905 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13906 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013907 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013908 * @throws SecurityException If the caller doesn't have the required permission.
13909 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013910 */
13911 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013912 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013913 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013914 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13915 final long identity = Binder.clearCallingIdentity();
13916 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013917 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013918 } finally {
13919 Binder.restoreCallingIdentity(identity);
13920 }
13921 }
13922
13923 /**
13924 * Unregisters for NTN signal strength changed from satellite modem.
13925 * If callback was not registered before, the request will be ignored.
13926 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013927 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013928 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013929 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013930 *
13931 * @throws SecurityException if the caller doesn't have the required permission.
13932 */
13933 @Override
13934 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013935 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013936 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13937 final long identity = Binder.clearCallingIdentity();
13938 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013939 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013940 } finally {
13941 Binder.restoreCallingIdentity(identity);
13942 }
13943 }
13944
13945 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013946 * Registers for satellite capabilities change event from the satellite service.
13947 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013948 * @param callback The callback to handle the satellite capabilities changed event.
13949 *
13950 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13951 *
13952 * @throws SecurityException if the caller doesn't have required permission.
13953 */
13954 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013955 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013956 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013957 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013958 final long identity = Binder.clearCallingIdentity();
13959 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013960 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013961 } finally {
13962 Binder.restoreCallingIdentity(identity);
13963 }
13964 }
13965
13966 /**
13967 * Unregisters for satellite capabilities change event from the satellite service.
13968 * If callback was not registered before, the request will be ignored.
13969 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013970 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013971 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013972 *
13973 * @throws SecurityException if the caller doesn't have required permission.
13974 */
13975 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013976 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013977 @NonNull ISatelliteCapabilitiesCallback callback) {
13978 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013979 final long identity = Binder.clearCallingIdentity();
13980 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013981 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013982 } finally {
13983 Binder.restoreCallingIdentity(identity);
13984 }
13985 }
13986
13987 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013988 * Registers for the satellite supported state changed.
13989 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013990 * @param callback The callback to handle the satellite supported state changed event.
13991 *
13992 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13993 *
13994 * @throws SecurityException if the caller doesn't have the required permission.
13995 */
13996 @Override
13997 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013998 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013999 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014000 final long identity = Binder.clearCallingIdentity();
14001 try {
14002 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
14003 } finally {
14004 Binder.restoreCallingIdentity(identity);
14005 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014006 }
14007
14008 /**
14009 * Unregisters for the satellite supported state changed.
14010 * If callback was not registered before, the request will be ignored.
14011 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014012 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014013 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000014014 *
14015 * @throws SecurityException if the caller doesn't have the required permission.
14016 */
14017 @Override
14018 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014019 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014020 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014021 final long identity = Binder.clearCallingIdentity();
14022 try {
14023 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
14024 } finally {
14025 Binder.restoreCallingIdentity(identity);
14026 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014027 }
14028
14029 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014030 * This API can be used by only CTS to update satellite vendor service package name.
14031 *
14032 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000014033 * @param provisioned Whether satellite should be provisioned or not.
14034 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014035 * @return {@code true} if the satellite vendor service is set successfully,
14036 * {@code false} otherwise.
14037 */
Hakjun Choic3393242024-06-26 18:02:08 +000014038 public boolean setSatelliteServicePackageName(String servicePackageName,
14039 String provisioned) {
14040 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
14041 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014042 TelephonyPermissions.enforceShellOnly(
14043 Binder.getCallingUid(), "setSatelliteServicePackageName");
14044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14045 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14046 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014047 final long identity = Binder.clearCallingIdentity();
14048 try {
14049 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
14050 provisioned);
14051 } finally {
14052 Binder.restoreCallingIdentity(identity);
14053 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014054 }
14055
14056 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014057 * This API can be used by only CTS to update satellite gateway service package name.
14058 *
14059 * @param servicePackageName The package name of the satellite gateway service.
14060 * @return {@code true} if the satellite gateway service is set successfully,
14061 * {@code false} otherwise.
14062 */
14063 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
14064 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
14065 TelephonyPermissions.enforceShellOnly(
14066 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
14067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14068 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14069 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014070 final long identity = Binder.clearCallingIdentity();
14071 try {
14072 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
14073 } finally {
14074 Binder.restoreCallingIdentity(identity);
14075 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014076 }
14077
14078 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070014079 * This API can be used by only CTS to update satellite pointing UI app package and class names.
14080 *
14081 * @param packageName The package name of the satellite pointing UI app.
14082 * @param className The class name of the satellite pointing UI app.
14083 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
14084 * {@code false} otherwise.
14085 */
14086 public boolean setSatellitePointingUiClassName(
14087 @Nullable String packageName, @Nullable String className) {
14088 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
14089 + ", className=" + className);
14090 TelephonyPermissions.enforceShellOnly(
14091 Binder.getCallingUid(), "setSatellitePointingUiClassName");
14092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14093 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014094 "setSatellitePointingUiClassName");
14095 final long identity = Binder.clearCallingIdentity();
14096 try {
14097 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
14098 } finally {
14099 Binder.restoreCallingIdentity(identity);
14100 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070014101 }
14102
14103 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014104 * This API can be used by only CTS to update the timeout duration in milliseconds that
14105 * satellite should stay at listening mode to wait for the next incoming page before disabling
14106 * listening mode.
14107 *
14108 * @param timeoutMillis The timeout duration in millisecond.
14109 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14110 */
14111 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14112 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14113 TelephonyPermissions.enforceShellOnly(
14114 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14116 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14117 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014118 final long identity = Binder.clearCallingIdentity();
14119 try {
14120 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14121 } finally {
14122 Binder.restoreCallingIdentity(identity);
14123 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014124 }
14125
14126 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014127 * This API can be used by only CTS to control ingoring cellular service state event.
14128 *
14129 * @param enabled Whether to enable boolean config.
14130 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14131 */
14132 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014133 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014134 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014135 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14137 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014138 "setSatelliteIgnoreCellularServiceState");
14139 final long identity = Binder.clearCallingIdentity();
14140 try {
14141 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14142 } finally {
14143 Binder.restoreCallingIdentity(identity);
14144 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014145 }
14146
14147 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014148 * This API can be used by only CTS to override the timeout durations used by the
14149 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014150 *
14151 * @param timeoutMillis The timeout duration in millisecond.
14152 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14153 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014154 public boolean setDatagramControllerTimeoutDuration(
14155 boolean reset, int timeoutType, long timeoutMillis) {
14156 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14157 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014158 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014159 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14161 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014162 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014163 final long identity = Binder.clearCallingIdentity();
14164 try {
14165 return mSatelliteController.setDatagramControllerTimeoutDuration(
14166 reset, timeoutType, timeoutMillis);
14167 } finally {
14168 Binder.restoreCallingIdentity(identity);
14169 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014170 }
14171
14172 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014173 * This API can be used by only CTS to override the boolean configs used by the
14174 * DatagramController module.
14175 *
14176 * @param enable Whether to enable or disable boolean config.
14177 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14178 */
14179 public boolean setDatagramControllerBooleanConfig(
14180 boolean reset, int booleanType, boolean enable) {
14181 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14182 + ", reset=" + reset + ", enable=" + enable);
14183 TelephonyPermissions.enforceShellOnly(
14184 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14186 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14187 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014188 final long identity = Binder.clearCallingIdentity();
14189 try {
14190 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14191 enable);
14192 } finally {
14193 Binder.restoreCallingIdentity(identity);
14194 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014195 }
14196
14197
14198 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014199 * This API can be used by only CTS to override the timeout durations used by the
14200 * SatelliteController module.
14201 *
14202 * @param timeoutMillis The timeout duration in millisecond.
14203 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14204 */
14205 public boolean setSatelliteControllerTimeoutDuration(
14206 boolean reset, int timeoutType, long timeoutMillis) {
14207 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14208 + reset + ", timeoutMillis=" + timeoutMillis);
14209 TelephonyPermissions.enforceShellOnly(
14210 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14212 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14213 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014214 final long identity = Binder.clearCallingIdentity();
14215 try {
14216 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14217 reset, timeoutType, timeoutMillis);
14218 } finally {
14219 Binder.restoreCallingIdentity(identity);
14220 }
Hakjun Choiae365972023-04-25 11:00:31 +000014221 }
14222
14223 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014224 * This API can be used in only testing to override connectivity status in monitoring emergency
14225 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14226 *
14227 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14228 * of the following values to enable the override:
14229 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14230 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14231 * To disable the override, use -1 for handoverType.
14232 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14233 * delaySeconds after the emergency call starts.
14234 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14235 */
14236 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14237 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14238 TelephonyPermissions.enforceShellOnly(
14239 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14241 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14242 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014243 final long identity = Binder.clearCallingIdentity();
14244 try {
14245 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14246 handoverType, delaySeconds);
14247 } finally {
14248 Binder.restoreCallingIdentity(identity);
14249 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014250 }
14251
14252 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014253 * This API can be used in only testing to override oem-enabled satellite provision status.
14254 *
14255 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14256 * otherwise.
14257 * @param isProvisioned The overriding provision status.
14258 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14259 */
14260 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14261 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14262 + ", isProvisioned=" + isProvisioned);
14263 TelephonyPermissions.enforceShellOnly(
14264 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14266 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14267 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014268 final long identity = Binder.clearCallingIdentity();
14269 try {
14270 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14271 } finally {
14272 Binder.restoreCallingIdentity(identity);
14273 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014274 }
14275
14276 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014277 * This API should be used by only CTS tests to forcefully set telephony country codes.
14278 *
14279 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14280 */
14281 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14282 Map cachedNetworkCountryCodes, String locationCountryCode,
14283 long locationCountryCodeTimestampNanos) {
14284 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14285 + String.join(", ", currentNetworkCountryCodes)
14286 + ", locationCountryCode=" + locationCountryCode
14287 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14288 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14289 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014290 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014292 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14293 final long identity = Binder.clearCallingIdentity();
14294 try {
14295 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14296 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14297 cachedNetworkCountryCodes, locationCountryCode,
14298 locationCountryCodeTimestampNanos);
14299 } finally {
14300 Binder.restoreCallingIdentity(identity);
14301 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014302 }
14303
14304 /**
14305 * This API should be used by only CTS tests to override the overlay configs of satellite
14306 * access controller.
14307 *
14308 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14309 * otherwise.
14310 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14311 */
14312 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14313 String s2CellFile, long locationFreshDurationNanos,
14314 List<String> satelliteCountryCodes) {
14315 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14316 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14317 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14318 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
14319 ? String.join(", ", satelliteCountryCodes) : null));
14320 TelephonyPermissions.enforceShellOnly(
14321 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14323 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14324 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014325 final long identity = Binder.clearCallingIdentity();
14326 try {
14327 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
14328 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
14329 } finally {
14330 Binder.restoreCallingIdentity(identity);
14331 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014332 }
14333
14334 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014335 * This API can be used by only CTS to override the cached value for the device overlay config
14336 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14337 * outgoing satellite datagrams should be sent to modem in demo mode.
14338 *
14339 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14340 * satellite modem or not.
14341 *
14342 * @return {@code true} if the operation is successful, {@code false} otherwise.
14343 */
14344 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14345 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14346 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14347 + "disabled");
14348 return false;
14349 }
14350 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14351 TelephonyPermissions.enforceShellOnly(
14352 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14354 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14355 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014356 final long identity = Binder.clearCallingIdentity();
14357 try {
14358 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14359 shouldSendToModemInDemoMode);
14360 } finally {
14361 Binder.restoreCallingIdentity(identity);
14362 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014363 }
14364
14365 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014366 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14367 *
14368 * @param state a state indicates whether satellite access allowed state should be cached and
14369 * the allowed state.
14370 * @return {@code true} if the setting is successful, {@code false} otherwise.
14371 */
14372 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14373 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14374 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14375 + "oemEnabledSatelliteFlag is disabled");
14376 return false;
14377 }
14378
14379 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14380 + "state=" + state);
14381 TelephonyPermissions.enforceShellOnly(
14382 Binder.getCallingUid(),
14383 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14385 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14386 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014387 final long identity = Binder.clearCallingIdentity();
14388 try {
14389 return mSatelliteAccessController
14390 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14391 } finally {
14392 Binder.restoreCallingIdentity(identity);
14393 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014394 }
14395
14396 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014397 * Sets the service defined in ComponentName to be bound.
14398 *
14399 * This should only be used for testing.
14400 * @return {@code true} if the DomainSelectionService to bind to was set,
14401 * {@code false} otherwise.
14402 */
14403 @Override
14404 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14405 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14406
14407 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14408 "setDomainSelectionServiceOverride");
14409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14410 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14411
14412 final long identity = Binder.clearCallingIdentity();
14413 try {
14414 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14415 return DomainSelectionResolver.getInstance()
14416 .setDomainSelectionServiceOverride(componentName);
14417 }
14418 } finally {
14419 Binder.restoreCallingIdentity(identity);
14420 }
14421 return false;
14422 }
14423
14424 /**
14425 * Clears the DomainSelectionService override.
14426 *
14427 * This should only be used for testing.
14428 * @return {@code true} if the DomainSelectionService override was cleared,
14429 * {@code false} otherwise.
14430 */
14431 @Override
14432 public boolean clearDomainSelectionServiceOverride() {
14433 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14434
14435 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14436 "clearDomainSelectionServiceOverride");
14437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14438 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14439
14440 final long identity = Binder.clearCallingIdentity();
14441 try {
14442 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14443 return DomainSelectionResolver.getInstance()
14444 .clearDomainSelectionServiceOverride();
14445 }
14446 } finally {
14447 Binder.restoreCallingIdentity(identity);
14448 }
14449 return false;
14450 }
14451
14452 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014453 * Enable or disable notifications sent for cellular identifier disclosure events.
14454 *
14455 * Disclosure events are defined as instances where a device has sent a cellular identifier
14456 * on the Non-access stratum (NAS) before a security context is established. As a result the
14457 * identifier is sent in the clear, which has privacy implications for the user.
14458 *
14459 * @param enable if notifications about disclosure events should be enabled
14460 * @throws SecurityException if the caller does not have the required privileges
14461 * @throws UnsupportedOperationException if the modem does not support this feature.
14462 */
14463 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014464 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014465 enforceModifyPermission();
14466 checkForIdentifierDisclosureNotificationSupport();
14467
14468 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14469 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14470 editor.apply();
14471
14472 // Each phone instance is responsible for updating its respective modem immediately
14473 // after we've made a preference change.
14474 for (Phone phone : PhoneFactory.getPhones()) {
14475 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14476 }
14477 }
14478
14479 /**
14480 * Get whether or not cellular identifier disclosure notifications are enabled.
14481 *
14482 * @throws SecurityException if the caller does not have the required privileges
14483 * @throws UnsupportedOperationException if the modem does not support this feature.
14484 */
14485 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014486 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014487 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14488 checkForIdentifierDisclosureNotificationSupport();
14489 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14490 }
14491
14492 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014493 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14494 * are in use by the cellular modem.
14495 *
14496 * @throws IllegalStateException if the Telephony process is not currently available
14497 * @throws SecurityException if the caller does not have the required privileges
14498 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14499 * and integrity algorithms in use
14500 * @hide
14501 */
14502 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014503 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014504 enforceModifyPermission();
14505 checkForNullCipherNotificationSupport();
14506
14507 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14508 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14509 editor.apply();
14510
14511 // Each phone instance is responsible for updating its respective modem immediately
14512 // after a preference change.
14513 for (Phone phone : PhoneFactory.getPhones()) {
14514 phone.handleNullCipherNotificationPreferenceChanged();
14515 }
14516 }
14517
14518 /**
14519 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14520 * cellular modem.
14521 *
14522 * @throws IllegalStateException if the Telephony process is not currently available
14523 * @throws SecurityException if the caller does not have the required privileges
14524 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14525 * and integrity algorithms in use
14526 * @hide
14527 */
14528 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14529 public boolean isNullCipherNotificationsEnabled() {
14530 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14531 checkForNullCipherNotificationSupport();
14532 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14533 }
14534
14535 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014536 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14537 *
14538 * <p>This method behaves in one of the following ways:
14539 * <ul>
14540 * <li>return true : if the calling package has the appop permission {@link
14541 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14542 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14543 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14544 * Owner device identifier access check, or the calling package has carrier privileges</>
14545 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14546 * </ul>
14547 */
14548 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14549 String callingPackage, @Nullable String callingFeatureId, String message) {
14550 for (Phone phone : PhoneFactory.getPhones()) {
14551 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14552 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14553 return true;
14554 }
14555 }
14556 return false;
14557 }
arunvoddud7401012022-12-15 16:08:12 +000014558
14559 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014560 * @return The subscription manager service instance.
14561 */
14562 public SubscriptionManagerService getSubscriptionManagerService() {
14563 return SubscriptionManagerService.getInstance();
14564 }
14565
14566 /**
arunvoddud7401012022-12-15 16:08:12 +000014567 * Class binds the consumer[callback] and carrierId.
14568 */
14569 private static class CallerCallbackInfo {
14570 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014571 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014572
Steve Statia28b7cb32024-03-11 23:58:50 +000014573 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014574 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014575 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014576 }
14577
14578 public Consumer<Integer> getConsumer() {
14579 return mConsumer;
14580 }
14581
Steve Statia28b7cb32024-03-11 23:58:50 +000014582 public Set<Integer> getCarrierIds() {
14583 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014584 }
14585 }
joonhunshin4ac60942023-11-15 15:23:39 +000014586
14587 /*
14588 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14589 * But the context that is passed in is unused if the phone app is already alive.
14590 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14591 */
14592 @VisibleForTesting
14593 public void setPackageManager(PackageManager packageManager) {
14594 mPackageManager = packageManager;
14595 }
14596
14597 /*
Nate Myren453c3472024-03-13 11:28:11 -070014598 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14599 * But the context that is passed in is unused if the phone app is already alive.
14600 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14601 */
14602 @VisibleForTesting
14603 public void setAppOpsManager(AppOpsManager appOps) {
14604 mAppOps = appOps;
14605 }
14606
14607 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014608 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14609 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14610 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14611 */
14612 @VisibleForTesting
14613 public void setFeatureFlags(FeatureFlags featureFlags) {
14614 mFeatureFlags = featureFlags;
14615 }
14616
14617 /**
14618 * Make sure the device has required telephony feature
14619 *
14620 * @throws UnsupportedOperationException if the device does not have required telephony feature
14621 */
14622 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14623 @NonNull String telephonyFeature, @NonNull String methodName) {
14624 if (callingPackage == null || mPackageManager == null) {
14625 return;
14626 }
14627
14628 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14629 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014630 Binder.getCallingUserHandle())
14631 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14632 // Skip to check associated telephony feature,
14633 // if compatibility change is not enabled for the current process or
14634 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014635 return;
14636 }
14637
14638 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14639 throw new UnsupportedOperationException(
14640 methodName + " is unsupported without " + telephonyFeature);
14641 }
14642 }
youngtaecha5d483d52024-04-29 17:05:45 +000014643
14644 /**
14645 * Registers for the satellite communication allowed state changed.
14646 *
14647 * @param subId The subId of the subscription to register for the satellite communication
14648 * allowed state changed.
14649 * @param callback The callback to handle the satellite communication allowed
14650 * state changed event.
14651 *
14652 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14653 *
14654 * @throws SecurityException if the caller doesn't have the required permission.
14655 */
14656 @Override
14657 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14658 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14659 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014660 final long identity = Binder.clearCallingIdentity();
14661 try {
14662 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14663 subId, callback);
14664 } finally {
14665 Binder.restoreCallingIdentity(identity);
14666 }
youngtaecha5d483d52024-04-29 17:05:45 +000014667 }
14668
14669 /**
14670 * Unregisters for the satellite communication allowed state changed.
14671 * If callback was not registered before, the request will be ignored.
14672 *
14673 * @param subId The subId of the subscription to unregister for the satellite communication
14674 * allowed state changed.
14675 * @param callback The callback that was passed to
14676 * {@link #registerForCommunicationAllowedStateChanged(int,
14677 * ISatelliteCommunicationAllowedStateCallback)}. *
14678 * @throws SecurityException if the caller doesn't have the required permission.
14679 */
14680 @Override
14681 public void unregisterForCommunicationAllowedStateChanged(
14682 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14683 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014684 final long identity = Binder.clearCallingIdentity();
14685 try {
14686 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14687 callback);
14688 } finally {
14689 Binder.restoreCallingIdentity(identity);
14690 }
youngtaecha5d483d52024-04-29 17:05:45 +000014691 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014692
14693 /**
14694 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14695 *
14696 * @param subId The subId of the subscription to the satellite session stats for.
14697 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14698 * if the request is successful or an error code if the request failed.
14699 *
14700 * @throws SecurityException if the caller doesn't have required permission.
14701 */
14702 @Override
14703 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14704 enforceModifyPermission();
14705 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014706 final long identity = Binder.clearCallingIdentity();
14707 try {
14708 mSatelliteController.requestSatelliteSessionStats(subId, result);
14709 } finally {
14710 Binder.restoreCallingIdentity(identity);
14711 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014712 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014713
14714 /**
14715 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14716 *
14717 * @param result The result receiver, which returns the list of prioritized satellite tokens
14718 * to be used for provision if the request is successful or an error code if the request failed.
14719 *
14720 * @throws SecurityException if the caller doesn't have the required permission.
14721 */
14722 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014723 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14724 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014725 final long identity = Binder.clearCallingIdentity();
14726 try {
14727 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14728 } finally {
14729 Binder.restoreCallingIdentity(identity);
14730 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014731 }
14732
14733 /**
14734 * Deliver the list of provisioned satellite subscriber ids.
14735 *
14736 * @param list List of provisioned satellite subscriber ids.
14737 * @param result The result receiver that returns whether deliver success or fail.
14738 *
14739 * @throws SecurityException if the caller doesn't have the required permission.
14740 */
14741 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014742 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014743 @NonNull ResultReceiver result) {
14744 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014745 final long identity = Binder.clearCallingIdentity();
14746 try {
14747 mSatelliteController.provisionSatellite(list, result);
14748 } finally {
14749 Binder.restoreCallingIdentity(identity);
14750 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014751 }
Hyosund6aaf062024-08-23 23:02:10 +000014752
14753 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014754 * Deliver the list of deprovisioned satellite subscriber ids.
14755 *
14756 * @param list List of deprovisioned satellite subscriber ids.
14757 * @param result The result receiver that returns whether deliver success or fail.
14758 *
14759 * @throws SecurityException if the caller doesn't have the required permission.
14760 */
14761 @Override
14762 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14763 @NonNull ResultReceiver result) {
14764 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14765 final long identity = Binder.clearCallingIdentity();
14766 try {
14767 mSatelliteController.deprovisionSatellite(list, result);
14768 } finally {
14769 Binder.restoreCallingIdentity(identity);
14770 }
14771 }
14772
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014773
14774 /**
14775 * Inform whether application supports NTN SMS in satellite mode.
14776 *
14777 * This method is used by default messaging application to inform framework whether it supports
14778 * NTN SMS or not.
14779 *
14780 * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}.
14781 *
14782 * @throws SecurityException if the caller doesn't have required permission.
14783 */
14784 @Override
14785 public void setNtnSmsSupported(boolean ntnSmsSupported) {
14786 enforceSatelliteCommunicationPermission("setNtnSmsSupported");
14787 enforceSendSmsPermission();
14788 mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
14789 }
14790
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014791 /**
Hyosund6aaf062024-08-23 23:02:10 +000014792 * This API can be used by only CTS to override the cached value for the device overlay config
14793 * value :
14794 * config_satellite_gateway_service_package and
14795 * config_satellite_carrier_roaming_esos_provisioned_class.
14796 * These values are set before sending an intent to broadcast there are any change to list of
14797 * subscriber informations.
14798 *
14799 * @param name the name is one of the following that constitute an intent.
14800 * Component package name, or component class name.
14801 * @return {@code true} if the setting is successful, {@code false} otherwise.
14802 */
14803 @Override
14804 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14805 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14806 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14807 + " carrierRoamingNbIotNtn is disabled");
14808 return false;
14809 }
14810 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14811 TelephonyPermissions.enforceShellOnly(
14812 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14814 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14815 "setSatelliteSubscriberIdListChangedIntentComponent");
14816 final long identity = Binder.clearCallingIdentity();
14817 try {
14818 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14819 } finally {
14820 Binder.restoreCallingIdentity(identity);
14821 }
14822 }
Jack Yu26735292024-09-25 14:33:49 -070014823
14824 /**
14825 * This API can be used by only CTS to override the Euicc UI component.
14826 *
14827 * @param componentName ui component to be launched for testing. {@code null} to reset.
14828 *
14829 * @hide
14830 */
14831 @Override
14832 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14833 enforceModifyPermission();
14834 log("setTestEuiccUiComponent: " + componentName);
14835 mTestEuiccUiComponent = componentName;
14836 }
14837
14838 /**
14839 * This API can be used by only CTS to retrieve the Euicc UI component.
14840 *
14841 * @return Euicc UI component. {@code null} if not available.
14842 * @hide
14843 */
14844 @Override
14845 @Nullable
14846 public ComponentName getTestEuiccUiComponent() {
14847 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14848 return mTestEuiccUiComponent;
14849 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014850
14851 /**
14852 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14853 *
14854 * @param state to update Ntn Eligibility.
14855 * @param resetRequired to reset the overridden flag in satellite controller.
14856 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14857 */
14858 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14859 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014860 final long identity = Binder.clearCallingIdentity();
14861 try {
14862 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14863 resetRequired);
14864 } finally {
14865 Binder.restoreCallingIdentity(identity);
14866 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014867 }
Jack Yufa8ed012023-02-11 15:42:28 -080014868}