blob: a8ec8a7b70eb6e43e18573ef11bcbe924de60a7e [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;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000161import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800162import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000163import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800164import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000165import android.telephony.satellite.NtnSignalStrength;
166import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800167import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000168import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800169import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800170import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteProvisionStateCallback;
Hyosun Kimb11f3ea2024-08-07 23:35:59 +0000172import android.telephony.satellite.SatelliteSubscriberInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700175import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800177import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Andrew Lee312e8172014-10-23 17:01:36 -0700179import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800180import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800181import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800182import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800183import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700185import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700186import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800187import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800188import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800191import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700192import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800193import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800194import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000197import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800199import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800202import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800203import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700205import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700208import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800209import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700210import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700211import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700212import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700213import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800214import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800215import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700216import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700218import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700219import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800220import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800221import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700223import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000224import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700226import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700227import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800228import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700229import com.android.internal.telephony.imsphone.ImsPhone;
230import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000231import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800232import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000233import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800234import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
235import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700236import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237import com.android.internal.telephony.uicc.IccIoResult;
238import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700240import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800244import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800246import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000247import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700248import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700249import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800250import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800251import com.android.phone.callcomposer.CallComposerPictureManager;
252import com.android.phone.callcomposer.CallComposerPictureTransfer;
253import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800254import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000255import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700256import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700257import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000258import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800260import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700262import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800263import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800264import com.android.services.telephony.TelecomAccountRegistry;
265import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000266import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800267import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800268
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.IOException;
272import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700273import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000276import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800277import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800278import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800280import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100281import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800285import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700286import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800287import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800288import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800289import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291/**
292 * Implementation of the ITelephony interface.
293 */
Santos Cordon117fee72014-05-16 17:56:12 -0700294public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 private static final String LOG_TAG = "PhoneInterfaceManager";
296 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
297 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800298 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
300 // Message codes used with mMainThreadHandler
301 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
303 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 private static final int CMD_OPEN_CHANNEL = 9;
305 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
306 private static final int CMD_CLOSE_CHANNEL = 11;
307 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800308 private static final int CMD_NV_READ_ITEM = 13;
309 private static final int EVENT_NV_READ_ITEM_DONE = 14;
310 private static final int CMD_NV_WRITE_ITEM = 15;
311 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
312 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
313 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_RESET_MODEM_CONFIG = 19;
315 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800316 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
317 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800318 private static final int CMD_SEND_ENVELOPE = 25;
319 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700320 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
321 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
322 private static final int CMD_EXCHANGE_SIM_IO = 31;
323 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
325 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700326 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700328 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
329 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700330 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
331 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
332 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
333 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700334 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
335 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
336 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
337 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700338 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800339 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
340 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000341 private static final int CMD_SWITCH_SLOTS = 50;
342 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700343 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
344 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
345 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
346 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
347 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
348 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
349 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
350 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700351 private static final int CMD_GET_ALL_CELL_INFO = 60;
352 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
353 private static final int CMD_GET_CELL_LOCATION = 62;
354 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700355 private static final int CMD_MODEM_REBOOT = 64;
356 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700357 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
358 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800359 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
360 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700361 private static final int CMD_GET_MODEM_STATUS = 70;
362 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700363 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
364 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700365 private static final int CMD_ERASE_MODEM_CONFIG = 74;
366 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800367 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
368 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
369 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
370 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800371 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
372 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800374 private static final int CMD_GET_CALL_FORWARDING = 83;
375 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
376 private static final int CMD_SET_CALL_FORWARDING = 85;
377 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
378 private static final int CMD_GET_CALL_WAITING = 87;
379 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
380 private static final int CMD_SET_CALL_WAITING = 89;
381 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700382 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
383 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
384 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
385 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700386 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
387 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800388 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
389 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int CMD_SET_DATA_THROTTLING = 99;
391 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800392 private static final int CMD_SET_SIM_POWER = 101;
393 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800394 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
395 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
396 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
397 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800398 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
399 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000400 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800401 private static final int CMD_GET_SLICING_CONFIG = 110;
402 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800403 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700404 private static final int CMD_ENABLE_VONR = 113;
405 private static final int EVENT_ENABLE_VONR_DONE = 114;
406 private static final int CMD_IS_VONR_ENABLED = 115;
407 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700408 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
409 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000419 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
420 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600421 // Null cipher notification support was added in IRadioNetwork 2.2
422 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /** The singleton instance. */
425 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800426 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000429 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800430 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final CallManager mCM;
432 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000433
434 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800435 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final SharedPreferences mTelephonySharedPreferences;
439 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800440 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700441 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000442 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000443 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Jack Yu26735292024-09-25 14:33:49 -0700445 @Nullable
446 private ComponentName mTestEuiccUiComponent;
447
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800449 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800450 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800451 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800452
Derek Tan97ebb422014-09-05 16:55:38 -0700453 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
454 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800455 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800456 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700457
Michelecea4cf22018-12-21 15:00:11 -0800458 // String to store multi SIM allowed
459 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
460
Derek Tan740e1672017-06-27 14:56:27 -0700461 // The AID of ISD-R.
462 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
463
yinxub1bed742017-04-17 11:45:04 -0700464 private NetworkScanRequestTracker mNetworkScanRequestTracker;
465
David Kelly5e06a7f2018-03-12 14:10:59 +0000466 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
467 private static final int MANUFACTURER_CODE_LENGTH = 8;
468
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800469 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800470 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800471
Sarah Chin2ec39f62022-08-31 17:03:26 -0700472 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
473 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
474
Derek Tan89e89d42014-07-08 17:00:10 -0700475 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700476 * Experiment flag to enable erase modem config on reset network, default value is false
477 */
478 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
479 "reset_network_erase_modem_config_enabled";
480
Nathan Harolddc3bcec2024-05-16 14:06:40 -0700481 private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800482
Gary Jian76280a42022-12-07 16:18:33 +0800483 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
484
arunvoddub1365e62024-07-31 09:42:31 +0000485 private static final int LINE1_NUMBER_MAX_LEN = 50;
486
sandeepjsb6c87872021-09-27 15:34:44 +0000487 /**
488 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
489 * one ICCID active at the same time.
490 * Apps should use below API signatures if targeting SDK is T and beyond.
491 *
492 * @hide
493 */
494 @ChangeId
495 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
496 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800497
Naina Nallurid63128d2019-09-17 14:10:30 -0700498 /**
Chen Xu540470b2021-12-14 17:15:47 -0800499 * Apps targeting on Android T and beyond will get exception whenever icc close channel
500 * operation fails.
501 */
502 @ChangeId
503 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
504 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
505
506 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 * A request object to use for transmitting data to an ICC.
508 */
509 private static final class IccAPDUArgument {
510 public int channel, cla, command, p1, p2, p3;
511 public String data;
512
513 public IccAPDUArgument(int channel, int cla, int command,
514 int p1, int p2, int p3, String data) {
515 this.channel = channel;
516 this.cla = cla;
517 this.command = command;
518 this.p1 = p1;
519 this.p2 = p2;
520 this.p3 = p3;
521 this.data = data;
522 }
523 }
524
525 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700526 * A request object to use for transmitting data to an ICC.
527 */
528 private static final class ManualNetworkSelectionArgument {
529 public OperatorInfo operatorInfo;
530 public boolean persistSelection;
531
532 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
533 this.operatorInfo = operatorInfo;
534 this.persistSelection = persistSelection;
535 }
536 }
537
Sarah Chin71b3a852022-09-28 15:54:19 -0700538 private static final class PurchasePremiumCapabilityArgument {
539 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 public @NonNull IIntegerConsumer callback;
541
542 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800543 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700544 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700545 this.callback = callback;
546 }
547 }
548
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700549 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
551 * request after sending. The main thread will notify the request when it is complete.
552 */
553 private static final class MainThreadRequest {
554 /** The argument to use for the request */
555 public Object argument;
556 /** The result of the request that is run on the main thread */
557 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800558 // The subscriber id that this request applies to. Defaults to
559 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
560 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561
Nathan Harold92bed182018-10-12 18:16:49 -0700562 // In cases where subId is unavailable, the caller needs to specify the phone.
563 public Phone phone;
564
vagdeviaf9a5b92018-08-15 16:01:53 -0700565 public WorkSource workSource;
566
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 public MainThreadRequest(Object argument) {
568 this.argument = argument;
569 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800570
Nathan Harold92bed182018-10-12 18:16:49 -0700571 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
572 this.argument = argument;
573 if (phone != null) {
574 this.phone = phone;
575 }
576 this.workSource = workSource;
577 }
578
vagdeviaf9a5b92018-08-15 16:01:53 -0700579 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800580 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800581 if (subId != null) {
582 this.subId = subId;
583 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700584 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586 }
587
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800588 private static final class IncomingThirdPartyCallArgs {
589 public final ComponentName component;
590 public final String callId;
591 public final String callerDisplayName;
592
593 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
594 String callerDisplayName) {
595 this.component = component;
596 this.callId = callId;
597 this.callerDisplayName = callerDisplayName;
598 }
599 }
600
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 /**
602 * A handler that processes messages on the main thread in the phone process. Since many
603 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
604 * inbound binder threads to the main thread in the phone process. The Binder thread
605 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
606 * on, which will be notified when the operation completes and will contain the result of the
607 * request.
608 *
609 * <p>If a MainThreadRequest object is provided in the msg.obj field,
610 * note that request.result must be set to something non-null for the calling thread to
611 * unblock.
612 */
613 private final class MainThreadHandler extends Handler {
614 @Override
615 public void handleMessage(Message msg) {
616 MainThreadRequest request;
617 Message onCompleted;
618 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000619 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800621 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622
623 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 case CMD_HANDLE_USSD_REQUEST: {
625 request = (MainThreadRequest) msg.obj;
626 final Phone phone = getPhoneFromRequest(request);
627 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800628 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700630
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 if (!isUssdApiAllowed(request.subId)) {
632 // Carrier does not support use of this API, return failure.
633 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
634 UssdResponse response = new UssdResponse(ussdRequest, null);
635 Bundle returnData = new Bundle();
636 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
637 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 request.result = true;
640 notifyRequester(request);
641 return;
642 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700643
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 try {
645 request.result = phone != null
646 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
647 } catch (CallStateException cse) {
648 request.result = false;
649 }
650 // Wake up the requesting thread
651 notifyRequester(request);
652 break;
pkanwar32d516d2016-10-14 19:37:38 -0700653 }
654
Yorke Lee716f67e2015-06-17 15:39:16 -0700655 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700657 final Phone phone = getPhoneFromRequest(request);
658 request.result = phone != null ?
659 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
660 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000669 uiccPort = getUiccPortFromRequest(request);
670 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800672 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800676 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800678 iccArgument.channel, iccArgument.cla, iccArgument.command,
679 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
680 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
687 if (ar.exception == null && ar.result != null) {
688 request.result = ar.result;
689 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800690 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 if (ar.result == null) {
692 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800693 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800695 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 } else {
697 loge("iccTransmitApduLogicalChannel: Unknown exception");
698 }
699 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
704 request = (MainThreadRequest) msg.obj;
705 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000706 uiccPort = getUiccPortFromRequest(request);
707 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 } else {
712 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000714 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800715 iccArgument.cla, iccArgument.command, iccArgument.p1,
716 iccArgument.p2,
717 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 }
719 break;
720
721 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result;
726 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800727 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 if (ar.result == null) {
729 loge("iccTransmitApduBasicChannel: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("iccTransmitApduBasicChannel: CommandException: " +
732 ar.exception);
733 } else {
734 loge("iccTransmitApduBasicChannel: Unknown exception");
735 }
736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 break;
739
740 case CMD_EXCHANGE_SIM_IO:
741 request = (MainThreadRequest) msg.obj;
742 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
744 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700745 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800746 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700748 } else {
749 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
750 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000751 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700752 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
753 iccArgument.data, onCompleted);
754 }
755 break;
756
757 case EVENT_EXCHANGE_SIM_IO_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result;
762 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800763 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 break;
767
Derek Tan4d5e5c12014-02-04 11:54:58 -0800768 case CMD_SEND_ENVELOPE:
769 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000770 uiccPort = getUiccPortFromRequest(request);
771 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800773 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 } else {
776 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800777 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700778 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800779 break;
780
781 case EVENT_SEND_ENVELOPE_DONE:
782 ar = (AsyncResult) msg.obj;
783 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700784 if (ar.exception == null && ar.result != null) {
785 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800786 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800787 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700788 if (ar.result == null) {
789 loge("sendEnvelopeWithStatus: Empty response");
790 } else if (ar.exception instanceof CommandException) {
791 loge("sendEnvelopeWithStatus: CommandException: " +
792 ar.exception);
793 } else {
794 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
795 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800796 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800798 break;
799
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 case CMD_OPEN_CHANNEL:
801 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000802 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800803 IccLogicalChannelRequest openChannelRequest =
804 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000805 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800807 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800808 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700809 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700810 } else {
811 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800812 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
813 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 break;
816
817 case EVENT_OPEN_CHANNEL_DONE:
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700820 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700822 int[] result = (int[]) ar.result;
823 int channelId = result[0];
824 byte[] selectResponse = null;
825 if (result.length > 1) {
826 selectResponse = new byte[result.length - 1];
827 for (int i = 1; i < result.length; ++i) {
828 selectResponse[i - 1] = (byte) result[i];
829 }
830 }
831 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800832 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800833
834 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700835 if (uiccPort == null) {
836 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
837 } else {
838 IccLogicalChannelRequest channelRequest =
839 (IccLogicalChannelRequest) request.argument;
840 channelRequest.channel = channelId;
841 uiccPort.onLogicalChannelOpened(channelRequest);
842 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 if (ar.result == null) {
845 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700847 if (ar.exception != null) {
848 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
849 }
850
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700852 if (ar.exception instanceof CommandException) {
853 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800854 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700855 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700856 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700857 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700858 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700859 }
860 }
861 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800862 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700864 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700865 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700866 break;
867
868 case CMD_CLOSE_CHANNEL:
869 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000870 uiccPort = getUiccPortFromRequest(request);
871 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700872 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800873 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800874 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800875 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700876 } else {
877 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000878 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700879 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 break;
881
882 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null) {
886 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800887 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700888 if (uiccPort == null) {
889 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
890 } else {
891 final int channelId = (Integer) request.argument;
892 uiccPort.onLogicalChannelClosed(channelId);
893 }
Chen Xu540470b2021-12-14 17:15:47 -0800894 } else {
895 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800896 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800897 if (ar.exception instanceof CommandException) {
898 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
899 CommandException.Error error =
900 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800901 if (error == CommandException.Error.INVALID_ARGUMENTS) {
902 // should only throw exceptions from the binder threads.
903 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800904 "iccCloseLogicalChannel: invalid argument ");
905 }
906 } else {
907 loge("iccCloseLogicalChannel: Unknown exception");
908 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800909 request.result = (exception != null) ? exception :
910 new IllegalStateException(
911 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800912 }
913 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
916 case CMD_NV_READ_ITEM:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
920 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
923 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 ar = (AsyncResult) msg.obj;
925 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800926 if (ar.exception == null && ar.result != null) {
927 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800929 request.result = "";
930 if (ar.result == null) {
931 loge("nvReadItem: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("nvReadItem: CommandException: " +
934 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800936 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700940 break;
941
Jake Hambye994d462014-02-03 13:10:13 -0800942 case CMD_NV_WRITE_ITEM:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
945 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800946 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700947 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800948 break;
949
950 case EVENT_NV_WRITE_ITEM_DONE:
951 handleNullReturnEvent(msg, "nvWriteItem");
952 break;
953
954 case CMD_NV_WRITE_CDMA_PRL:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800957 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800958 break;
959
960 case EVENT_NV_WRITE_CDMA_PRL_DONE:
961 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
962 break;
963
chen xu6dac5ab2018-10-26 17:39:23 -0700964 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800965 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700966 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800967 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800968 break;
969
chen xu6dac5ab2018-10-26 17:39:23 -0700970 case EVENT_RESET_MODEM_CONFIG_DONE:
971 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800972 break;
973
Sooraj Sasindran37444802020-08-11 10:40:43 -0700974 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
977 request);
978 Phone phone = getPhoneFromRequest(request);
979 if (phone != null) {
980 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
981 } else {
982 loge("isNRDualConnectivityEnabled: No phone object");
983 request.result = false;
984 notifyRequester(request);
985 }
986 break;
987 }
988
989 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null && ar.result != null) {
993 request.result = ar.result;
994 } else {
995 // request.result must be set to something non-null
996 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700997 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700998 request.result = ar.result;
999 } else {
1000 request.result = false;
1001 }
1002 if (ar.result == null) {
1003 loge("isNRDualConnectivityEnabled: Empty response");
1004 } else if (ar.exception instanceof CommandException) {
1005 loge("isNRDualConnectivityEnabled: CommandException: "
1006 + ar.exception);
1007 } else {
1008 loge("isNRDualConnectivityEnabled: Unknown exception");
1009 }
1010 }
1011 notifyRequester(request);
1012 break;
1013
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001014 case CMD_IS_VONR_ENABLED: {
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1017 request);
1018 Phone phone = getPhoneFromRequest(request);
1019 if (phone != null) {
1020 phone.isVoNrEnabled(onCompleted, request.workSource);
1021 } else {
1022 loge("isVoNrEnabled: No phone object");
1023 request.result = false;
1024 notifyRequester(request);
1025 }
1026 break;
1027 }
1028
1029 case EVENT_IS_VONR_ENABLED_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null && ar.result != null) {
1033 request.result = ar.result;
1034 } else {
1035 // request.result must be set to something non-null
1036 // for the calling thread to unblock
1037 if (ar.result != null) {
1038 request.result = ar.result;
1039 } else {
1040 request.result = false;
1041 }
1042 if (ar.result == null) {
1043 loge("isVoNrEnabled: Empty response");
1044 } else if (ar.exception instanceof CommandException) {
1045 loge("isVoNrEnabled: CommandException: "
1046 + ar.exception);
1047 } else {
1048 loge("isVoNrEnabled: Unknown exception");
1049 }
1050 }
1051 notifyRequester(request);
1052 break;
1053
Sooraj Sasindran37444802020-08-11 10:40:43 -07001054 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1057 Phone phone = getPhoneFromRequest(request);
1058 if (phone != null) {
1059 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1060 request.workSource);
1061 } else {
1062 loge("enableNrDualConnectivity: No phone object");
1063 request.result =
1064 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1065 notifyRequester(request);
1066 }
1067 break;
1068 }
1069
1070 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
1073 if (ar.exception == null) {
1074 request.result =
1075 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1076 } else {
1077 request.result =
1078 TelephonyManager
1079 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1080 if (ar.exception instanceof CommandException) {
1081 CommandException.Error error =
1082 ((CommandException) (ar.exception)).getCommandError();
1083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1084 request.result =
1085 TelephonyManager
1086 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001087 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1088 request.result =
1089 TelephonyManager
1090 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001091 }
1092 loge("enableNrDualConnectivity" + ": CommandException: "
1093 + ar.exception);
1094 } else {
1095 loge("enableNrDualConnectivity" + ": Unknown exception");
1096 }
1097 }
1098 notifyRequester(request);
1099 break;
1100 }
1101
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001102 case CMD_ENABLE_VONR: {
1103 request = (MainThreadRequest) msg.obj;
1104 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1105 Phone phone = getPhoneFromRequest(request);
1106 if (phone != null) {
1107 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1108 request.workSource);
1109 } else {
1110 loge("setVoNrEnabled: No phone object");
1111 request.result =
1112 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1113 notifyRequester(request);
1114 }
1115 break;
1116 }
1117
1118 case EVENT_ENABLE_VONR_DONE: {
1119 ar = (AsyncResult) msg.obj;
1120 request = (MainThreadRequest) ar.userObj;
1121 if (ar.exception == null) {
1122 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1123 } else {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1129 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1130 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1131 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1132 } else {
1133 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1134 }
1135 loge("setVoNrEnabled" + ": CommandException: "
1136 + ar.exception);
1137 } else {
1138 loge("setVoNrEnabled" + ": Unknown exception");
1139 }
1140 }
1141 notifyRequester(request);
1142 break;
1143 }
1144
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1148 request);
1149 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 break;
1151
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 if (ar.exception == null && ar.result != null) {
1156 request.result = ar.result; // Integer
1157 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301158 // request.result must be set to something non-null
1159 // for the calling thread to unblock
1160 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 loge("getAllowedNetworkTypesBitmask: CommandException: "
1165 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001167 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 }
1169 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 break;
1172
SongFerngWang3ef3e072020-12-21 16:41:52 +08001173 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1176 request);
1177 Pair<Integer, Long> reasonWithNetworkTypes =
1178 (Pair<Integer, Long>) request.argument;
1179 getPhoneFromRequest(request).setAllowedNetworkTypes(
1180 reasonWithNetworkTypes.first,
1181 reasonWithNetworkTypes.second,
1182 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001183 break;
1184
SongFerngWang3ef3e072020-12-21 16:41:52 +08001185 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1186 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001187 break;
1188
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001189 case CMD_SET_VOICEMAIL_NUMBER:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1192 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001193 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1194 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001195 break;
1196
1197 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1198 handleNullReturnEvent(msg, "setVoicemailNumber");
1199 break;
1200
Stuart Scott54788802015-03-30 13:18:01 -07001201 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1204 request);
1205 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1206 break;
1207
1208 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1209 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1210 break;
1211
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 case CMD_PERFORM_NETWORK_SCAN:
1213 request = (MainThreadRequest) msg.obj;
1214 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1215 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1216 break;
1217
Hall Liu27d24262020-09-18 19:04:59 -07001218 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001221 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1222 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1223 request.argument;
1224 int callForwardingReason = args.first;
1225 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
Hall Liu27d24262020-09-18 19:04:59 -07001227 }
1228 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001229 ar = (AsyncResult) msg.obj;
1230 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001231 TelephonyManager.CallForwardingInfoCallback callback =
1232 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1233 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001235 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001236 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1237 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1238 // Service Class is a bit mask per 3gpp 27.007. Search for
1239 // any service for voice call.
1240 if ((callForwardInfo.serviceClass
1241 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001242 callForwardingInfo = new CallForwardingInfo(
1243 callForwardInfo.status
1244 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001245 callForwardInfo.reason,
1246 callForwardInfo.number,
1247 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
1249 }
1250 }
1251 // Didn't find a call forward info for voice call.
1252 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001253 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1254 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
Hall Liu27d24262020-09-18 19:04:59 -07001256 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 } else {
1258 if (ar.result == null) {
1259 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1260 }
1261 if (ar.exception != null) {
1262 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1263 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001264 int errorCode = TelephonyManager
1265 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager
1271 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001273 errorCode = TelephonyManager
1274 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
1276 }
Hall Liu27d24262020-09-18 19:04:59 -07001277 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281
Hall Liu27d24262020-09-18 19:04:59 -07001282 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001283 request = (MainThreadRequest) msg.obj;
1284 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001285 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001286 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001287 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1288 request.argument).first;
1289 request.phone.setCallForwardingOption(
1290 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001291 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001292 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001293 callForwardingInfoToSet.getReason(),
1294 callForwardingInfoToSet.getNumber(),
1295 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1296 break;
Hall Liu27d24262020-09-18 19:04:59 -07001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298
Hall Liu27d24262020-09-18 19:04:59 -07001299 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001300 ar = (AsyncResult) msg.obj;
1301 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001302 Consumer<Integer> callback =
1303 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1304 request.argument).second;
1305 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001306 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001307 int errorCode = TelephonyManager.CallForwardingInfoCallback
1308 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001309 if (ar.exception instanceof CommandException) {
1310 CommandException.Error error =
1311 ((CommandException) (ar.exception)).getCommandError();
1312 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001313 errorCode = TelephonyManager.CallForwardingInfoCallback
1314 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001315 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001316 errorCode = TelephonyManager.CallForwardingInfoCallback
1317 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
1319 }
1320 callback.accept(errorCode);
1321 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001322 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001323 }
Shuo Qian4a594052020-01-23 11:59:30 -08001324 break;
Hall Liu27d24262020-09-18 19:04:59 -07001325 }
Shuo Qian4a594052020-01-23 11:59:30 -08001326
Hall Liu27d24262020-09-18 19:04:59 -07001327 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001328 request = (MainThreadRequest) msg.obj;
1329 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1330 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1331 break;
Hall Liu27d24262020-09-18 19:04:59 -07001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333
Hall Liu27d24262020-09-18 19:04:59 -07001334 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001337 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001340 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 // Service Class is a bit mask per 3gpp 27.007.
1342 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001343 if (callForwardResults.length > 1
1344 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001345 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001347 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1348 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001349 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001350 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001351 }
1352 } else {
1353 if (ar.result == null) {
1354 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1355 }
1356 if (ar.exception != null) {
1357 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1358 }
1359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001363 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001364 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001365 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1366 callWaitingStatus =
1367 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001368 }
1369 }
1370 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001371 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001372 break;
Hall Liu27d24262020-09-18 19:04:59 -07001373 }
Shuo Qian4a594052020-01-23 11:59:30 -08001374
Hall Liu27d24262020-09-18 19:04:59 -07001375 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001376 request = (MainThreadRequest) msg.obj;
1377 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001378 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1379 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001380 break;
Hall Liu27d24262020-09-18 19:04:59 -07001381 }
Shuo Qian4a594052020-01-23 11:59:30 -08001382
Hall Liu27d24262020-09-18 19:04:59 -07001383 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001386 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1387 Consumer<Integer> callback =
1388 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1389 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001390 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001391 if (ar.exception instanceof CommandException) {
1392 CommandException.Error error =
1393 ((CommandException) (ar.exception)).getCommandError();
1394 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001396 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1397 callback.accept(
1398 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001399 } else {
1400 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1401 }
1402 } else {
1403 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1404 }
1405 } else {
1406 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1407 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001408 }
Shuo Qian4a594052020-01-23 11:59:30 -08001409 break;
Hall Liu27d24262020-09-18 19:04:59 -07001410 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001411 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 CellNetworkScanResult cellScanResult;
1415 if (ar.exception == null && ar.result != null) {
1416 cellScanResult = new CellNetworkScanResult(
1417 CellNetworkScanResult.STATUS_SUCCESS,
1418 (List<OperatorInfo>) ar.result);
1419 } else {
1420 if (ar.result == null) {
1421 loge("getCellNetworkScanResults: Empty response");
1422 }
1423 if (ar.exception != null) {
1424 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1425 }
1426 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1427 if (ar.exception instanceof CommandException) {
1428 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001429 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1431 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1432 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1433 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1434 }
1435 }
1436 cellScanResult = new CellNetworkScanResult(errorCode, null);
1437 }
1438 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001440 break;
1441
1442 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1443 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001444 ManualNetworkSelectionArgument selArg =
1445 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001446 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1447 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001448 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1449 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001450 break;
1451
1452 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 if (ar.exception == null) {
1456 request.result = true;
1457 } else {
1458 request.result = false;
1459 loge("setNetworkSelectionModeManual " + ar.exception);
1460 }
1461 notifyRequester(request);
1462 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001463 break;
1464
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 case CMD_GET_MODEM_ACTIVITY_INFO:
1466 request = (MainThreadRequest) msg.obj;
1467 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001468 if (defaultPhone != null) {
1469 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001470 } else {
1471 ResultReceiver result = (ResultReceiver) request.argument;
1472 Bundle bundle = new Bundle();
1473 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001474 new ModemActivityInfo(0, 0, 0,
1475 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001476 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001477 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 break;
1479
Hall Liud0f208c2020-10-14 16:54:44 -07001480 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001481 ar = (AsyncResult) msg.obj;
1482 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001483 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001484 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001485 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001486 if (mLastModemActivityInfo == null) {
1487 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1488 mLastModemActivitySpecificInfo[0] =
1489 new ActivityStatsTechSpecificInfo(
1490 0,
1491 0,
1492 new int[ModemActivityInfo.getNumTxPowerLevels()],
1493 0);
1494 mLastModemActivityInfo =
1495 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1496 }
1497
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001498 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001499 // Update the last modem activity info and the result of the request.
1500 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1501 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001502 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001503 } else {
1504 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001505 }
Kai Shi917fdc62022-11-28 14:01:02 -08001506 // This is needed to decouple ret from mLastModemActivityInfo
1507 // We don't want to return mLastModemActivityInfo which is updated
1508 // inside mergeModemActivityInfo()
1509 ret = new ModemActivityInfo(
1510 mLastModemActivityInfo.getTimestampMillis(),
1511 mLastModemActivityInfo.getSleepTimeMillis(),
1512 mLastModemActivityInfo.getIdleTimeMillis(),
1513 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001514
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else {
1516 if (ar.result == null) {
1517 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001518 error = TelephonyManager.ModemActivityInfoException
1519 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001521 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001522 error = TelephonyManager.ModemActivityInfoException
1523 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524 } else {
1525 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001526 error = TelephonyManager.ModemActivityInfoException
1527 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001528 }
1529 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001530 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001531 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001532 bundle.putParcelable(
1533 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001534 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001535 } else {
1536 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1537 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001538 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001539 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001540 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001541 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001542
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001543 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001545 CarrierRestrictionRules argument =
1546 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001548 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001550 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551
1552 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1553 ar = (AsyncResult) msg.obj;
1554 request = (MainThreadRequest) ar.userObj;
1555 if (ar.exception == null && ar.result != null) {
1556 request.result = ar.result;
1557 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001558 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1559 if (ar.exception instanceof CommandException) {
1560 loge("setAllowedCarriers: CommandException: " + ar.exception);
1561 CommandException.Error error =
1562 ((CommandException) (ar.exception)).getCommandError();
1563 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1564 request.result =
1565 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1566 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 } else {
1568 loge("setAllowedCarriers: Unknown exception");
1569 }
1570 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001572 break;
1573
1574 case CMD_GET_ALLOWED_CARRIERS:
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001577 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001578 break;
1579
1580 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1581 ar = (AsyncResult) msg.obj;
1582 request = (MainThreadRequest) ar.userObj;
1583 if (ar.exception == null && ar.result != null) {
1584 request.result = ar.result;
1585 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001586 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001587 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001588 if (ar.result == null) {
1589 loge("getAllowedCarriers: Empty response");
1590 } else if (ar.exception instanceof CommandException) {
1591 loge("getAllowedCarriers: CommandException: " +
1592 ar.exception);
1593 } else {
1594 loge("getAllowedCarriers: Unknown exception");
1595 }
1596 }
arunvoddud7401012022-12-15 16:08:12 +00001597 if (request.argument != null) {
1598 // This is for the implementation of carrierRestrictionStatus.
1599 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1600 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001601 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001602 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1603 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1604 CarrierRestrictionRules carrierRestrictionRules =
1605 (CarrierRestrictionRules) ar.result;
1606 int carrierId = -1;
1607 try {
1608 CarrierIdentifier carrierIdentifier =
1609 carrierRestrictionRules.getAllowedCarriers().get(0);
1610 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1611 carrierIdentifier);
1612 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1613 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1614 }
1615 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001616 int restrictedStatus =
1617 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1618 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1619 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001620 lockStatus = TelephonyManager
1621 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001622 }
1623 } else {
1624 Rlog.e(LOG_TAG,
1625 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1626 }
1627 callback.accept(lockStatus);
1628 } else {
1629 // This is for the implementation of getAllowedCarriers.
1630 notifyRequester(request);
1631 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001632 break;
1633
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1635 ar = (AsyncResult) msg.obj;
1636 request = (MainThreadRequest) ar.userObj;
1637 if (ar.exception == null && ar.result != null) {
1638 request.result = ar.result;
1639 } else {
1640 request.result = new IllegalArgumentException(
1641 "Failed to retrieve Forbidden Plmns");
1642 if (ar.result == null) {
1643 loge("getForbiddenPlmns: Empty response");
1644 } else {
1645 loge("getForbiddenPlmns: Unknown exception");
1646 }
1647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001648 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 break;
1650
1651 case CMD_GET_FORBIDDEN_PLMNS:
1652 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 uiccPort = getUiccPortFromRequest(request);
1654 if (uiccPort == null) {
1655 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001657 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 break;
1660 }
1661 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001662 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 if (uiccApp == null) {
1664 loge("getForbiddenPlmns() no app with specified type -- "
1665 + appType);
1666 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001667 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001668 break;
1669 } else {
1670 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1671 + " specified type -- " + appType);
1672 }
1673 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1674 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001675 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001676 break;
1677
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 case CMD_SWITCH_SLOTS:
1679 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001680 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001681 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001682 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001683 break;
1684
1685 case EVENT_SWITCH_SLOTS_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001689 notifyRequester(request);
1690 break;
1691 case CMD_GET_NETWORK_SELECTION_MODE:
1692 request = (MainThreadRequest) msg.obj;
1693 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1694 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1695 break;
1696
1697 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception != null) {
1701 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1702 } else {
1703 int mode = ((int[]) ar.result)[0];
1704 if (mode == 0) {
1705 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1706 } else {
1707 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1708 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001710 notifyRequester(request);
1711 break;
1712 case CMD_GET_CDMA_ROAMING_MODE:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1715 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1716 break;
1717 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1718 ar = (AsyncResult) msg.obj;
1719 request = (MainThreadRequest) ar.userObj;
1720 if (ar.exception != null) {
1721 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1722 } else {
1723 request.result = ((int[]) ar.result)[0];
1724 }
1725 notifyRequester(request);
1726 break;
1727 case CMD_SET_CDMA_ROAMING_MODE:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1730 int mode = (int) request.argument;
1731 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1732 break;
1733 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 request.result = ar.exception == null;
1737 notifyRequester(request);
1738 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001739 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1740 request = (MainThreadRequest) msg.obj;
1741 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1742 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1743 break;
1744 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1745 ar = (AsyncResult) msg.obj;
1746 request = (MainThreadRequest) ar.userObj;
1747 if (ar.exception != null) {
1748 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1749 } else {
1750 request.result = ((int[]) ar.result)[0];
1751 }
1752 notifyRequester(request);
1753 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001754 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1755 request = (MainThreadRequest) msg.obj;
1756 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1757 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001758 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1759 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001760 break;
1761 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 request.result = ar.exception == null;
1765 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001766 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 case CMD_GET_ALL_CELL_INFO:
1768 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001770 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001771 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001772 case EVENT_GET_ALL_CELL_INFO_DONE:
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001775 // If a timeout occurs, the response will be null
1776 request.result = (ar.exception == null && ar.result != null)
1777 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001778 synchronized (request) {
1779 request.notifyAll();
1780 }
1781 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001782 case CMD_REQUEST_CELL_INFO_UPDATE:
1783 request = (MainThreadRequest) msg.obj;
1784 request.phone.requestCellInfoUpdate(request.workSource,
1785 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1786 break;
1787 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1791 try {
1792 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001794 cb.onError(
1795 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1796 ar.exception.getClass().getName(),
1797 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001798 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001799 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001800 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001801 } else {
1802 // use the result as returned
1803 cb.onCellInfo((List<CellInfo>) ar.result);
1804 }
1805 } catch (RemoteException re) {
1806 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1807 }
1808 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 request = (MainThreadRequest) msg.obj;
1811 WorkSource ws = (WorkSource) request.argument;
1812 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001813 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001814 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001815 }
1816 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null) {
1820 request.result = ar.result;
1821 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001823 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001824 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001825 }
1826
1827 synchronized (request) {
1828 request.notifyAll();
1829 }
1830 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001831 }
chen xu6dac5ab2018-10-26 17:39:23 -07001832 case CMD_MODEM_REBOOT:
1833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001835 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001836 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001837 case EVENT_CMD_MODEM_REBOOT_DONE:
1838 handleNullReturnEvent(msg, "rebootModem");
1839 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001840 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 request = (MainThreadRequest) msg.obj;
1842 boolean enable = (boolean) request.argument;
1843 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001844 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001845 PhoneConfigurationManager.getInstance()
1846 .enablePhone(request.phone, enable, onCompleted);
1847 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001848 }
Michele Berionne5e411512020-11-13 02:36:59 +00001849 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001853 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001854 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001855 if ((boolean) request.result) {
1856 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1857 updateModemStateMetrics();
1858 } else {
1859 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1860 + ar.exception);
1861 }
1862 notifyRequester(request);
1863 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001865 case CMD_GET_MODEM_STATUS:
1866 request = (MainThreadRequest) msg.obj;
1867 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1868 PhoneConfigurationManager.getInstance()
1869 .getPhoneStatusFromModem(request.phone, onCompleted);
1870 break;
1871 case EVENT_GET_MODEM_STATUS_DONE:
1872 ar = (AsyncResult) msg.obj;
1873 request = (MainThreadRequest) ar.userObj;
1874 int id = request.phone.getPhoneId();
1875 if (ar.exception == null && ar.result != null) {
1876 request.result = ar.result;
1877 //update the cache as modem status has changed
1878 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1879 (boolean) request.result);
1880 } else {
1881 // Return true if modem status cannot be retrieved. For most cases,
1882 // modem status is on. And for older version modems, GET_MODEM_STATUS
1883 // and disable modem are not supported. Modem is always on.
1884 // TODO: this should be fixed in R to support a third
1885 // status UNKNOWN b/131631629
1886 request.result = true;
1887 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1888 + ar.exception);
1889 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001890 notifyRequester(request);
1891 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001892 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1895 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1896 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1897 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1898 break;
1899 }
1900 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1901 ar = (AsyncResult) msg.obj;
1902 request = (MainThreadRequest) ar.userObj;
1903 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1904 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1905 args.second.accept(ar.exception == null);
1906 notifyRequester(request);
1907 break;
1908 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001909 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1912 Phone phone = getPhoneFromRequest(request);
1913 if (phone != null) {
1914 phone.getSystemSelectionChannels(onCompleted);
1915 } else {
1916 loge("getSystemSelectionChannels: No phone object");
1917 request.result = new ArrayList<RadioAccessSpecifier>();
1918 notifyRequester(request);
1919 }
1920 break;
1921 }
1922 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 if (ar.exception == null && ar.result != null) {
1926 request.result = ar.result;
1927 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001928 request.result = new IllegalStateException(
1929 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001930 if (ar.result == null) {
1931 loge("getSystemSelectionChannels: Empty response");
1932 } else {
1933 loge("getSystemSelectionChannels: Unknown exception");
1934 }
1935 }
1936 notifyRequester(request);
1937 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001938 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 if (ar.exception == null && ar.result != null) {
1942 request.result = ar.result;
1943 } else {
1944 request.result = -1;
1945 loge("Failed to set Forbidden Plmns");
1946 if (ar.result == null) {
1947 loge("setForbidenPlmns: Empty response");
1948 } else if (ar.exception != null) {
1949 loge("setForbiddenPlmns: Exception: " + ar.exception);
1950 request.result = -1;
1951 } else {
1952 loge("setForbiddenPlmns: Unknown exception");
1953 }
1954 }
1955 notifyRequester(request);
1956 break;
1957 case CMD_SET_FORBIDDEN_PLMNS:
1958 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001959 uiccPort = getUiccPortFromRequest(request);
1960 if (uiccPort == null) {
1961 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001962 request.result = -1;
1963 notifyRequester(request);
1964 break;
1965 }
1966 Pair<Integer, List<String>> setFplmnsArgs =
1967 (Pair<Integer, List<String>>) request.argument;
1968 appType = setFplmnsArgs.first;
1969 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001970 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001971 if (uiccApp == null) {
1972 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1973 request.result = -1;
1974 loge("Failed to get UICC App");
1975 notifyRequester(request);
1976 } else {
1977 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1978 ((SIMRecords) uiccApp.getIccRecords())
1979 .setForbiddenPlmns(onCompleted, fplmns);
1980 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001981 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001982 case CMD_ERASE_MODEM_CONFIG:
1983 request = (MainThreadRequest) msg.obj;
1984 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1985 defaultPhone.eraseModemConfig(onCompleted);
1986 break;
1987 case EVENT_ERASE_MODEM_CONFIG_DONE:
1988 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001989 break;
zoey chene02881a2019-12-30 16:11:23 +08001990
Kai Shif70f46f2021-03-03 13:59:46 -08001991 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1992 request = (MainThreadRequest) msg.obj;
1993 request.result = defaultPhone.eraseDataInSharedPreferences();
1994 notifyRequester(request);
1995 break;
1996
zoey chene02881a2019-12-30 16:11:23 +08001997 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2000 Pair<String, String> changed = (Pair<String, String>) request.argument;
2001 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2002 changed.first, changed.second, onCompleted);
2003 break;
2004 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 if (ar.exception == null) {
2008 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002009 // If the operation is successful, update the PIN storage
2010 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2011 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002012 UiccController.getInstance().getPinStorage()
2013 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002014 } else {
2015 request.result = msg.arg1;
2016 }
2017 notifyRequester(request);
2018 break;
2019
Michele Berionne5e411512020-11-13 02:36:59 +00002020 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002021 request = (MainThreadRequest) msg.obj;
2022 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2023 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2024 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2025 enabled.first, enabled.second, onCompleted);
2026 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002027 }
zoey chene02881a2019-12-30 16:11:23 +08002028 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 if (ar.exception == null) {
2032 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002033 // If the operation is successful, update the PIN storage
2034 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2035 int phoneId = getPhoneFromRequest(request).getPhoneId();
2036 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002037 UiccController.getInstance().getPinStorage()
2038 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002039 } else {
2040 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2041 }
zoey chene02881a2019-12-30 16:11:23 +08002042 } else {
2043 request.result = msg.arg1;
2044 }
Michele Berionne5e411512020-11-13 02:36:59 +00002045
2046
zoey chene02881a2019-12-30 16:11:23 +08002047 notifyRequester(request);
2048 break;
2049
Peter Wangdafb9ac2020-01-15 14:13:38 -08002050 case MSG_NOTIFY_USER_ACTIVITY:
2051 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002052 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002053 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2054 getDefaultPhone().getContext().sendBroadcastAsUser(
2055 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2056 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002057
2058 case CMD_SET_DATA_THROTTLING: {
2059 request = (MainThreadRequest) msg.obj;
2060 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2061 DataThrottlingRequest dataThrottlingRequest =
2062 (DataThrottlingRequest) request.argument;
2063 Phone phone = getPhoneFromRequest(request);
2064 if (phone != null) {
2065 phone.setDataThrottling(onCompleted,
2066 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2067 dataThrottlingRequest.getCompletionDurationMillis());
2068 } else {
2069 loge("setDataThrottling: No phone object");
2070 request.result =
2071 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2072 notifyRequester(request);
2073 }
2074
2075 break;
2076 }
2077 case EVENT_SET_DATA_THROTTLING_DONE:
2078 ar = (AsyncResult) msg.obj;
2079 request = (MainThreadRequest) ar.userObj;
2080
2081 if (ar.exception == null) {
2082 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2083 } else if (ar.exception instanceof CommandException) {
2084 loge("setDataThrottling: CommandException: " + ar.exception);
2085 CommandException.Error error =
2086 ((CommandException) (ar.exception)).getCommandError();
2087
2088 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2089 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002090 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002091 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2092 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002093 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2094 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002095 } else {
2096 request.result =
2097 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2098 }
2099 } else {
2100 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2101 }
2102 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2103 notifyRequester(request);
2104 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002105
2106 case CMD_SET_SIM_POWER: {
2107 request = (MainThreadRequest) msg.obj;
2108 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2109 request = (MainThreadRequest) msg.obj;
2110 int stateToSet =
2111 ((Pair<Integer, IIntegerConsumer>)
2112 request.argument).first;
2113 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2114 break;
2115 }
2116 case EVENT_SET_SIM_POWER_DONE: {
2117 ar = (AsyncResult) msg.obj;
2118 request = (MainThreadRequest) ar.userObj;
2119 IIntegerConsumer callback =
2120 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2121 if (ar.exception != null) {
2122 loge("setSimPower exception: " + ar.exception);
2123 int errorCode = TelephonyManager.CallForwardingInfoCallback
2124 .RESULT_ERROR_UNKNOWN;
2125 if (ar.exception instanceof CommandException) {
2126 CommandException.Error error =
2127 ((CommandException) (ar.exception)).getCommandError();
2128 if (error == CommandException.Error.SIM_ERR) {
2129 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2130 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2132 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2133 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2134 } else {
2135 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2136 }
2137 }
2138 try {
2139 callback.accept(errorCode);
2140 } catch (RemoteException e) {
2141 // Ignore if the remote process is no longer available to call back.
2142 Log.w(LOG_TAG, "setSimPower: callback not available.");
2143 }
2144 } else {
2145 try {
2146 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2147 } catch (RemoteException e) {
2148 // Ignore if the remote process is no longer available to call back.
2149 Log.w(LOG_TAG, "setSimPower: callback not available.");
2150 }
2151 }
2152 break;
2153 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002154 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2155 request = (MainThreadRequest) msg.obj;
2156
2157 final Phone phone = getPhoneFromRequest(request);
2158 if (phone == null || phone.getServiceStateTracker() == null) {
2159 request.result = new IllegalStateException("Phone or SST is null");
2160 notifyRequester(request);
2161 break;
2162 }
2163
2164 Pair<Integer, SignalStrengthUpdateRequest> pair =
2165 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2166 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2167 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002168 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002169 request.subId, pair.first /*callingUid*/,
2170 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002171 break;
2172 }
2173 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2174 ar = (AsyncResult) msg.obj;
2175 request = (MainThreadRequest) ar.userObj;
2176 // request.result will be the exception of ar if present, true otherwise.
2177 // Be cautious not to leave result null which will wait() forever
2178 request.result = ar.exception != null ? ar.exception : true;
2179 notifyRequester(request);
2180 break;
2181 }
2182 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2183 request = (MainThreadRequest) msg.obj;
2184
2185 Phone phone = getPhoneFromRequest(request);
2186 if (phone == null || phone.getServiceStateTracker() == null) {
2187 request.result = new IllegalStateException("Phone or SST is null");
2188 notifyRequester(request);
2189 break;
2190 }
2191
2192 Pair<Integer, SignalStrengthUpdateRequest> pair =
2193 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2194 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2195 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002196 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002197 request.subId, pair.first /*callingUid*/,
2198 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002199 break;
2200 }
2201 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2202 ar = (AsyncResult) msg.obj;
2203 request = (MainThreadRequest) ar.userObj;
2204 request.result = ar.exception != null ? ar.exception : true;
2205 notifyRequester(request);
2206 break;
2207 }
Jordan Liu109698e2020-11-24 14:50:34 -08002208
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 case CMD_GET_SLICING_CONFIG: {
2210 request = (MainThreadRequest) msg.obj;
2211 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2212 request.phone.getSlicingConfig(onCompleted);
2213 break;
2214 }
2215 case EVENT_GET_SLICING_CONFIG_DONE: {
2216 ar = (AsyncResult) msg.obj;
2217 request = (MainThreadRequest) ar.userObj;
2218 ResultReceiver result = (ResultReceiver) request.argument;
2219
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002221 Bundle bundle = new Bundle();
2222 int resultCode = 0;
2223 if (ar.exception != null) {
2224 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2225 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002226 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002227 } else if (ar.result == null) {
2228 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002229 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002230 } else {
2231 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002232 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2233 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002234 }
2235
2236 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002237 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002238 }
2239 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2240 result.send(resultCode, bundle);
2241 notifyRequester(request);
2242 break;
2243 }
2244
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 request = (MainThreadRequest) msg.obj;
2247 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 PurchasePremiumCapabilityArgument arg =
2249 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002250 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2251 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 ar = (AsyncResult) msg.obj;
2257 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 PurchasePremiumCapabilityArgument arg =
2259 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002260 try {
2261 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002262 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002265 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002266 + TelephonyManager.convertPurchaseResultToString(result));
2267 } catch (RemoteException e) {
2268 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002269 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002270 + " failed: " + e;
2271 if (DBG) log(logStr);
2272 AnomalyReporter.reportAnomaly(
2273 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2274 }
2275 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002276 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002277
Michele Berionne5e411512020-11-13 02:36:59 +00002278 case CMD_PREPARE_UNATTENDED_REBOOT:
2279 request = (MainThreadRequest) msg.obj;
2280 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002281 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002282 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002283 notifyRequester(request);
2284 break;
2285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 default:
2287 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2288 break;
2289 }
2290 }
Jake Hambye994d462014-02-03 13:10:13 -08002291
Pengquan Menga1bb6272018-09-06 09:59:22 -07002292 private void notifyRequester(MainThreadRequest request) {
2293 synchronized (request) {
2294 request.notifyAll();
2295 }
2296 }
2297
Jake Hambye994d462014-02-03 13:10:13 -08002298 private void handleNullReturnEvent(Message msg, String command) {
2299 AsyncResult ar = (AsyncResult) msg.obj;
2300 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2301 if (ar.exception == null) {
2302 request.result = true;
2303 } else {
2304 request.result = false;
2305 if (ar.exception instanceof CommandException) {
2306 loge(command + ": CommandException: " + ar.exception);
2307 } else {
2308 loge(command + ": Unknown exception");
2309 }
2310 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002311 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete, and returns the result.
2318 * @see #sendRequestAsync
2319 */
2320 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2322 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002323 }
2324
2325 /**
2326 * Posts the specified command to be executed on the main thread,
2327 * waits for the request to complete, and returns the result.
2328 * @see #sendRequestAsync
2329 */
2330 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2331 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002340 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2342 }
2343
2344 /**
2345 * Posts the specified command to be executed on the main thread,
2346 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2347 * if not timeout or null otherwise.
2348 * @see #sendRequestAsync
2349 */
2350 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2351 long timeoutInMs) {
2352 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002353 }
2354
2355 /**
2356 * Posts the specified command to be executed on the main thread,
2357 * waits for the request to complete, and returns the result.
2358 * @see #sendRequestAsync
2359 */
Nathan Harold92bed182018-10-12 18:16:49 -07002360 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002361 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002362 }
2363
2364 /**
2365 * Posts the specified command to be executed on the main thread,
2366 * waits for the request to complete, and returns the result.
2367 * @see #sendRequestAsync
2368 */
2369 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2371 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002372 }
2373
2374 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2376 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2377 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002378 * @see #sendRequestAsync
2379 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2381 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2383 throw new RuntimeException("This method will deadlock if called from the main thread.");
2384 }
2385
Nathan Harold92bed182018-10-12 18:16:49 -07002386 MainThreadRequest request = null;
2387 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2388 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2389 } else if (phone != null) {
2390 request = new MainThreadRequest(argument, phone, workSource);
2391 } else {
2392 request = new MainThreadRequest(argument, subId, workSource);
2393 }
2394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 Message msg = mMainThreadHandler.obtainMessage(command, request);
2396 msg.sendToTarget();
2397
Rambo Wang0f050d82021-02-12 11:43:36 -08002398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 if (timeoutInMs >= 0) {
2401 // Wait for at least timeoutInMs before returning null request result
2402 long now = SystemClock.elapsedRealtime();
2403 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002404 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002405 try {
2406 request.wait(deadline - now);
2407 } catch (InterruptedException e) {
2408 // Do nothing, go back and check if request is completed or timeout
2409 } finally {
2410 now = SystemClock.elapsedRealtime();
2411 }
2412 }
2413 } else {
2414 // Wait for the request to complete
2415 while (request.result == null) {
2416 try {
2417 request.wait();
2418 } catch (InterruptedException e) {
2419 // Do nothing, go back and wait until the request is complete
2420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422 }
2423 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002424 if (request.result == null) {
2425 Log.wtf(LOG_TAG,
2426 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 return request.result;
2429 }
2430
2431 /**
2432 * Asynchronous ("fire and forget") version of sendRequest():
2433 * Posts the specified command to be executed on the main thread, and
2434 * returns immediately.
2435 * @see #sendRequest
2436 */
2437 private void sendRequestAsync(int command) {
2438 mMainThreadHandler.sendEmptyMessage(command);
2439 }
2440
2441 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002442 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002443 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002444 */
2445 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002446 sendRequestAsync(command, argument, null, null);
2447 }
2448
2449 /**
2450 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2451 * @see {@link #sendRequest(int,Object)}
2452 */
2453 private void sendRequestAsync(
2454 int command, Object argument, Phone phone, WorkSource workSource) {
2455 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002456 Message msg = mMainThreadHandler.obtainMessage(command, request);
2457 msg.sendToTarget();
2458 }
2459
2460 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 * Initialize the singleton PhoneInterfaceManager instance.
2462 * This is only done once, at startup, from PhoneApp.onCreate().
2463 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 synchronized (PhoneInterfaceManager.class) {
2466 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002467 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 } else {
2469 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2470 }
2471 return sInstance;
2472 }
2473 }
2474
2475 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002476 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002478 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002479 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002481 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002482 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002483 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2485 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002486 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002487 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002488 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002489 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002490 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002491 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002492 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2493 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002494 mVendorApiLevel = SystemProperties.getInt(
2495 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2496
Tyler Gunn64144d92022-03-17 14:16:41 -07002497 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 publish();
arunvoddud7401012022-12-15 16:08:12 +00002499 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002500
2501 // Create the SatelliteEntitlementController singleton, for using the get the
2502 // entitlementStatus for satellite service.
2503 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002506 @VisibleForTesting
2507 public SharedPreferences getSharedPreferences() {
2508 return mTelephonySharedPreferences;
2509 }
2510
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002511 /**
2512 * Get the default phone for this device.
2513 */
2514 @VisibleForTesting
2515 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002516 Phone thePhone = getPhone(getDefaultSubscription());
2517 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2518 }
2519
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 private void publish() {
2521 if (DBG) log("publish: " + this);
2522
Peter Wangc035ce42020-01-08 21:00:22 -08002523 TelephonyFrameworkInitializer
2524 .getTelephonyServiceManager()
2525 .getTelephonyServiceRegisterer()
2526 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
Stuart Scott584921c2015-01-15 17:10:34 -08002529 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002530 if (request.phone != null) {
2531 return request.phone;
2532 } else {
2533 return getPhoneFromSubId(request.subId);
2534 }
2535 }
2536
2537 private Phone getPhoneFromSubId(int subId) {
2538 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2539 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002540 }
2541
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002542 /**
2543 * Get phone object associated with a subscription.
2544 * Return default phone if phone object associated with subscription is null
2545 * @param subId - subscriptionId
2546 * @return phone object associated with a subscription or default phone if null.
2547 */
Ling Mac28f0212023-03-24 16:07:15 -07002548 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002549 Phone phone = getPhoneFromSubId(subId);
2550 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002551 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002552 phone = getDefaultPhone();
2553 }
2554 return phone;
2555 }
2556
Rambo Wange53e07d2022-05-10 13:01:13 -07002557 @Nullable
2558 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002559 Phone phone = getPhoneFromRequest(request);
2560 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002561 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002562 }
2563
Ling Mac28f0212023-03-24 16:07:15 -07002564 /**
2565 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2566 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2567 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2568 * @return The Phone associated the sub Id
2569 */
2570 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002571 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573
Kai Shif70f46f2021-03-03 13:59:46 -08002574 private void sendEraseModemConfig(@NonNull Phone phone) {
2575 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2576 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2577 }
2578
2579 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2580 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2581 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002582 }
2583
Peter Wang44b186e2020-01-13 23:33:09 -08002584 private boolean isImsAvailableOnDevice() {
2585 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2586 if (pm == null) {
2587 // For some reason package manger is not available.. This will fail internally anyway,
2588 // so do not throw error and allow.
2589 return true;
2590 }
2591 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2592 }
2593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2596 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2597
Wink Savilleadd7cc52014-09-08 14:23:09 -07002598 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 if (DBG) log("dial: " + number);
2603 // No permission check needed here: This is just a wrapper around the
2604 // ACTION_DIAL intent, which is available to any app since it puts up
2605 // the UI before it does anything.
2606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 String url = createTelUrl(number);
2610 if (url == null) {
2611 return;
2612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 // PENDING: should we just silently fail if phone is offhook or ringing?
2615 PhoneConstants.State state = mCM.getState(subId);
2616 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2617 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2618 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002619 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 }
2624 }
2625
2626 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002627 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002628 }
2629
Wink Savilleb564aae2014-10-23 10:18:09 -07002630 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 if (DBG) log("call: " + number);
2632
2633 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002634 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 // from the context of the phone app.
2636 enforceCallPermission();
2637
Jordan Liu1617b712019-07-10 15:06:26 -07002638 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 != AppOpsManager.MODE_ALLOWED) {
2640 return;
2641 }
2642
joonhunshin4ac60942023-11-15 15:23:39 +00002643 enforceTelephonyFeatureWithException(callingPackage,
2644 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 String url = createTelUrl(number);
2649 if (url == null) {
2650 return;
2651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 boolean isValid = false;
2654 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2655 if (slist != null) {
2656 for (SubscriptionInfo subInfoRecord : slist) {
2657 if (subInfoRecord.getSubscriptionId() == subId) {
2658 isValid = true;
2659 break;
2660 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002661 }
Wink Saville08874612014-08-31 19:19:58 -07002662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 if (!isValid) {
2664 return;
2665 }
Wink Saville08874612014-08-31 19:19:58 -07002666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2668 intent.putExtra(SUBSCRIPTION_KEY, subId);
2669 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002670 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
Wink Savilleb564aae2014-10-23 10:18:09 -07002676 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002678 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002682 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002683 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2684 }
2685
Wink Savilleb564aae2014-10-23 10:18:09 -07002686 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
joonhunshin4ac60942023-11-15 15:23:39 +00002689 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2690 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2691 "supplyPinReportResultForSubscriber");
2692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 final long identity = Binder.clearCallingIdentity();
2694 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002695 Phone phone = getPhone(subId);
2696 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 checkSimPin.start();
2698 return checkSimPin.unlockSim(null, pin);
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 }
2703
Wink Savilleb564aae2014-10-23 10:18:09 -07002704 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706
joonhunshin4ac60942023-11-15 15:23:39 +00002707 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2708 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 final long identity = Binder.clearCallingIdentity();
2711 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002712 Phone phone = getPhone(subId);
2713 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 checkSimPuk.start();
2715 return checkSimPuk.unlockSim(puk, pin);
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
2718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 }
2720
2721 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002722 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 * a synchronous one.
2724 */
2725 private static class UnlockSim extends Thread {
2726
2727 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002728 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729
2730 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002731 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2732 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733
2734 // For replies from SimCard interface
2735 private Handler mHandler;
2736
2737 // For async handler to identify request type
2738 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002739 private static final int SUPPLY_PIN_DELAYED = 101;
2740 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2741 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2742 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743
Michele Berionne5e411512020-11-13 02:36:59 +00002744 UnlockSim(int phoneId, IccCard simCard) {
2745 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 mSimCard = simCard;
2747 }
2748
2749 @Override
2750 public void run() {
2751 Looper.prepare();
2752 synchronized (UnlockSim.this) {
2753 mHandler = new Handler() {
2754 @Override
2755 public void handleMessage(Message msg) {
2756 AsyncResult ar = (AsyncResult) msg.obj;
2757 switch (msg.what) {
2758 case SUPPLY_PIN_COMPLETE:
2759 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2760 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002761 mRetryCount = msg.arg1;
2762 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002763 CommandException.Error error = null;
2764 if (ar.exception instanceof CommandException) {
2765 error = ((CommandException) (ar.exception))
2766 .getCommandError();
2767 }
2768 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002769 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002770 } else if (error == CommandException.Error.ABORTED) {
2771 /* When UiccCardApp dispose, handle message and return
2772 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002773 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002774 } else {
2775 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2776 }
2777 } else {
2778 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002781 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 UnlockSim.this.notifyAll();
2783 }
2784 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002785 case SUPPLY_PIN_DELAYED:
2786 if(!mDone) {
2787 String logStr = "Delay in receiving SIM PIN response ";
2788 if (DBG) log(logStr);
2789 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2790 }
2791 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793 }
2794 };
2795 UnlockSim.this.notifyAll();
2796 }
2797 Looper.loop();
2798 }
2799
2800 /*
2801 * Use PIN or PUK to unlock SIM card
2802 *
2803 * If PUK is null, unlock SIM card with PIN
2804 *
2805 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302806 *
2807 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2808 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 */
Wink Saville9de0f752013-10-22 19:04:03 -07002810 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811
2812 while (mHandler == null) {
2813 try {
2814 wait();
2815 } catch (InterruptedException e) {
2816 Thread.currentThread().interrupt();
2817 }
2818 }
2819 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2820
2821 if (puk == null) {
2822 mSimCard.supplyPin(pin, callback);
2823 } else {
2824 mSimCard.supplyPuk(puk, pin, callback);
2825 }
2826
2827 while (!mDone) {
2828 try {
2829 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002830 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2831 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 wait();
2833 } catch (InterruptedException e) {
2834 // Restore the interrupted status
2835 Thread.currentThread().interrupt();
2836 }
2837 }
2838 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002839 int[] resultArray = new int[2];
2840 resultArray[0] = mResult;
2841 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002842
2843 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002844 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002845 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302846 // This instance is no longer reused, so quit its thread's looper.
2847 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002848
Wink Saville9de0f752013-10-22 19:04:03 -07002849 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851 }
2852
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002853 /**
2854 * This method has been removed due to privacy and stability concerns.
2855 */
2856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002858 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2859 return;
Wink Saville36469e72014-06-11 15:17:00 -07002860 }
2861
Nathan Harold1f889d82020-06-04 17:05:26 -07002862 @Override
2863 public void updateServiceLocationWithPackageName(String callingPackage) {
2864 mApp.getSystemService(AppOpsManager.class)
2865 .checkPackage(Binder.getCallingUid(), callingPackage);
2866
Nathan Haroldf096d982020-11-18 17:18:06 -08002867 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002868 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2869 // Callers targeting S have no business invoking this method.
2870 return;
2871 }
2872
2873 LocationAccessPolicy.LocationPermissionResult locationResult =
2874 LocationAccessPolicy.checkLocationPermission(mApp,
2875 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2876 .setCallingPackage(callingPackage)
2877 .setCallingFeatureId(null)
2878 .setCallingPid(Binder.getCallingPid())
2879 .setCallingUid(Binder.getCallingUid())
2880 .setMethod("updateServiceLocation")
2881 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2882 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2883 .build());
2884 // Apps that lack location permission have no business calling this method;
2885 // however, because no permission was declared in the public API, denials must
2886 // all be "soft".
2887 switch (locationResult) {
2888 case DENIED_HARD: /* fall through */
2889 case DENIED_SOFT:
2890 return;
2891 }
2892
2893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 final long identity = Binder.clearCallingIdentity();
2895 try {
Ling Mac28f0212023-03-24 16:07:15 -07002896 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 } finally {
2898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002900 }
2901
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002902 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002903 @Override
2904 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002905 return isRadioOnWithFeature(callingPackage, null);
2906 }
2907
2908
2909 @Override
2910 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2911 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2912 callingFeatureId);
2913 }
2914
2915 @Deprecated
2916 @Override
2917 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2918 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002919 }
2920
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002922 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2923 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002925 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002926 return false;
2927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928
joonhunshin4ac60942023-11-15 15:23:39 +00002929 enforceTelephonyFeatureWithException(callingPackage,
2930 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 return isRadioOnForSubscriber(subId);
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002938 }
2939
2940 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 final Phone phone = getPhone(subId);
2944 if (phone != null) {
2945 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2946 } else {
2947 return false;
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002955 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 }
Wink Saville36469e72014-06-11 15:17:00 -07002957
Wink Savilleb564aae2014-10-23 10:18:09 -07002958 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
joonhunshin4ac60942023-11-15 15:23:39 +00002961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2962 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 final Phone phone = getPhone(subId);
2967 if (phone != null) {
2968 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2969 }
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002972 }
Wink Saville36469e72014-06-11 15:17:00 -07002973 }
2974
2975 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002976 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002977 }
2978
Wink Savilleb564aae2014-10-23 10:18:09 -07002979 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 final Phone phone = getPhone(subId);
2985 if (phone == null) {
2986 return false;
2987 }
2988 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2989 toggleRadioOnOffForSubscriber(subId);
2990 }
2991 return true;
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
Wink Saville36469e72014-06-11 15:17:00 -07002996
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002997 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002998 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002999
Tomasz Wasilczykef763582024-09-17 13:50:32 -07003000 if (!mApp.getResources().getBoolean(
3001 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3003 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3004 }
joonhunshin4ac60942023-11-15 15:23:39 +00003005
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003006 /*
3007 * If any of the Radios are available, it will need to be
3008 * shutdown. So return true if any Radio is available.
3009 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3013 Phone phone = PhoneFactory.getPhone(i);
3014 if (phone != null && phone.isRadioAvailable()) return true;
3015 }
3016 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3017 return false;
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003020 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003021 }
3022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003024 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 enforceModifyPermission();
3026
joonhunshin4ac60942023-11-15 15:23:39 +00003027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3028 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3033 logv("Shutting down Phone " + i);
3034 shutdownRadioUsingPhoneId(i);
3035 }
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003038 }
3039 }
3040
3041 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003042 Phone phone = PhoneFactory.getPhone(phoneId);
3043 if (phone != null && phone.isRadioAvailable()) {
3044 phone.shutdownRadio();
3045 }
3046 }
3047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
Ling Ma83dc5ea2023-01-12 15:06:04 -08003051 if (!turnOn) {
3052 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3053 }
3054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3058 if (defaultPhone != null) {
3059 defaultPhone.setRadioPower(turnOn);
3060 return true;
3061 } else {
3062 loge("There's no default phone.");
3063 return false;
3064 }
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003067 }
Wink Saville36469e72014-06-11 15:17:00 -07003068 }
3069
Wink Savilleb564aae2014-10-23 10:18:09 -07003070 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
Ling Ma83dc5ea2023-01-12 15:06:04 -08003073 if (!turnOn) {
3074 log("setRadioPowerForSubscriber off: subId=" + subId
3075 + ",callingPackage=" + getCurrentPackageName());
3076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 final Phone phone = getPhone(subId);
3080 if (phone != null) {
3081 phone.setRadioPower(turnOn);
3082 return true;
3083 } else {
3084 return false;
3085 }
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
3090
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003091 /**
3092 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3093 * no reason to power it off. When any of the voters want to power it off, it will be turned
3094 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3095 * powering it off, and these radio off votes will be cleared.
3096 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3097 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3098 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3099 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3100 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3101 * check its vote.
3102 *
3103 * @param subId The subscription ID.
3104 * @param reason The reason for powering off radio.
3105 * @return true on success and false on failure.
3106 */
3107 public boolean requestRadioPowerOffForReason(int subId,
3108 @TelephonyManager.RadioPowerReason int reason) {
3109 enforceModifyPermission();
3110
joonhunshin4ac60942023-11-15 15:23:39 +00003111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3112 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3113
Ling Ma83dc5ea2023-01-12 15:06:04 -08003114 log("requestRadioPowerOffForReason: subId=" + subId
3115 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003116 final long identity = Binder.clearCallingIdentity();
3117 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003118 boolean result = false;
3119 for (Phone phone : PhoneFactory.getPhones()) {
3120 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003121 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003122 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003123 if (!result) {
3124 loge("requestRadioPowerOffForReason: no phone exists");
3125 }
3126 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 /**
3133 * Remove the vote on powering off the radio for a reason, as requested by
3134 * {@link requestRadioPowerOffForReason}.
3135 *
3136 * @param subId The subscription ID.
3137 * @param reason The reason for powering off radio.
3138 * @return true on success and false on failure.
3139 */
3140 public boolean clearRadioPowerOffForReason(int subId,
3141 @TelephonyManager.RadioPowerReason int reason) {
3142 enforceModifyPermission();
3143
joonhunshin4ac60942023-11-15 15:23:39 +00003144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3145 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3146
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003147 final long identity = Binder.clearCallingIdentity();
3148 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003149 boolean result = false;
3150 for (Phone phone : PhoneFactory.getPhones()) {
3151 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003152 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003154 if (!result) {
3155 loge("clearRadioPowerOffForReason: no phone exists");
3156 }
3157 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 }
3162
3163 /**
3164 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3165 *
3166 * @param subId The subscription ID.
3167 * @param callingPackage The package making the call.
3168 * @param callingFeatureId The feature in the package.
3169 * @return List of reasons for powering off radio.
3170 */
3171 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3172 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3173
joonhunshin4ac60942023-11-15 15:23:39 +00003174 enforceTelephonyFeatureWithException(callingPackage,
3175 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3176
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003177 final long identity = Binder.clearCallingIdentity();
3178 List result = new ArrayList();
3179 try {
3180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3181 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3182 return result;
3183 }
3184
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003185 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003186 if (phone != null) {
3187 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003188 } else {
3189 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003190 }
3191 } finally {
3192 Binder.restoreCallingIdentity(identity);
3193 }
3194 return result;
3195 }
3196
Wink Saville36469e72014-06-11 15:17:00 -07003197 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003199 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
joonhunshin4ac60942023-11-15 15:23:39 +00003202 enforceTelephonyFeatureWithException(callingPackage,
3203 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
Jack Yu285100e2022-12-02 22:48:35 -08003207 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003209 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003210 phone.getDataSettingsManager().setDataEnabled(
3211 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 return true;
3213 } else {
3214 return false;
3215 }
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220
Wink Saville36469e72014-06-11 15:17:00 -07003221 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003222 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003223 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225
joonhunshin4ac60942023-11-15 15:23:39 +00003226 enforceTelephonyFeatureWithException(callingPackage,
3227 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
Jack Yu285100e2022-12-02 22:48:35 -08003231 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003233 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003234 phone.getDataSettingsManager().setDataEnabled(
3235 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 return true;
3237 } else {
3238 return false;
3239 }
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 }
3244
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003246 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3248 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 final Phone phone = getPhone(subId);
3253 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003254 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 } else {
3256 return false;
3257 }
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
3263 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003264 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003265 }
3266
pkanwarae03a6b2016-11-06 20:37:09 -08003267 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 enforceCallPermission();
3269
joonhunshin4ac60942023-11-15 15:23:39 +00003270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3271 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3276 return;
3277 }
3278 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3279 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
pkanwar32d516d2016-10-14 19:37:38 -07003283 };
3284
Wink Savilleb564aae2014-10-23 10:18:09 -07003285 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287
joonhunshin4ac60942023-11-15 15:23:39 +00003288 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3289 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3294 return false;
3295 }
3296 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003302 /**
3303 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3304 * tag on getCallState Binder call.
3305 */
3306 @Deprecated
3307 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003309 if (CompatChanges.isChangeEnabled(
3310 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3311 Binder.getCallingUid())) {
3312 // Do not allow this API to be called on API version 31+, it should only be
3313 // called on old apps using this Binder call directly.
3314 throw new SecurityException("This method can only be used for applications "
3315 + "targeting API version 30 or less.");
3316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317 final long identity = Binder.clearCallingIdentity();
3318 try {
Ling Mac28f0212023-03-24 16:07:15 -07003319 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3320 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3328 if (CompatChanges.isChangeEnabled(
3329 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3330 Binder.getCallingUid())) {
3331 // Check READ_PHONE_STATE for API version 31+
3332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3333 featureId, "getCallStateForSubscription")) {
3334 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3335 + "targeting API level 31+.");
3336 }
3337 }
joonhunshin4ac60942023-11-15 15:23:39 +00003338
3339 enforceTelephonyFeatureWithException(callingPackage,
3340 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3341
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3346 PhoneConstantConversions.convertCallState(phone.getState());
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 }
3351
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003353 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003354 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003355 }
3356
3357 @Override
3358 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3360 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 final long identity = Binder.clearCallingIdentity();
3363 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003364 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003366 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 } else {
3368 return PhoneConstantConversions.convertDataState(
3369 PhoneConstants.DataState.DISCONNECTED);
3370 }
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003374 }
3375
Sanket Padawe356d7632015-06-22 14:03:32 -07003376 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003377 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003378 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003379 }
3380
3381 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003382 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3384 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003388 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003390 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 } else {
3392 return TelephonyManager.DATA_ACTIVITY_NONE;
3393 }
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 }
3398
3399 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003400 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003402 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003403
3404 LocationAccessPolicy.LocationPermissionResult locationResult =
3405 LocationAccessPolicy.checkLocationPermission(mApp,
3406 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3407 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003408 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003409 .setCallingPid(Binder.getCallingPid())
3410 .setCallingUid(Binder.getCallingUid())
3411 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3414 .build());
3415 switch (locationResult) {
3416 case DENIED_HARD:
3417 throw new SecurityException("Not allowed to access cell location");
3418 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003419 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3420 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003421 }
3422
joonhunshin4ac60942023-11-15 15:23:39 +00003423 enforceTelephonyFeatureWithException(callingPackage,
3424 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3425
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003426 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003430 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003431 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
Svetoslav64fad262015-04-14 14:35:21 -07003435 }
3436
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003438 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003439 if (!mApp.getResources().getBoolean(
3440 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3442 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3443 }
joonhunshin4ac60942023-11-15 15:23:39 +00003444
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003445 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3446 // registered cell info, so return a NULL country instead.
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003449 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3450 // Get default phone in this case.
3451 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3452 }
Jack Yu285100e2022-12-02 22:48:35 -08003453 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003455 if (phone == null) return "";
3456 ServiceStateTracker sst = phone.getServiceStateTracker();
3457 if (sst == null) return "";
3458 LocaleTracker lt = sst.getLocaleTracker();
3459 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003460 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003464 }
3465
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003466 /**
3467 * This method was removed due to potential issues caused by performing partial
3468 * updates of service state, and lack of a credible use case.
3469 *
3470 * This has the ability to break the telephony implementation by disabling notification of
3471 * changes in device connectivity. DO NOT USE THIS!
3472 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003473 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 public void enableLocationUpdates() {
3475 mApp.enforceCallingOrSelfPermission(
3476 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003477 }
3478
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003479 /**
3480 * This method was removed due to potential issues caused by performing partial
3481 * updates of service state, and lack of a credible use case.
3482 *
3483 * This has the ability to break the telephony implementation by disabling notification of
3484 * changes in device connectivity. DO NOT USE THIS!
3485 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 @Override
3487 public void disableLocationUpdates() {
3488 mApp.enforceCallingOrSelfPermission(
3489 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 }
3491
3492 @Override
3493 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003494 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3495 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003496 try {
3497 mApp.getSystemService(AppOpsManager.class)
3498 .checkPackage(Binder.getCallingUid(), callingPackage);
3499 } catch (SecurityException e) {
3500 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3501 throw e;
3502 }
3503
Nathan Haroldf096d982020-11-18 17:18:06 -08003504 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003505 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3506 throw new SecurityException(
3507 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3508 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003509
Jordan Liu1617b712019-07-10 15:06:26 -07003510 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3512 return null;
3513 }
Svetoslav64fad262015-04-14 14:35:21 -07003514
joonhunshin4ac60942023-11-15 15:23:39 +00003515 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3516 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3517
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003518 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003520 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003521 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522
Nathan Haroldf180aac2018-06-01 18:43:55 -07003523 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3524 for (CellInfo ci : info) {
3525 if (ci instanceof CellInfoGsm) {
3526 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3527 } else if (ci instanceof CellInfoWcdma) {
3528 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003530 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003531 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003534 private List<CellInfo> getCachedCellInfo() {
3535 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3536 for (Phone phone : PhoneFactory.getPhones()) {
3537 List<CellInfo> info = phone.getAllCellInfo();
3538 if (info != null) cellInfos.addAll(info);
3539 }
3540 return cellInfos;
3541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003542
3543 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003544 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003545 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003546 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003547
3548 LocationAccessPolicy.LocationPermissionResult locationResult =
3549 LocationAccessPolicy.checkLocationPermission(mApp,
3550 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3551 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003552 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003553 .setCallingPid(Binder.getCallingPid())
3554 .setCallingUid(Binder.getCallingUid())
3555 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003556 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003557 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3558 .build());
3559 switch (locationResult) {
3560 case DENIED_HARD:
3561 throw new SecurityException("Not allowed to access cell info");
3562 case DENIED_SOFT:
3563 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
Nathan Haroldf096d982020-11-18 17:18:06 -08003566 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003567 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3568 return getCachedCellInfo();
3569 }
3570
joonhunshin4ac60942023-11-15 15:23:39 +00003571 enforceTelephonyFeatureWithException(callingPackage,
3572 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3573
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003574 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3579 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003580 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003581 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582 if (info != null) cellInfos.addAll(info);
3583 }
3584 return cellInfos;
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588 }
3589
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003590 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003591 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3592 String callingFeatureId) {
3593 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3594 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003595 }
3596
3597 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003598 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3599 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003600 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003601 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003602 }
3603
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003604 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3605 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003607 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003608
3609 LocationAccessPolicy.LocationPermissionResult locationResult =
3610 LocationAccessPolicy.checkLocationPermission(mApp,
3611 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3612 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003613 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003614 .setCallingPid(Binder.getCallingPid())
3615 .setCallingUid(Binder.getCallingUid())
3616 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003617 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3618 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003619 .build());
3620 switch (locationResult) {
3621 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003622 if (TelephonyPermissions
3623 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003624 // Safetynet logging for b/154934934
3625 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3626 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003627 throw new SecurityException("Not allowed to access cell info");
3628 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003629 if (TelephonyPermissions
3630 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003631 // Safetynet logging for b/154934934
3632 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3633 }
Nathan Harold5320c422019-05-09 10:26:08 -07003634 try {
3635 cb.onCellInfo(new ArrayList<CellInfo>());
3636 } catch (RemoteException re) {
3637 // Drop without consequences
3638 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003639 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003640 }
3641
joonhunshin4ac60942023-11-15 15:23:39 +00003642 enforceTelephonyFeatureWithException(callingPackage,
3643 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003644
3645 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003646 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3647
3648 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3649 }
3650
3651 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003652 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003653 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003658 Phone phone = getPhone(subId);
3659 if (phone == null) {
3660 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3661 } else {
3662 phone.setCellInfoListRate(rateInMillis, workSource);
3663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003667 }
3668
Shishir Agrawala9f32182016-04-12 12:00:16 -07003669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003670 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003671 Phone phone = PhoneFactory.getPhone(slotIndex);
3672 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003673 return null;
3674 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003675 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003676 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003677 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003678 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003679 return null;
3680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 return phone.getImei();
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003688 }
3689
3690 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003691 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3692 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3693 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3694 callingFeatureId, "getPrimaryImei")) {
3695 throw new SecurityException("Caller does not have permission");
3696 }
joonhunshin4ac60942023-11-15 15:23:39 +00003697
arunvoddud5c6ce02022-12-11 06:03:12 +00003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 for (Phone phone : PhoneFactory.getPhones()) {
3701 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3702 return phone.getImei();
3703 }
3704 }
3705 throw new UnsupportedOperationException("Operation not supported");
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
3711 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003712 public String getTypeAllocationCodeForSlot(int slotIndex) {
3713 Phone phone = PhoneFactory.getPhone(slotIndex);
3714 String tac = null;
3715 if (phone != null) {
3716 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003717 try {
3718 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3719 } catch (IndexOutOfBoundsException e) {
3720 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3721 return null;
3722 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003723 }
3724 return tac;
3725 }
3726
3727 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003728 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003729 try {
3730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3731 } catch (SecurityException se) {
3732 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3733 throw new SecurityException("Package " + callingPackage + " does not belong to "
3734 + Binder.getCallingUid());
3735 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003736 Phone phone = PhoneFactory.getPhone(slotIndex);
3737 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003738 return null;
3739 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740
Jeff Davidson913390f2018-02-23 17:11:49 -08003741 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003742 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003743 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003744 return null;
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
joonhunshin4ac60942023-11-15 15:23:39 +00003747 enforceTelephonyFeatureWithException(callingPackage,
3748 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 return phone.getMeid();
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Jack Yu2af8d712017-03-15 17:14:14 -07003756 }
3757
3758 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003759 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3761 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3762
David Kelly5e06a7f2018-03-12 14:10:59 +00003763 Phone phone = PhoneFactory.getPhone(slotIndex);
3764 String manufacturerCode = null;
3765 if (phone != null) {
3766 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003767 try {
3768 manufacturerCode =
3769 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3770 } catch (IndexOutOfBoundsException e) {
3771 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3772 return null;
3773 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003774 }
3775 return manufacturerCode;
3776 }
3777
3778 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003779 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3780 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003781 Phone phone = PhoneFactory.getPhone(slotIndex);
3782 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 return null;
3784 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003785 int subId = phone.getSubId();
3786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003787 mApp, subId, callingPackage, callingFeatureId,
3788 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003789 return null;
3790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
joonhunshin4ac60942023-11-15 15:23:39 +00003792 enforceTelephonyFeatureWithException(callingPackage,
3793 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 return phone.getDeviceSvn();
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003801 }
3802
fionaxu43304da2017-11-27 22:51:16 -08003803 @Override
3804 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003805 if (!mApp.getResources().getBoolean(
3806 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3807 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3808 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3809 }
joonhunshin4ac60942023-11-15 15:23:39 +00003810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 final Phone phone = getPhone(subId);
3814 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
fionaxu43304da2017-11-27 22:51:16 -08003818 }
3819
3820 @Override
3821 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3823 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = getPhone(subId);
3828 return phone == null ? null : phone.getCarrierName();
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
fionaxu43304da2017-11-27 22:51:16 -08003832 }
3833
calvinpanffe225e2018-11-01 19:43:06 +08003834 @Override
chen xu0026ca62019-03-06 15:28:50 -08003835 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3837 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3838
chen xu25637222018-11-04 17:17:00 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 final Phone phone = getPhone(subId);
3842 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003843 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
3847 }
3848
3849 @Override
chen xu0026ca62019-03-06 15:28:50 -08003850 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003851 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3852 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3853 "getSubscriptionSpecificCarrierName");
3854
chen xu25637222018-11-04 17:17:00 -08003855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003858 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
chen xu651eec72018-11-11 19:03:44 -08003864 @Override
chen xu864e11c2018-12-06 22:10:03 -08003865 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3866 if (!isSubscriptionMccMnc) {
3867 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3868 }
chen xu651eec72018-11-11 19:03:44 -08003869 final Phone phone = PhoneFactory.getPhone(slotIndex);
3870 if (phone == null) {
3871 return TelephonyManager.UNKNOWN_CARRIER_ID;
3872 }
joonhunshin4ac60942023-11-15 15:23:39 +00003873
3874 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3875 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3876
chen xu651eec72018-11-11 19:03:44 -08003877 final long identity = Binder.clearCallingIdentity();
3878 try {
3879 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
3883 }
3884
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 //
3886 // Internal helper methods.
3887 //
3888
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003889 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003890 * Make sure the caller is the calling package itself
3891 *
3892 * @throws SecurityException if the caller is not the calling package
3893 */
3894 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3895 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003896 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3897 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003898 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003899 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003900 } catch (PackageManager.NameNotFoundException e) {
3901 // packageUid is -1
3902 }
3903 if (packageUid != callingUid) {
3904 throw new SecurityException(message + ": Package " + callingPackage
3905 + " does not belong to " + callingUid);
3906 }
3907 }
3908
3909 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003910 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3911 *
3912 * @throws SecurityException if the caller does not have the required permission
3913 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003914 @VisibleForTesting
3915 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003916 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3917 }
3918
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003919 /**
arunvoddud7401012022-12-15 16:08:12 +00003920 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003921 *
3922 * @throws SecurityException if the caller does not have the required permission
3923 */
3924 @VisibleForTesting
3925 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003926 enforceReadPermission(null);
3927 }
3928
3929 /**
3930 * Make sure the caller has the READ_PHONE_STATE permissions.
3931 *
3932 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3933 */
3934 @VisibleForTesting
3935 public void enforceReadPermission(String msg) {
3936 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003937 }
3938
Shuo Qian3b6ee772019-11-13 17:43:31 -08003939 private void enforceActiveEmergencySessionPermission() {
3940 mApp.enforceCallingOrSelfPermission(
3941 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3942 }
3943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003944 /**
3945 * Make sure the caller has the CALL_PHONE permission.
3946 *
3947 * @throws SecurityException if the caller does not have the required permission
3948 */
3949 private void enforceCallPermission() {
3950 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3951 }
3952
paulhu5a773602019-08-23 19:17:33 +08003953 private void enforceSettingsPermission() {
3954 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003955 }
3956
Michele Berionne5e411512020-11-13 02:36:59 +00003957 private void enforceRebootPermission() {
3958 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3959 }
3960
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003961 /**
3962 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3963 * @param message - log message to print.
3964 * @throws SecurityException if the caller does not have the required permission
3965 */
3966 private void enforceSatelliteCommunicationPermission(String message) {
3967 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3968 }
3969
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003970 /**
3971 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3972 * @param message - log message to print.
3973 * @throws SecurityException if the caller does not have the required permission
3974 */
3975 private void enforcePackageUsageStatsPermission(String message) {
3976 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3977 }
3978
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003979 private String createTelUrl(String number) {
3980 if (TextUtils.isEmpty(number)) {
3981 return null;
3982 }
3983
Jake Hambye994d462014-02-03 13:10:13 -08003984 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003985 }
3986
Ihab Awadf9e92732013-12-05 18:02:52 -08003987 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003988 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003989 }
3990
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003991 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003992 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003993 }
3994
Ihab Awadf9e92732013-12-05 18:02:52 -08003995 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003996 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003997 }
3998
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003999 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004000 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004001 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004002 }
4003
Sanket Padawe356d7632015-06-22 14:03:32 -07004004 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004005 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004006 if (!mApp.getResources().getBoolean(
4007 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4008 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4009 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4010 }
joonhunshin4ac60942023-11-15 15:23:39 +00004011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 final Phone phone = PhoneFactory.getPhone(slotIndex);
4015 if (phone == null) {
4016 return PhoneConstants.PHONE_TYPE_NONE;
4017 } else {
4018 return phone.getPhoneType();
4019 }
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004023 }
4024
4025 /**
4026 * Returns the CDMA ERI icon index to display
4027 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004029 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4030 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4031 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004032 }
4033
Sanket Padawe356d7632015-06-22 14:03:32 -07004034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004035 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4036 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004038 mApp, subId, callingPackage, callingFeatureId,
4039 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004040 return -1;
4041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042
joonhunshin4ac60942023-11-15 15:23:39 +00004043 enforceTelephonyFeatureWithException(callingPackage,
4044 PackageManager.FEATURE_TELEPHONY_CDMA,
4045 "getCdmaEriIconIndexForSubscriber");
4046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 final Phone phone = getPhone(subId);
4050 if (phone != null) {
4051 return phone.getCdmaEriIconIndex();
4052 } else {
4053 return -1;
4054 }
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004058 }
4059
4060 /**
4061 * Returns the CDMA ERI icon mode,
4062 * 0 - ON
4063 * 1 - FLASHING
4064 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4067 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4068 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004069 }
4070
Sanket Padawe356d7632015-06-22 14:03:32 -07004071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004072 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4073 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004075 mApp, subId, callingPackage, callingFeatureId,
4076 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004077 return -1;
4078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079
4080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 final Phone phone = getPhone(subId);
4083 if (phone != null) {
4084 return phone.getCdmaEriIconMode();
4085 } else {
4086 return -1;
4087 }
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004091 }
4092
4093 /**
4094 * Returns the CDMA ERI text,
4095 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004097 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4098 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4099 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004100 }
4101
Sanket Padawe356d7632015-06-22 14:03:32 -07004102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004103 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4104 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004106 mApp, subId, callingPackage, callingFeatureId,
4107 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004108 return null;
4109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 final Phone phone = getPhone(subId);
4114 if (phone != null) {
4115 return phone.getCdmaEriText();
4116 } else {
4117 return null;
4118 }
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004122 }
4123
4124 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004125 * Returns the CDMA MDN.
4126 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004127 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004128 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4130 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131
joonhunshin4ac60942023-11-15 15:23:39 +00004132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4133 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 return phone.getLine1Number();
4140 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 return null;
4143 }
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004146 }
4147 }
4148
4149 /**
4150 * Returns the CDMA MIN.
4151 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004152 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004153 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4155 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156
joonhunshin4ac60942023-11-15 15:23:39 +00004157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4158 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 final Phone phone = getPhone(subId);
4163 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4164 return phone.getCdmaMin();
4165 } else {
4166 return null;
4167 }
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004170 }
4171 }
4172
Hall Liud892bec2018-11-30 14:51:45 -08004173 @Override
4174 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4175 INumberVerificationCallback callback, String callingPackage) {
4176 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4177 != PERMISSION_GRANTED) {
4178 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4179 }
4180 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4181
4182 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4183 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004184 throw new SecurityException("Calling package must be configured in the device config: "
4185 + "calling package: " + callingPackage
4186 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004187 }
4188
joonhunshin4ac60942023-11-15 15:23:39 +00004189 enforceTelephonyFeatureWithException(callingPackage,
4190 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4191
Hall Liud892bec2018-11-30 14:51:45 -08004192 if (range == null) {
4193 throw new NullPointerException("Range must be non-null");
4194 }
4195
4196 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004197 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004198
4199 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4200 }
4201
Junda Liuca05d5d2014-08-14 22:36:34 -07004202 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004203 * Returns true if CDMA provisioning needs to run.
4204 */
4205 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4207 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 final long identity = Binder.clearCallingIdentity();
4210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004211 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004215 }
4216
4217 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004218 * Sets the voice mail number of a given subId.
4219 */
4220 @Override
4221 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004222 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4223 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224
joonhunshin4ac60942023-11-15 15:23:39 +00004225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4226 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 final long identity = Binder.clearCallingIdentity();
4229 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004230 Boolean success = (Boolean) sendRequest(
4231 CMD_SET_VOICEMAIL_NUMBER,
4232 new Pair<String, String>(alphaTag, number),
4233 new Integer(subId),
4234 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4235 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 return success;
4237 } finally {
4238 Binder.restoreCallingIdentity(identity);
4239 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004240 }
4241
Ta-wei Yen87c49842016-05-13 21:19:52 -07004242 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004243 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4244 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004245 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4246 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004247 if (!TextUtils.equals(callingPackage, systemDialer)) {
4248 throw new SecurityException("caller must be system dialer");
4249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250
joonhunshin4ac60942023-11-15 15:23:39 +00004251 enforceTelephonyFeatureWithException(callingPackage,
4252 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4257 if (phoneAccountHandle == null) {
4258 return null;
4259 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004260 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004263 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004264 }
4265
4266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004267 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4268 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 mApp, subId, callingPackage, callingFeatureId,
4272 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004273 return null;
4274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
joonhunshin4ac60942023-11-15 15:23:39 +00004276 enforceTelephonyFeatureWithException(callingPackage,
4277 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4278
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004279 final long identity = Binder.clearCallingIdentity();
4280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004281 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004285 }
4286
4287 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004288 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4289 VisualVoicemailSmsFilterSettings settings) {
4290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004291 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004292 enforceTelephonyFeatureWithException(callingPackage,
4293 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004297 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004301 }
4302
4303 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004304 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4305 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004306 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004307 enforceTelephonyFeatureWithException(callingPackage,
4308 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004313 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004317 }
4318
4319 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004320 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4321 String callingPackage, int subId) {
4322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323
4324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004327 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004331 }
4332
4333 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004334 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336
4337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004340 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004344 }
4345
4346 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004347 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4348 String callingAttributionTag, int subId, String number, int port, String text,
4349 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004351 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004352 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004353
4354 enforceTelephonyFeatureWithException(callingPackage,
4355 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4356
Amit Mahajandccb3f12019-05-13 13:48:32 -07004357 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004358 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4359 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4360 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004361 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004362
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004363 /**
fionaxu0152e512016-11-14 13:36:14 -08004364 * Sets the voice activation state of a given subId.
4365 */
4366 @Override
4367 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4369 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370
joonhunshin4ac60942023-11-15 15:23:39 +00004371 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4372 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 final Phone phone = getPhone(subId);
4377 if (phone != null) {
4378 phone.setVoiceActivationState(activationState);
4379 } else {
4380 loge("setVoiceActivationState fails with invalid subId: " + subId);
4381 }
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004384 }
4385 }
4386
4387 /**
4388 * Sets the data activation state of a given subId.
4389 */
4390 @Override
4391 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4393 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394
joonhunshin4ac60942023-11-15 15:23:39 +00004395 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4396 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 final Phone phone = getPhone(subId);
4401 if (phone != null) {
4402 phone.setDataActivationState(activationState);
4403 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004404 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 }
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004408 }
4409 }
4410
4411 /**
4412 * Returns the voice activation state of a given subId.
4413 */
4414 @Override
4415 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417
joonhunshin4ac60942023-11-15 15:23:39 +00004418 enforceTelephonyFeatureWithException(callingPackage,
4419 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4420
fionaxu0152e512016-11-14 13:36:14 -08004421 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 if (phone != null) {
4425 return phone.getVoiceActivationState();
4426 } else {
4427 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4428 }
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004431 }
4432 }
4433
4434 /**
4435 * Returns the data activation state of a given subId.
4436 */
4437 @Override
4438 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440
joonhunshin4ac60942023-11-15 15:23:39 +00004441 enforceTelephonyFeatureWithException(callingPackage,
4442 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4443
fionaxu0152e512016-11-14 13:36:14 -08004444 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 final long identity = Binder.clearCallingIdentity();
4446 try {
4447 if (phone != null) {
4448 return phone.getDataActivationState();
4449 } else {
4450 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4451 }
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004454 }
4455 }
4456
4457 /**
Wink Saville36469e72014-06-11 15:17:00 -07004458 * Returns the unread count of voicemails for a subId
4459 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004460 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004461 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4462 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004464 mApp, subId, callingPackage, callingFeatureId,
4465 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004466 return 0;
4467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 final Phone phone = getPhone(subId);
4471 if (phone != null) {
4472 return phone.getVoiceMessageCount();
4473 } else {
4474 return 0;
4475 }
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004479 }
4480
4481 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004482 * returns true, if the device is in a state where both voice and data
4483 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004484 */
4485 @Override
4486 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004487 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4488 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 final long identity = Binder.clearCallingIdentity();
4491 try {
Ling Mac28f0212023-03-24 16:07:15 -07004492 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004496 }
4497
4498 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004499 * Send the dialer code if called from the current default dialer or the caller has
4500 * carrier privilege.
4501 * @param inputCode The dialer code to send
4502 */
4503 @Override
4504 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004505 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004507 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4508 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004509 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004510 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513
joonhunshin4ac60942023-11-15 15:23:39 +00004514 enforceTelephonyFeatureWithException(callingPackage,
4515 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 final long identity = Binder.clearCallingIdentity();
4518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004519 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
fionaxu235cc5e2017-03-06 22:25:57 -08004523 }
4524
Pengquan Menga1bb6272018-09-06 09:59:22 -07004525 @Override
4526 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004527 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004528 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4529 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004530
4531 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4532 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4533
shilufc958392020-01-20 11:36:01 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 if (!isActiveSubscription(subId)) {
4537 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4538 }
4539 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4540 } finally {
4541 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004543 }
4544
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004546 public boolean isInEmergencySmsMode() {
4547 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004548
4549 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4550 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4551
Brad Ebingerb2b65522019-03-15 13:48:47 -07004552 final long identity = Binder.clearCallingIdentity();
4553 try {
4554 for (Phone phone : PhoneFactory.getPhones()) {
4555 if (phone.isInEmergencySmsMode()) {
4556 return true;
4557 }
4558 }
4559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
4562 return false;
4563 }
4564
shilu366312e2019-12-17 09:28:10 -08004565 /**
4566 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4567 * @param subId The subscription to use to check the configuration.
4568 * @param c The callback that will be used to send the result.
4569 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004570 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004571 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4572 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004574 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004575
4576 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4577 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4578 "IMS not available on device.");
4579 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 final long token = Binder.clearCallingIdentity();
4581 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004582 int slotId = getSlotIndexOrException(subId);
4583 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004584
4585 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4586 if (controller != null) {
4587 ImsManager imsManager = controller.getImsManager(subId);
4588 if (imsManager != null) {
4589 imsManager.addRegistrationCallbackForSubscription(c, subId);
4590 } else {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4592 }
4593 } else {
4594 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4595 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
4597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 } finally {
4599 Binder.restoreCallingIdentity(token);
4600 }
4601 }
4602
shilu366312e2019-12-17 09:28:10 -08004603 /**
4604 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4605 * @param subId The subscription to use to check the configuration.
4606 * @param c The callback that will be used to send the result.
4607 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004608 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004609 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004610 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004611 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004612 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4613 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4614 }
Meng Wangafbc5852019-09-19 17:37:13 -07004615 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004616
Meng Wangafbc5852019-09-19 17:37:13 -07004617 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004618 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4619 if (controller != null) {
4620 ImsManager imsManager = controller.getImsManager(subId);
4621 if (imsManager != null) {
4622 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4623 } else {
4624 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4625 + "is inactive, ignoring unregister.");
4626 // If the ImsManager is not valid, just return, since the callback
4627 // will already have been removed internally.
4628 }
4629 }
Meng Wangafbc5852019-09-19 17:37:13 -07004630 } finally {
4631 Binder.restoreCallingIdentity(token);
4632 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 }
4634
Brad Ebingera34a6c22019-10-22 17:36:18 -07004635 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004636 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4637 * @param subId The subscription to use to check the configuration.
4638 * @param c The callback that will be used to send the result.
4639 */
4640 @Override
4641 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4642 throws RemoteException {
4643 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4644 mApp, subId, "registerImsEmergencyRegistrationCallback");
4645
4646 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4648 "IMS not available on device.");
4649 }
4650 final long token = Binder.clearCallingIdentity();
4651 try {
4652 int slotId = getSlotIndexOrException(subId);
4653 verifyImsMmTelConfiguredOrThrow(slotId);
4654
4655 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4656 if (controller != null) {
4657 ImsManager imsManager = controller.getImsManager(subId);
4658 if (imsManager != null) {
4659 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4660 } else {
4661 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4662 }
4663 } else {
4664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4665 }
4666 } catch (ImsException e) {
4667 throw new ServiceSpecificException(e.getCode());
4668 } finally {
4669 Binder.restoreCallingIdentity(token);
4670 }
4671 }
4672
4673 /**
4674 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4675 * @param subId The subscription to use to check the configuration.
4676 * @param c The callback that will be used to send the result.
4677 */
4678 @Override
4679 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4680 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4681 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4683 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4684 }
4685 final long token = Binder.clearCallingIdentity();
4686
4687 try {
4688 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4689 if (controller != null) {
4690 ImsManager imsManager = controller.getImsManager(subId);
4691 if (imsManager != null) {
4692 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4693 } else {
4694 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4695 + "is inactive, ignoring unregister.");
4696 // If the ImsManager is not valid, just return, since the callback
4697 // will already have been removed internally.
4698 }
4699 }
4700 } finally {
4701 Binder.restoreCallingIdentity(token);
4702 }
4703 }
4704
4705 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004706 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4707 */
4708 @Override
4709 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4710 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4711 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4712 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4713 "IMS not available on device.");
4714 }
4715 final long token = Binder.clearCallingIdentity();
4716 try {
4717 Phone phone = getPhone(subId);
4718 if (phone == null) {
4719 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4720 + subId + "'");
4721 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4722 }
4723 phone.getImsRegistrationState(regState -> {
4724 try {
4725 consumer.accept((regState == null)
4726 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4727 } catch (RemoteException e) {
4728 // Ignore if the remote process is no longer available to call back.
4729 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4730 }
4731 });
4732 } finally {
4733 Binder.restoreCallingIdentity(token);
4734 }
4735 }
4736
4737 /**
4738 * Get the transport type for the IMS service registration state.
4739 */
4740 @Override
4741 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004742 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004743 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004744 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4745 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4746 "IMS not available on device.");
4747 }
4748 final long token = Binder.clearCallingIdentity();
4749 try {
4750 Phone phone = getPhone(subId);
4751 if (phone == null) {
4752 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4753 + subId + "'");
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4755 }
4756 phone.getImsRegistrationTech(regTech -> {
4757 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4758 int regTechConverted = (regTech == null)
4759 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4760 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4761 regTechConverted);
4762 try {
4763 consumer.accept(regTechConverted);
4764 } catch (RemoteException e) {
4765 // Ignore if the remote process is no longer available to call back.
4766 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4767 }
4768 });
4769 } finally {
4770 Binder.restoreCallingIdentity(token);
4771 }
4772 }
4773
shilu366312e2019-12-17 09:28:10 -08004774 /**
4775 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4776 * @param subId The subscription to use to check the configuration.
4777 * @param c The callback that will be used to send the result.
4778 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004780 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4781 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004782 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004783 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004784 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4785 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4786 "IMS not available on device.");
4787 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 final long token = Binder.clearCallingIdentity();
4789 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004790 int slotId = getSlotIndexOrException(subId);
4791 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004792
4793 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4794 if (controller != null) {
4795 ImsManager imsManager = controller.getImsManager(subId);
4796 if (imsManager != null) {
4797 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4798 } else {
4799 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4800 }
4801 } else {
4802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4803 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004804 } catch (ImsException e) {
4805 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004806 } finally {
4807 Binder.restoreCallingIdentity(token);
4808 }
4809 }
4810
shilu366312e2019-12-17 09:28:10 -08004811 /**
4812 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4813 * @param subId The subscription to use to check the configuration.
4814 * @param c The callback that will be used to send the result.
4815 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004817 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004818 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004819 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004820 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4821 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4822 }
Meng Wangafbc5852019-09-19 17:37:13 -07004823
4824 final long token = Binder.clearCallingIdentity();
4825 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004826 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4827 if (controller != null) {
4828 ImsManager imsManager = controller.getImsManager(subId);
4829 if (imsManager != null) {
4830 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4831 } else {
4832 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4833 + " is inactive, ignoring unregister.");
4834 // If the ImsManager is not valid, just return, since the callback
4835 // will already have been removed internally.
4836 }
4837 }
Meng Wangafbc5852019-09-19 17:37:13 -07004838 } finally {
4839 Binder.restoreCallingIdentity(token);
4840 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004841 }
4842
4843 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004844 public boolean isCapable(int subId, int capability, int regTech) {
4845 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004846
4847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4848 FEATURE_TELEPHONY_IMS, "isCapable");
4849
Brad Ebinger35c841c2018-10-01 10:40:55 -07004850 final long token = Binder.clearCallingIdentity();
4851 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004852 int slotId = getSlotIndexOrException(subId);
4853 verifyImsMmTelConfiguredOrThrow(slotId);
4854 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4855 } catch (com.android.ims.ImsException e) {
4856 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4857 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004858 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004859 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4860 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004861 } finally {
4862 Binder.restoreCallingIdentity(token);
4863 }
4864 }
4865
4866 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004867 public boolean isAvailable(int subId, int capability, int regTech) {
4868 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004869
4870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4871 FEATURE_TELEPHONY_IMS, "isAvailable");
4872
Brad Ebinger35c841c2018-10-01 10:40:55 -07004873 final long token = Binder.clearCallingIdentity();
4874 try {
4875 Phone phone = getPhone(subId);
4876 if (phone == null) return false;
4877 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004878 } catch (com.android.ims.ImsException e) {
4879 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4880 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004881 } finally {
4882 Binder.restoreCallingIdentity(token);
4883 }
4884 }
4885
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004886 /**
4887 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4888 * subscription.
4889 * @param subId The subscription to use to check the configuration.
4890 * @param callback The callback that will be used to send the result.
4891 * @param capability The MmTelFeature capability that will be used to send the result.
4892 * @param transportType The transport type of the MmTelFeature capability.
4893 */
4894 @Override
4895 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4896 int transportType) {
4897 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004898 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4899 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4900 "IMS not available on device.");
4901 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004902 final long token = Binder.clearCallingIdentity();
4903 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004904 int slotId = getSlotIndex(subId);
4905 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4906 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4907 + subId + "'");
4908 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4909 }
4910 verifyImsMmTelConfiguredOrThrow(slotId);
4911 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4912 transportType, aBoolean -> {
4913 try {
4914 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4915 } catch (RemoteException e) {
4916 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4917 + "running. Ignore");
4918 }
4919 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004920 } catch (ImsException e) {
4921 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004922 } finally {
4923 Binder.restoreCallingIdentity(token);
4924 }
4925 }
4926
shilu366312e2019-12-17 09:28:10 -08004927 /**
4928 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4929 * @param subId The subscription to use to check the configuration.
4930 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004931 @Override
4932 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004933 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004934 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004935
joonhunshin4ac60942023-11-15 15:23:39 +00004936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4937 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4938
Brad Ebinger35c841c2018-10-01 10:40:55 -07004939 final long token = Binder.clearCallingIdentity();
4940 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004941 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004942 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004943 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004944 } catch (ImsException e) {
4945 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 } finally {
4947 Binder.restoreCallingIdentity(token);
4948 }
4949 }
4950
4951 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004952 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004954 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004955
4956 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4957 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4958
Brad Ebinger35c841c2018-10-01 10:40:55 -07004959 final long identity = Binder.clearCallingIdentity();
4960 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004961 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004962 // This setting doesn't require an active ImsService connection, so do not verify. The
4963 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004965 } catch (ImsException e) {
4966 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971
shilu366312e2019-12-17 09:28:10 -08004972 /**
4973 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4974 * @param subId The subscription to use to check the configuration.
4975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004977 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004979 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004980
4981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4982 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4983
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 final long identity = Binder.clearCallingIdentity();
4985 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004986 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004987 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004989 } catch (ImsException e) {
4990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
4994 }
4995
4996 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004997 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004999 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005000
5001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5002 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5003
Brad Ebinger35c841c2018-10-01 10:40:55 -07005004 final long identity = Binder.clearCallingIdentity();
5005 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005006 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005007 // This setting doesn't require an active ImsService connection, so do not verify. The
5008 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005009 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005010 } catch (ImsException e) {
5011 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
5015 }
5016
shilu366312e2019-12-17 09:28:10 -08005017 /**
5018 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5019 * @param subId The subscription to use to check the configuration.
5020 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005021 @Override
5022 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005023 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005024 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005025
5026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5027 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5028
Brad Ebinger35c841c2018-10-01 10:40:55 -07005029 final long identity = Binder.clearCallingIdentity();
5030 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005031 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005032 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005033 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005034 } catch (ImsException e) {
5035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
5039 }
5040
5041 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005042 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005044 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005045
5046 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5047 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5048
Brad Ebinger35c841c2018-10-01 10:40:55 -07005049 final long identity = Binder.clearCallingIdentity();
5050 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005051 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005052 // This setting doesn't require an active ImsService connection, so do not verify. The
5053 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005054 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005055 } catch (ImsException e) {
5056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
5059 }
5060 }
5061
shilu366312e2019-12-17 09:28:10 -08005062 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005063 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5064 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5065 * @param subId The subscription to use to check the configuration.
5066 */
5067 @Override
5068 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005069 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005070 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005071
5072 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5073 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5074
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005077 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005078 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005079 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005080 } catch (ImsException e) {
5081 throw new ServiceSpecificException(e.getCode());
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
5085 }
5086
5087 /**
5088 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5089 * Requires MODIFY_PHONE_STATE permission.
5090 * @param subId The subscription to use to check the configuration.
5091 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5092 * false otherwise
5093 */
5094 @Override
5095 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5097 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005098
5099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5100 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5101
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005102 final long identity = Binder.clearCallingIdentity();
5103 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005104 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005105 // This setting doesn't require an active ImsService connection, so do not verify. The
5106 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005107 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005108 } catch (ImsException e) {
5109 throw new ServiceSpecificException(e.getCode());
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
5113 }
5114
5115 /**
shilu366312e2019-12-17 09:28:10 -08005116 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5117 * @param subId The subscription to use to check the configuration.
5118 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005119 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005120
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005122 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005123 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005124
5125 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5126 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5127
Brad Ebinger35c841c2018-10-01 10:40:55 -07005128 final long identity = Binder.clearCallingIdentity();
5129 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005130 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005131 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005132 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005133 } catch (ImsException e) {
5134 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
5138 }
5139
5140 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005141 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005143 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005144
5145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5146 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5147
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 final long identity = Binder.clearCallingIdentity();
5149 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005150 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005151 // This setting doesn't require an active ImsService connection, so do not verify. The
5152 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005153 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005154 } catch (ImsException e) {
5155 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
5159 }
5160
5161 @Override
5162 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5164 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005165
5166 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5167 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5168
Brad Ebinger35c841c2018-10-01 10:40:55 -07005169 final long identity = Binder.clearCallingIdentity();
5170 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005171 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005172 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005174 } catch (ImsException e) {
5175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
shilu366312e2019-12-17 09:28:10 -08005181 /**
5182 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5183 * @param subId The subscription to use to check the configuration.
5184 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005185 @Override
5186 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005187 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005188 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005189
5190 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5191 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5192
Brad Ebinger35c841c2018-10-01 10:40:55 -07005193 final long identity = Binder.clearCallingIdentity();
5194 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005195 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005196 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005197 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005198 } catch (ImsException e) {
5199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
5203 }
5204
5205 @Override
5206 public void setVoWiFiModeSetting(int subId, int mode) {
5207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5208 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005209
5210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5211 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5212
Brad Ebinger35c841c2018-10-01 10:40:55 -07005213 final long identity = Binder.clearCallingIdentity();
5214 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005215 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005216 // This setting doesn't require an active ImsService connection, so do not verify. The
5217 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005218 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005219 } catch (ImsException e) {
5220 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
5224 }
5225
5226 @Override
5227 public int getVoWiFiRoamingModeSetting(int subId) {
5228 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005229
5230 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5231 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5232
Brad Ebinger35c841c2018-10-01 10:40:55 -07005233 final long identity = Binder.clearCallingIdentity();
5234 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005235 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005236 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005237 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005238 } catch (ImsException e) {
5239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244
5245 @Override
5246 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5248 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005249
5250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5251 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5252
Brad Ebinger35c841c2018-10-01 10:40:55 -07005253 final long identity = Binder.clearCallingIdentity();
5254 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005256 // This setting doesn't require an active ImsService connection, so do not verify. The
5257 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005258 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005259 } catch (ImsException e) {
5260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
5264 }
5265
5266 @Override
5267 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5269 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005270
5271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5272 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5273
Brad Ebinger35c841c2018-10-01 10:40:55 -07005274 final long identity = Binder.clearCallingIdentity();
5275 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005276 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005277 // This setting doesn't require an active ImsService connection, so do not verify. The
5278 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005279 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005280 } catch (ImsException e) {
5281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
5285 }
5286
shilu366312e2019-12-17 09:28:10 -08005287 /**
5288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5289 * @param subId The subscription to use to check the configuration.
5290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005291 @Override
5292 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005294 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005295
5296 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5297 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5298
Brad Ebinger35c841c2018-10-01 10:40:55 -07005299 final long identity = Binder.clearCallingIdentity();
5300 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005301 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005302 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005303 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005304 } catch (ImsException e) {
5305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
5309 }
5310
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005311 @Override
5312 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5313 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005314
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005315 final long identity = Binder.clearCallingIdentity();
5316 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005317 if (!isImsAvailableOnDevice()) {
5318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5319 "IMS not available on device.");
5320 }
5321 int slotId = getSlotIndexOrException(subId);
5322 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005323
5324 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5325 if (controller != null) {
5326 ImsManager imsManager = controller.getImsManager(subId);
5327 if (imsManager != null) {
5328 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5329 } else {
5330 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5331 }
5332 } else {
5333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5334 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005335 } catch (ImsException e) {
5336 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
5340 }
5341
5342 @Override
5343 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5344 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005345
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005346 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5348 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5349 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005350 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005351 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5352 if (controller != null) {
5353 ImsManager imsManager = controller.getImsManager(subId);
5354 if (imsManager != null) {
5355 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5356 } else {
5357 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5358 + " is inactive, ignoring unregister.");
5359 // If the ImsManager is not valid, just return, since the callback will already
5360 // have been removed internally.
5361 }
5362 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
5366 }
5367
joonhunshincffb7fc2021-11-28 07:32:01 +00005368 @Override
5369 public void registerFeatureProvisioningChangedCallback(int subId,
5370 IFeatureProvisioningCallback callback) {
5371 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5372 mApp, subId, "registerFeatureProvisioningChangedCallback");
5373
5374 final long identity = Binder.clearCallingIdentity();
5375 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5376 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5377 }
5378
joonhunshin91bc1952022-04-29 08:47:15 +00005379 try {
5380 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5381 if (controller == null) {
5382 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5383 "Device does not support IMS");
5384 }
5385 controller.addFeatureProvisioningChangedCallback(subId, callback);
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005389 }
5390
5391 @Override
5392 public void unregisterFeatureProvisioningChangedCallback(int subId,
5393 IFeatureProvisioningCallback callback) {
5394 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5395 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5396
5397 final long identity = Binder.clearCallingIdentity();
5398 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5399 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5400 }
5401
joonhunshin91bc1952022-04-29 08:47:15 +00005402 try {
5403 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5404 if (controller == null) {
5405 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5406 return;
5407 }
5408 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
5411 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005412 }
allenwtsu99c623b2020-01-03 18:24:23 +08005413
5414 private void checkModifyPhoneStatePermission(int subId, String message) {
5415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5416 message);
5417 }
5418
allenwtsu99c623b2020-01-03 18:24:23 +08005419 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005420 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005421 boolean isProvisioned) {
5422 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5423
joonhunshin4ac60942023-11-15 15:23:39 +00005424 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5425 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5426
allenwtsu99c623b2020-01-03 18:24:23 +08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005429 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5430 if (controller == null) {
5431 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5432 return;
5433 }
5434 controller.setRcsProvisioningStatusForCapability(
5435 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
allenwtsu99c623b2020-01-03 18:24:23 +08005439 }
5440
5441
5442 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005443 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5444 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5445 mApp, subId, "getRcsProvisioningStatusForCapability");
5446
joonhunshin4ac60942023-11-15 15:23:39 +00005447 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5448 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5449
allenwtsu99c623b2020-01-03 18:24:23 +08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005452 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5453 if (controller == null) {
5454 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5455
5456 // device does not support IMS, this method will return true always.
5457 return true;
5458 }
5459 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
5463 }
5464
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005465 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005466 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5467 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005468 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005469
joonhunshin4ac60942023-11-15 15:23:39 +00005470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5471 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5472
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005473 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005476 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5477 if (controller == null) {
5478 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5479 return;
5480 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005481 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005482 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
5486 }
5487
5488 @Override
5489 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005490 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5491 mApp, subId, "getProvisioningStatusForCapability");
5492
joonhunshin4ac60942023-11-15 15:23:39 +00005493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5494 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5495
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005496 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005497 final long identity = Binder.clearCallingIdentity();
5498 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005499 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5500 if (controller == null) {
5501 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502
joonhunshin91bc1952022-04-29 08:47:15 +00005503 // device does not support IMS, this method will return true always.
5504 return true;
5505 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005506 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5507 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
5511 }
5512
5513 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005514 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5515 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5516 mApp, subId, "isProvisioningRequiredForCapability");
5517
joonhunshin4ac60942023-11-15 15:23:39 +00005518 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5519 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5520
joonhunshincffb7fc2021-11-28 07:32:01 +00005521 final long identity = Binder.clearCallingIdentity();
5522 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005523 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5524 if (controller == null) {
5525 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5526
5527 // device does not support IMS, this method will return false
5528 return false;
5529 }
5530 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005534 }
5535
5536 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005537 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5538 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5539 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005540
joonhunshin4ac60942023-11-15 15:23:39 +00005541 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5542 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5543
joonhunshincffb7fc2021-11-28 07:32:01 +00005544 final long identity = Binder.clearCallingIdentity();
5545 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005546 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5547 if (controller == null) {
5548 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5549
5550 // device does not support IMS, this method will return false
5551 return false;
5552 }
5553 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005557 }
5558
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005559 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005560 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005561 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5562 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5563 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005564 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5565 mApp, subId, "getImsProvisioningInt");
5566
joonhunshin4ac60942023-11-15 15:23:39 +00005567 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5568 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5569
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005570 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005574 int slotId = getSlotIndex(subId);
5575 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5576 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5577 + subId + "' for key:" + key);
5578 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5579 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005580
joonhunshin91bc1952022-04-29 08:47:15 +00005581 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5582 if (controller == null) {
5583 loge("getImsProvisioningInt: Device does not support IMS");
5584
5585 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5586 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5587 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005588 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5589 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005590 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5591 return retVal;
5592 }
5593
calvinpanb5a34062021-02-08 19:59:36 +08005594 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005595 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005596 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5597 + subId + "' for key:" + key);
5598 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603
5604 @Override
5605 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005606 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5607 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5608 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005609 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5610 mApp, subId, "getImsProvisioningString");
5611
joonhunshin4ac60942023-11-15 15:23:39 +00005612 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5613 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5614
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 int slotId = getSlotIndex(subId);
5619 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5620 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5621 + subId + "' for key:" + key);
5622 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5623 }
calvinpanb5a34062021-02-08 19:59:36 +08005624 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005625 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005626 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5627 + subId + "' for key:" + key);
5628 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
5632 }
5633
5634 @Override
5635 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5637 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5638 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5640 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005641
joonhunshin4ac60942023-11-15 15:23:39 +00005642 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5643 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5644
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005645 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005649 int slotId = getSlotIndex(subId);
5650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5651 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5652 + subId + "' for key:" + key);
5653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5654 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005655
joonhunshin91bc1952022-04-29 08:47:15 +00005656 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5657 if (controller == null) {
5658 loge("setImsProvisioningInt: Device does not support IMS");
5659
5660 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5662 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005663 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5664 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005665 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5666 return retVal;
5667 }
5668
calvinpanb5a34062021-02-08 19:59:36 +08005669 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5670 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005671 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005672 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005673 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 }
5678
5679 @Override
5680 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005681 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5682 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5683 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5685 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005686
5687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5688 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5689
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005693 int slotId = getSlotIndex(subId);
5694 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5695 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5696 + subId + "' for key:" + key);
5697 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5698 }
calvinpanb5a34062021-02-08 19:59:36 +08005699 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5700 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005701 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005702 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005703 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
5707 }
5708
Brad Ebinger919631e2021-06-02 17:46:35 -07005709 /**
5710 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5711 * for the given slot ID or no ImsResolver instance has been created.
5712 * @param slotId The slot ID that the IMS service is created for.
5713 * @throws ImsException If there is no ImsService configured for this slot.
5714 */
5715 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5716 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5717 ImsFeature.FEATURE_MMTEL)) {
5718 throw new ImsException("This subscription does not support MMTEL over IMS",
5719 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5720 }
5721 }
5722
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005723 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005724 int slotId = SubscriptionManager.getSlotIndex(subId);
5725 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005726 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5727 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005728 }
5729 return slotId;
5730 }
5731
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005732 private int getSlotIndex(int subId) {
5733 int slotId = SubscriptionManager.getSlotIndex(subId);
5734 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5735 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5736 }
5737 return slotId;
5738 }
5739
Wink Saville36469e72014-06-11 15:17:00 -07005740 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005741 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005742 */
5743 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005744 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5745 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005746 try {
5747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5748 } catch (SecurityException se) {
5749 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5750 throw new SecurityException("Package " + callingPackage + " does not belong to "
5751 + Binder.getCallingUid());
5752 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005753 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005754 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005755 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005756 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005757 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005758 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005759 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5761 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005762
joonhunshin4ac60942023-11-15 15:23:39 +00005763 enforceTelephonyFeatureWithException(callingPackage,
5764 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 final Phone phone = getPhone(subId);
5769 if (phone != null) {
5770 return phone.getServiceState().getDataNetworkType();
5771 } else {
5772 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5773 }
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005777 }
5778
5779 /**
5780 * Returns the data network type
5781 */
5782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005783 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005784 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005785 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005786 }
5787
5788 /**
5789 * Returns the data network type for a subId
5790 */
5791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005792 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5793 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005794 String functionName = "getDataNetworkTypeForSubscriber";
5795 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5796 mApp, functionName)) {
5797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5798 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5799 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5800 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005801 }
5802
joonhunshin4ac60942023-11-15 15:23:39 +00005803 enforceTelephonyFeatureWithException(callingPackage,
5804 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 final Phone phone = getPhone(subId);
5809 if (phone != null) {
5810 return phone.getServiceState().getDataNetworkType();
5811 } else {
5812 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5813 }
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005817 }
5818
5819 /**
Wink Saville36469e72014-06-11 15:17:00 -07005820 * Returns the Voice network type for a subId
5821 */
5822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005823 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5824 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005825 String functionName = "getVoiceNetworkTypeForSubscriber";
5826 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5827 mApp, functionName)) {
5828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5829 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5831 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005832 }
5833
joonhunshin4ac60942023-11-15 15:23:39 +00005834 enforceTelephonyFeatureWithException(callingPackage,
5835 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 final Phone phone = getPhone(subId);
5840 if (phone != null) {
5841 return phone.getServiceState().getVoiceNetworkType();
5842 } else {
5843 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5844 }
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005848 }
5849
5850 /**
5851 * @return true if a ICC card is present
5852 */
5853 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005854 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005855 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005856 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005857 }
5858
5859 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005860 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005861 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005862 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005863 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005864 if (!mApp.getResources().getBoolean(
5865 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5867 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5868 }
joonhunshin4ac60942023-11-15 15:23:39 +00005869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 final long identity = Binder.clearCallingIdentity();
5871 try {
5872 final Phone phone = PhoneFactory.getPhone(slotIndex);
5873 if (phone != null) {
5874 return phone.getIccCard().hasIccCard();
5875 } else {
5876 return false;
5877 }
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005881 }
5882
5883 /**
5884 * Return if the current radio is LTE on CDMA. This
5885 * is a tri-state return value as for a period of time
5886 * the mode may be unknown.
5887 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005888 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005889 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005890 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005891 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005893 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5894 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5895 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005896 }
5897
Sanket Padawe356d7632015-06-22 14:03:32 -07005898 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005899 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5900 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005901 try {
5902 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5903 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005904 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5905 }
5906
joonhunshin4ac60942023-11-15 15:23:39 +00005907 enforceTelephonyFeatureWithException(callingPackage,
5908 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 final Phone phone = getPhone(subId);
5913 if (phone == null) {
5914 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5915 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005916 return TelephonyProperties.lte_on_cdma_device()
5917 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 }
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005921 }
Wink Saville36469e72014-06-11 15:17:00 -07005922 }
5923
Wink Saville36469e72014-06-11 15:17:00 -07005924 /**
5925 * {@hide}
5926 * Returns Default subId, 0 in the case of single standby.
5927 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005928 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005929 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005930 }
5931
Shishir Agrawala9f32182016-04-12 12:00:16 -07005932 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005933 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005934 }
5935
Wink Savilleb564aae2014-10-23 10:18:09 -07005936 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005937 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005938 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005939
Pengquan Menge92a50d2018-09-21 15:54:48 -07005940 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005941 return getSubscriptionManagerService().isActiveSubId(subId,
5942 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005943 }
5944
Ihab Awadf2177b72013-11-25 13:33:23 -08005945 /**
5946 * @see android.telephony.TelephonyManager.WifiCallingChoices
5947 */
5948 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005951 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5953 getWhenToMakeWifiCallsDefaultPreference());
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005957 }
5958
5959 /**
5960 * @see android.telephony.TelephonyManager.WifiCallingChoices
5961 */
5962 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005966 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005971 }
5972
Sailesh Nepald1e68152013-12-12 19:08:02 -08005973 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005974 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005975 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005976 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005977
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005978 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5979 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5980 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005981 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005982 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005983 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005984 }
5985 return PhoneFactory.getPhone(phoneId);
5986 }
5987
Shishir Agrawal566b7612013-10-28 14:41:00 -07005988 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005989 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005990 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005991
Rambo Wanga1782702021-11-10 20:15:19 -08005992 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5993 /*message=*/ "iccOpenLogicalChannel");
5994
5995 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5996 // Verify that the callingPackage in the request belongs to the calling UID
5997 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5998
joonhunshin4ac60942023-11-15 15:23:39 +00005999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6000 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6001
Rambo Wanga1782702021-11-10 20:15:19 -08006002 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006003 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006004
Rambo Wanga1782702021-11-10 20:15:19 -08006005 private Phone getPhoneFromValidIccLogicalChannelRequest(
6006 @NonNull IccLogicalChannelRequest request, String message) {
6007 Phone phone;
6008 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6010 mApp, request.subId, message);
6011 phone = getPhoneFromSubId(request.subId);
6012 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6013 enforceModifyPermission();
6014 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6015 } else {
6016 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006017 }
Rambo Wanga1782702021-11-10 20:15:19 -08006018 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006019 }
6020
6021 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006022 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 final long identity = Binder.clearCallingIdentity();
6024 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006025 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006027 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6028 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006029 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6030 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 loge("The calling package is not allowed to access ISD-R.");
6032 throw new SecurityException(
6033 "The calling package is not allowed to access ISD-R.");
6034 }
Derek Tan740e1672017-06-27 14:56:27 -07006035 }
Derek Tan740e1672017-06-27 14:56:27 -07006036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006038 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6039 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 return response;
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006044 }
6045
6046 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006047 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6049 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6050
Rambo Wanga1782702021-11-10 20:15:19 -08006051 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6052 /*message=*/"iccCloseLogicalChannel");
6053
6054 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6055
6056 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006057 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006058
Rambo Wanga1782702021-11-10 20:15:19 -08006059 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6060 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006061 // before this feature is enabled, this API should only return false if
6062 // the operation fails instead of throwing runtime exception for
6063 // backward-compatibility.
6064 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6065 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 final long identity = Binder.clearCallingIdentity();
6067 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006068 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006069 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 }
Chen Xue9d737e2022-01-01 23:41:31 -08006071 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006072 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006073 Boolean success = false;
6074 if (result instanceof RuntimeException) {
6075 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006076 if (shouldThrowExceptionOnFailure) {
6077 throw (RuntimeException) result;
6078 } else {
6079 return false;
6080 }
Chen Xue9d737e2022-01-01 23:41:31 -08006081 } else if (result instanceof Boolean) {
6082 success = (Boolean) result;
6083 } else {
6084 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6085 }
Rambo Wanga1782702021-11-10 20:15:19 -08006086 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 return success;
6088 } finally {
6089 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006091 }
6092
6093 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006094 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006095 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6097 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006098
6099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6100 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6101
Jordan Liu4c733742019-02-28 12:03:40 -08006102 if (DBG) {
6103 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6104 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6105 + p3 + " data=" + data);
6106 }
6107 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6108 command, p1, p2, p3, data);
6109 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006110
Jordan Liu4c733742019-02-28 12:03:40 -08006111 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006112 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006113 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006114 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006115
6116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6117 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6118 "iccTransmitApduLogicalChannelBySlot");
6119
Jordan Liu4c733742019-02-28 12:03:40 -08006120 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006121 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006122 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6123 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006124 }
6125 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006126 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6127 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006128 }
6129
6130 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6131 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 final long identity = Binder.clearCallingIdentity();
6133 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006134 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 return "";
6136 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006139 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6140 null /* workSource */);
6141 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 // Append the returned status code to the end of the response payload.
6144 String s = Integer.toHexString(
6145 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6146 if (response.payload != null) {
6147 s = IccUtils.bytesToHexString(response.payload) + s;
6148 }
6149 return s;
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006152 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006153 }
Jake Hambye994d462014-02-03 13:10:13 -08006154
Evan Charltonc66da362014-05-16 14:06:40 -07006155 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006156 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6157 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6159 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006161
6162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6163 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6164
Jordan Liu4c733742019-02-28 12:03:40 -08006165 if (DBG) {
6166 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6167 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6168 }
6169 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6170 cla, command, p1, p2, p3, data);
6171 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006172
Jordan Liu4c733742019-02-28 12:03:40 -08006173 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006174 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006175 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006176 enforceModifyPermission();
6177 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006178
6179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6180 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6181
Jordan Liu4c733742019-02-28 12:03:40 -08006182 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006183 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006184 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6185 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006186 }
6187
6188 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006189 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6190 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006191 }
6192
6193 // open APDU basic channel assuming the caller has sufficient permissions
6194 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6195 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 final long identity = Binder.clearCallingIdentity();
6197 try {
6198 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6199 && TextUtils.equals(ISDR_AID, data)) {
6200 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006201 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6202 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 if (bestComponent == null
6204 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6205 loge("The calling package is not allowed to select ISD-R.");
6206 throw new SecurityException(
6207 "The calling package is not allowed to select ISD-R.");
6208 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006209 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006212 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6213 null /* workSource */);
6214 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 // Append the returned status code to the end of the response payload.
6217 String s = Integer.toHexString(
6218 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6219 if (response.payload != null) {
6220 s = IccUtils.bytesToHexString(response.payload) + s;
6221 }
6222 return s;
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006225 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006226 }
6227
6228 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006229 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006230 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6232 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006233
joonhunshin4ac60942023-11-15 15:23:39 +00006234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6235 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 if (DBG) {
6240 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6241 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6242 }
6243
6244 IccIoResult response =
6245 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6246 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6247 subId);
6248
6249 if (DBG) {
6250 log("Exchange SIM_IO [R]" + response);
6251 }
6252
6253 byte[] result = null;
6254 int length = 2;
6255 if (response.payload != null) {
6256 length = 2 + response.payload.length;
6257 result = new byte[length];
6258 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6259 } else {
6260 result = new byte[length];
6261 }
6262
6263 result[length - 1] = (byte) response.sw2;
6264 result[length - 2] = (byte) response.sw1;
6265 return result;
6266 } finally {
6267 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006268 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006269 }
6270
Nathan Haroldb3014052017-01-25 15:57:32 -08006271 /**
6272 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6273 * on a particular subscription
6274 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006275 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6276 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006278 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006279 return null;
6280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281
joonhunshin4ac60942023-11-15 15:23:39 +00006282 enforceTelephonyFeatureWithException(callingPackage,
6283 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 if (appType != TelephonyManager.APPTYPE_USIM
6288 && appType != TelephonyManager.APPTYPE_SIM) {
6289 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6290 return null;
6291 }
6292 Object response = sendRequest(
6293 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6294 if (response instanceof String[]) {
6295 return (String[]) response;
6296 }
yincheng zhao2737e882019-09-06 17:06:54 -07006297 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006299 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 } finally {
6301 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006302 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006303 }
6304
yincheng zhao2737e882019-09-06 17:06:54 -07006305 /**
6306 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6307 * subscription.
6308 *
6309 * @param subId the id of the subscription.
6310 * @param appType the uicc app type, must be USIM or SIM.
6311 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6312 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006313 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006314 * @return number of fplmns that is successfully written to the SIM.
6315 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006316 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6317 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6319 mApp, subId, "setForbiddenPlmns");
6320
joonhunshin4ac60942023-11-15 15:23:39 +00006321 enforceTelephonyFeatureWithException(callingPackage,
6322 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6323
yincheng zhao2737e882019-09-06 17:06:54 -07006324 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6325 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6326 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6327 }
6328 if (fplmns == null) {
6329 throw new IllegalArgumentException("Fplmn List provided is null");
6330 }
6331 for (String fplmn : fplmns) {
6332 if (!CellIdentity.isValidPlmn(fplmn)) {
6333 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6334 }
6335 }
6336 final long identity = Binder.clearCallingIdentity();
6337 try {
6338 Object response = sendRequest(
6339 CMD_SET_FORBIDDEN_PLMNS,
6340 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6341 subId);
6342 return (int) response;
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
6346 }
6347
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006348 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006349 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6351 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006352
joonhunshin4ac60942023-11-15 15:23:39 +00006353 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6354 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6359 if (response.payload == null) {
6360 return "";
6361 }
Evan Charltonc66da362014-05-16 14:06:40 -07006362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 // Append the returned status code to the end of the response payload.
6364 String s = Integer.toHexString(
6365 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6366 s = IccUtils.bytesToHexString(response.payload) + s;
6367 return s;
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
Evan Charltonc66da362014-05-16 14:06:40 -07006371 }
6372
Jake Hambye994d462014-02-03 13:10:13 -08006373 /**
6374 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6375 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6376 *
6377 * @param itemID the ID of the item to read
6378 * @return the NV item as a String, or null on error.
6379 */
6380 @Override
6381 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006382 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6384 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385
6386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006389 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6391 return value;
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Jake Hambye994d462014-02-03 13:10:13 -08006395 }
6396
6397 /**
6398 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6399 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6400 *
6401 * @param itemID the ID of the item to read
6402 * @param itemValue the value to write, as a String
6403 * @return true on success; false on any failure
6404 */
6405 @Override
6406 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006407 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6409 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6414 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006415 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6417 return success;
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Jake Hambye994d462014-02-03 13:10:13 -08006421 }
6422
6423 /**
6424 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6425 * Used for device configuration by some CDMA operators.
6426 *
6427 * @param preferredRoamingList byte array containing the new PRL
6428 * @return true on success; false on any failure
6429 */
6430 @Override
6431 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6433 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434
6435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6438 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6439 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6440 return success;
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
6443 }
Jake Hambye994d462014-02-03 13:10:13 -08006444 }
6445
6446 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006447 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006448 * Used for device configuration by some CDMA operators.
6449 *
chen xu6dac5ab2018-10-26 17:39:23 -07006450 * @param slotIndex - device slot.
6451 *
Jake Hambye994d462014-02-03 13:10:13 -08006452 * @return true on success; false on any failure
6453 */
6454 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006455 public boolean resetModemConfig(int slotIndex) {
6456 Phone phone = PhoneFactory.getPhone(slotIndex);
6457 if (phone != null) {
6458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6459 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460
joonhunshin4ac60942023-11-15 15:23:39 +00006461 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6462 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6463
chen xu6dac5ab2018-10-26 17:39:23 -07006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6467 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6468 return success;
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 }
chen xu6dac5ab2018-10-26 17:39:23 -07006473 return false;
6474 }
6475
6476 /**
6477 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6478 *
6479 * @param slotIndex - device slot.
6480 *
6481 * @return true on success; false on any failure
6482 */
6483 @Override
6484 public boolean rebootModem(int slotIndex) {
6485 Phone phone = PhoneFactory.getPhone(slotIndex);
6486 if (phone != null) {
6487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6488 mApp, phone.getSubId(), "rebootModem");
6489
joonhunshin4ac60942023-11-15 15:23:39 +00006490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6491 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6492
chen xu6dac5ab2018-10-26 17:39:23 -07006493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6496 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6497 return success;
6498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
6501 }
6502 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006503 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006504
Brad Ebinger51f743a2017-01-23 13:50:20 -08006505 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006506 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6507 * {@link #disableIms(int)}.
6508 * @param slotIndex device slot.
6509 */
6510 public void resetIms(int slotIndex) {
6511 enforceModifyPermission();
6512
joonhunshin4ac60942023-11-15 15:23:39 +00006513 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6514 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6515
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006516 final long identity = Binder.clearCallingIdentity();
6517 try {
6518 if (mImsResolver == null) {
6519 // may happen if the does not support IMS.
6520 return;
6521 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006522 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
6526 }
6527
6528 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006529 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6530 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006531 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006532 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006533 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534
6535 final long identity = Binder.clearCallingIdentity();
6536 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006537 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006538 // may happen if the device does not support IMS.
6539 return;
6540 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006541 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006545 }
6546
6547 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006548 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6549 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006550 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006551 public void disableIms(int slotId) {
6552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006556 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006557 // may happen if the device does not support IMS.
6558 return;
6559 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006560 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006564 }
6565
6566 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006567 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6568 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006569 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006570 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006571 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006576 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006577 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6578 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006579 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006580 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006584 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006585 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006586 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6587 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006588 @Override
6589 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006590 enforceModifyPermission();
6591
6592 final long identity = Binder.clearCallingIdentity();
6593 try {
6594 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006595 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006596 } finally {
6597 Binder.restoreCallingIdentity(identity);
6598 }
6599 }
6600
6601 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006602 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006603 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006604 */
6605 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006610 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006611 // may happen if the device does not support IMS.
6612 return null;
6613 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006614 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006618 }
6619
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006620 /**
6621 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006622 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006623 */
6624 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6625 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006629 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006630 // may happen if the device does not support IMS.
6631 return null;
6632 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006633 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 } finally {
6635 Binder.restoreCallingIdentity(identity);
6636 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006637 }
6638
Brad Ebinger884c07b2018-02-15 16:17:40 -08006639 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006640 * Sets the ImsService Package Name that Telephony will bind to.
6641 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006642 * @param slotIndex the slot ID that the ImsService should bind for.
Brad Ebinger555ddec2024-11-04 13:46:31 -08006643 * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL}
6644 * if there is no preference.
Brad Ebinger24c29992019-12-05 13:03:21 -08006645 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006646 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006647 * @param featureTypes An integer array of feature types associated with a packageName.
6648 * @param packageName The name of the package that the current configuration will be replaced
6649 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006650 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 */
Brad Ebinger555ddec2024-11-04 13:46:31 -08006652 public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService,
Brad Ebinger24c29992019-12-05 13:03:21 -08006653 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006656 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 final long identity = Binder.clearCallingIdentity();
6659 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006661 // may happen if the device does not support IMS.
6662 return false;
6663 }
Brad Ebinger555ddec2024-11-04 13:46:31 -08006664 return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId,
6665 isCarrierService, featureTypes);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006669 }
6670
6671 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006672 * Clears any carrier ImsService overrides for the slot index specified that were previously
6673 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6674 *
6675 * This should only be used for testing.
6676 *
6677 * @param slotIndex the slot ID that the ImsService should bind for.
6678 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6679 */
6680 @Override
6681 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6683 "clearCarrierImsServiceOverride");
6684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006685 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 if (mImsResolver == null) {
6690 // may happen if the device does not support IMS.
6691 return false;
6692 }
6693 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
6697 }
6698
6699 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006700 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006701 *
6702 * @param slotId The slot that the ImsService is associated with.
6703 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6704 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006705 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006706 * @return the package name of the ImsService configuration.
6707 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006708 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6709 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006710 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006711 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6712 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006716 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006717 // may happen if the device does not support IMS.
6718 return "";
6719 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006720 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006721 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6722 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006726 }
6727
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006728 /**
6729 * Get the MmTelFeature state associated with the requested subscription id.
6730 * @param subId The subscription that the MmTelFeature is associated with.
6731 * @param callback A callback with an integer containing the
6732 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6733 */
6734 @Override
6735 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6736 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006737 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6739 "IMS not available on device.");
6740 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006741 final long token = Binder.clearCallingIdentity();
6742 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006743 int slotId = getSlotIndex(subId);
6744 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6745 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6746 + subId + "'");
6747 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6748 }
6749 verifyImsMmTelConfiguredOrThrow(slotId);
6750 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6751 try {
6752 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6753 } catch (RemoteException e) {
6754 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6755 + "Ignore");
6756 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006757 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006758 } catch (ImsException e) {
6759 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006760 } finally {
6761 Binder.restoreCallingIdentity(token);
6762 }
6763 }
6764
Daniel Brightbb5840b2021-01-12 15:48:18 -08006765 /**
6766 * Sets the ims registration state on all valid {@link Phone}s.
6767 */
6768 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770
6771 final long identity = Binder.clearCallingIdentity();
6772 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006773 // NOTE: Before S, this method only set the default phone.
6774 for (final Phone phone : PhoneFactory.getPhones()) {
6775 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6776 phone.setImsRegistrationState(registered);
6777 }
6778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 } finally {
6780 Binder.restoreCallingIdentity(identity);
6781 }
Wink Saville36469e72014-06-11 15:17:00 -07006782 }
6783
6784 /**
Stuart Scott54788802015-03-30 13:18:01 -07006785 * Set the network selection mode to automatic.
6786 *
6787 */
6788 @Override
6789 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6791 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792
joonhunshin4ac60942023-11-15 15:23:39 +00006793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6794 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 final long identity = Binder.clearCallingIdentity();
6797 try {
shilufc958392020-01-20 11:36:01 -08006798 if (!isActiveSubscription(subId)) {
6799 return;
6800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006802 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006803 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
Stuart Scott54788802015-03-30 13:18:01 -07006807 }
6808
Jack Yud10cdd42020-09-28 20:28:01 -07006809 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006810 * Ask the radio to connect to the input network and change selection mode to manual.
6811 *
6812 * @param subId the id of the subscription.
6813 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6814 * the operator to attach to.
6815 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6816 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6817 * normal network selection next time.
6818 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006819 */
6820 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006821 public boolean setNetworkSelectionModeManual(
6822 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6824 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006825
joonhunshin4ac60942023-11-15 15:23:39 +00006826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6827 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6828
Jack Yu285100e2022-12-02 22:48:35 -08006829 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006830 if (!isActiveSubscription(subId)) {
6831 return false;
6832 }
6833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006835 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006837 if (DBG) {
6838 log("setNetworkSelectionModeManual: subId: " + subId
6839 + " operator: " + operatorInfo);
6840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
6844 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006845 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006846 /**
shilu84f6e8b2019-12-19 13:58:01 -08006847 * Get the manual network selection
6848 *
6849 * @param subId the id of the subscription.
6850 *
6851 * @return the previously saved user selected PLMN
6852 */
6853 @Override
6854 public String getManualNetworkSelectionPlmn(int subId) {
6855 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006856 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6857 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006858
joonhunshin4ac60942023-11-15 15:23:39 +00006859 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6860 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6861
shilu84f6e8b2019-12-19 13:58:01 -08006862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006865 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006866 }
6867
6868 final Phone phone = getPhone(subId);
6869 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006870 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006871 }
6872 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6873 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006874 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006879
6880 /**
6881 * Scans for available networks.
6882 */
6883 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006884 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6885 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6887 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006888 LocationAccessPolicy.LocationPermissionResult locationResult =
6889 LocationAccessPolicy.checkLocationPermission(mApp,
6890 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6891 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006892 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006893 .setCallingPid(Binder.getCallingPid())
6894 .setCallingUid(Binder.getCallingUid())
6895 .setMethod("getCellNetworkScanResults")
6896 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006897 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6898 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006899 .build());
6900 switch (locationResult) {
6901 case DENIED_HARD:
6902 throw new SecurityException("Not allowed to access scan results -- location");
6903 case DENIED_SOFT:
6904 return null;
6905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906
Pengquan Menga1bb6272018-09-06 09:59:22 -07006907 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 try {
6909 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006910 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006915 }
6916
6917 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006918 * Get the call forwarding info, given the call forwarding reason.
6919 */
6920 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006921 public void getCallForwarding(int subId, int callForwardingReason,
6922 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006923 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006924
6925 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6926 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6927
Shuo Qian4a594052020-01-23 11:59:30 -08006928 long identity = Binder.clearCallingIdentity();
6929 try {
6930 if (DBG) {
6931 log("getCallForwarding: subId " + subId
6932 + " callForwardingReason" + callForwardingReason);
6933 }
Hall Liu27d24262020-09-18 19:04:59 -07006934
6935 Phone phone = getPhone(subId);
6936 if (phone == null) {
6937 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006938 callback.onError(
6939 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006940 } catch (RemoteException e) {
6941 // ignore
6942 }
6943 return;
6944 }
6945
6946 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6947 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6948 @Override
6949 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6950 try {
6951 callback.onCallForwardingInfoAvailable(info);
6952 } catch (RemoteException e) {
6953 // ignore
6954 }
6955 }
6956
6957 @Override
6958 public void onError(int error) {
6959 try {
6960 callback.onError(error);
6961 } catch (RemoteException e) {
6962 // ignore
6963 }
6964 }
6965 });
6966 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
6970 }
6971
6972 /**
6973 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6974 * reason, the number to forward, and the timeout before the forwarding is attempted.
6975 */
6976 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006977 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6978 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006979 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006980
6981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6982 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6983
Shuo Qian4a594052020-01-23 11:59:30 -08006984 long identity = Binder.clearCallingIdentity();
6985 try {
6986 if (DBG) {
6987 log("setCallForwarding: subId " + subId
6988 + " callForwardingInfo" + callForwardingInfo);
6989 }
Hall Liu27d24262020-09-18 19:04:59 -07006990
6991 Phone phone = getPhone(subId);
6992 if (phone == null) {
6993 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006994 callback.accept(
6995 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006996 } catch (RemoteException e) {
6997 // ignore
6998 }
6999 return;
7000 }
7001
7002 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7003 FunctionalUtils.ignoreRemoteException(callback::accept));
7004
7005 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
7009 }
7010
7011 /**
Hall Liu27d24262020-09-18 19:04:59 -07007012 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007013 */
7014 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007015 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007016 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007017
7018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7019 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7020
Shuo Qian4a594052020-01-23 11:59:30 -08007021 long identity = Binder.clearCallingIdentity();
7022 try {
Hall Liu27d24262020-09-18 19:04:59 -07007023 Phone phone = getPhone(subId);
7024 if (phone == null) {
7025 try {
7026 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7027 } catch (RemoteException e) {
7028 // ignore
7029 }
7030 return;
7031 }
SongFerngWang0e767992021-03-31 22:08:45 +08007032 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7033 PersistableBundle c = configManager.getConfigForSubId(subId);
7034 boolean requireUssd = c.getBoolean(
7035 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007036
Shuo Qian4a594052020-01-23 11:59:30 -08007037 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007038 if (requireUssd) {
7039 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7040 getSubscriptionCarrierId(subId));
7041 String newUssdCommand = "";
7042 try {
7043 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007044 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007045 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7046 } catch (NullPointerException e) {
7047 loge("Failed to generate USSD number" + e);
7048 }
7049 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7050 mMainThreadHandler, callback, carrierXmlParser,
7051 CarrierXmlParser.SsEntry.SSAction.QUERY);
7052 final String ussdCommand = newUssdCommand;
7053 Executors.newSingleThreadExecutor().execute(() -> {
7054 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7055 });
7056 } else {
7057 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7058 callback::accept);
7059 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7060 }
Shuo Qian4a594052020-01-23 11:59:30 -08007061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 }
7065
7066 /**
Hall Liu27d24262020-09-18 19:04:59 -07007067 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007068 */
7069 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007070 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007071 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007072
7073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7074 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7075
Shuo Qian4a594052020-01-23 11:59:30 -08007076 long identity = Binder.clearCallingIdentity();
7077 try {
Hall Liu27d24262020-09-18 19:04:59 -07007078 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7079
7080 Phone phone = getPhone(subId);
7081 if (phone == null) {
7082 try {
7083 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7084 } catch (RemoteException e) {
7085 // ignore
7086 }
7087 return;
7088 }
7089
SongFerngWang0e767992021-03-31 22:08:45 +08007090 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7091 PersistableBundle c = configManager.getConfigForSubId(subId);
7092 boolean requireUssd = c.getBoolean(
7093 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007094
SongFerngWang0e767992021-03-31 22:08:45 +08007095 if (DBG) log("getCallWaitingStatus: subId " + subId);
7096 if (requireUssd) {
7097 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7098 getSubscriptionCarrierId(subId));
7099 CarrierXmlParser.SsEntry.SSAction ssAction =
7100 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7101 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7102 String newUssdCommand = "";
7103 try {
7104 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007105 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007106 .makeCommand(ssAction, null);
7107 } catch (NullPointerException e) {
7108 loge("Failed to generate USSD number" + e);
7109 }
7110 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7111 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7112 final String ussdCommand = newUssdCommand;
7113 Executors.newSingleThreadExecutor().execute(() -> {
7114 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7115 });
7116 } else {
7117 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7118 FunctionalUtils.ignoreRemoteException(callback::accept));
7119
7120 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7121 }
Shuo Qian4a594052020-01-23 11:59:30 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
7125 }
7126
7127 /**
yinxub1bed742017-04-17 11:45:04 -07007128 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007129 *
yinxub1bed742017-04-17 11:45:04 -07007130 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007131 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7132 * location related information which will be sent if the caller already possess
7133 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007134 * @param request contains the radio access networks with bands/channels to scan
7135 * @param messenger callback messenger for scan results or errors
7136 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007137 * @return the id of the requested scan which can be used to stop the scan.
7138 */
7139 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007140 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7141 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007142 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7144 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007145 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007146 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7147 if (!renounceFineLocationAccess) {
7148 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007149 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7150 .setCallingPackage(callingPackage)
7151 .setCallingFeatureId(callingFeatureId)
7152 .setCallingPid(Binder.getCallingPid())
7153 .setCallingUid(Binder.getCallingUid())
7154 .setMethod("requestNetworkScan")
7155 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7156 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7157 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7158 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007159 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007161 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7162 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007163 if (e != null) {
7164 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7165 throw e;
7166 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007167 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007168 return TelephonyScanManager.INVALID_SCAN_ID;
7169 }
7170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 }
joonhunshin4ac60942023-11-15 15:23:39 +00007172
7173 enforceTelephonyFeatureWithException(callingPackage,
7174 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7175
Hall Liu912dfd32019-04-25 14:02:26 -07007176 int callingUid = Binder.getCallingUid();
7177 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007181 renounceFineLocationAccess, request, messenger, binder,
7182 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007183 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
yinxu504e1392017-04-12 16:03:22 -07007187 }
7188
Hall Liub2ac8ef2019-02-28 15:56:23 -08007189 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007190 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007191 boolean hasCarrierPriv;
7192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7195 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7196 } finally {
7197 Binder.restoreCallingIdentity(identity);
7198 }
Hall Liu558027f2019-05-15 19:14:05 -07007199 boolean hasNetworkScanPermission =
7200 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007201 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007202
7203 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7204 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7205 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007206 }
7207
7208 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7209 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007210 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7211 return new SecurityException("Specific channels must not be"
7212 + " scanned without location access.");
7213 }
7214 }
7215 }
7216
Hall Liub2ac8ef2019-02-28 15:56:23 -08007217 return null;
7218 }
7219
yinxu504e1392017-04-12 16:03:22 -07007220 /**
7221 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007222 *
7223 * @param subId id of the subscription
7224 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007225 */
7226 @Override
7227 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7229 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
Hall Liu912dfd32019-04-25 14:02:26 -07007231 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 final long identity = Binder.clearCallingIdentity();
7233 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007234 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
yinxu504e1392017-04-12 16:03:22 -07007238 }
7239
7240 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007241 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007242 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007243 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007244 */
7245 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007246 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007247 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007248 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007249 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250
joonhunshin4ac60942023-11-15 15:23:39 +00007251 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7252 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 final long identity = Binder.clearCallingIdentity();
7255 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007256 if (DBG) log("getAllowedNetworkTypesBitmask");
7257 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7258 int networkTypesBitmask = (result != null ? result[0] : -1);
7259 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7260 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007264 }
7265
7266 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007267 * Get the allowed network types for certain reason.
7268 *
7269 * @param subId the id of the subscription.
7270 * @param reason the reason the allowed network type change is taking place
7271 * @return the allowed network types.
7272 */
7273 @Override
7274 public long getAllowedNetworkTypesForReason(int subId,
7275 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007276 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007277 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007278
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007279 if (!mApp.getResources().getBoolean(
7280 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7282 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7283 "getAllowedNetworkTypesForReason");
7284 }
joonhunshin4ac60942023-11-15 15:23:39 +00007285
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007286 final long identity = Binder.clearCallingIdentity();
7287 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007288 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
7292 }
7293
7294 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007295 * Enable/Disable E-UTRA-NR Dual Connectivity
7296 * @param subId subscription id of the sim card
7297 * @param nrDualConnectivityState expected NR dual connectivity state
7298 * This can be passed following states
7299 * <ol>
7300 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7301 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7302 * <li>Disable NR dual connectivity and force secondary cell to be released
7303 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7304 * </ol>
7305 * @return operation result.
7306 */
7307 @Override
7308 public int setNrDualConnectivityState(int subId,
7309 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7311 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007312 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007313 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7314 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7315 }
7316
Sooraj Sasindran37444802020-08-11 10:40:43 -07007317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7321 nrDualConnectivityState, subId,
7322 workSource);
7323 if (DBG) log("enableNRDualConnectivity result: " + result);
7324 return result;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 }
7329
7330 /**
7331 * Is E-UTRA-NR Dual Connectivity enabled
7332 * @return true if dual connectivity is enabled else false
7333 */
7334 @Override
7335 public boolean isNrDualConnectivityEnabled(int subId) {
7336 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007337 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007338 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007339 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007340 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7341 return false;
7342 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7347 null, subId, workSource);
7348 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7349 return isEnabled;
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
7353 }
7354
7355 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007356 * Set the allowed network types of the device and
7357 * provide the reason triggering the allowed network change.
7358 *
7359 * @param subId the id of the subscription.
7360 * @param reason the reason the allowed network type change is taking place
7361 * @param allowedNetworkTypes the allowed network types.
7362 * @return true on success; false on any failure.
7363 */
7364 @Override
7365 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007366 @TelephonyManager.AllowedNetworkTypesReason int reason,
7367 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7369 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007370 // If the caller only has carrier privileges, then they should not be able to override
7371 // any network types which were set for security reasons.
7372 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7373 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007374 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007375 throw new SecurityException(
7376 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007377 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007378 }
joonhunshin4ac60942023-11-15 15:23:39 +00007379
7380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7381 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7382
SongFerngWang3ef3e072020-12-21 16:41:52 +08007383 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007384 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007385 return false;
7386 }
7387 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7388 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007389 return false;
7390 }
7391
Jack Yu5b494332023-01-23 18:18:04 +00007392 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7393 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007394
Jack Yue37dd262022-12-16 11:53:37 -08007395 Phone phone = getPhone(subId);
7396 if (phone == null) {
7397 return false;
7398 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007399
Jack Yue37dd262022-12-16 11:53:37 -08007400 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007401 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007402 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007403 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007404
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007405 final long identity = Binder.clearCallingIdentity();
7406 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007407 Boolean success = (Boolean) sendRequest(
7408 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7409 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7410
7411 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7412 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
7418 /**
Miaoa84611c2019-03-15 09:21:10 +08007419 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007420 *
Miaoa84611c2019-03-15 09:21:10 +08007421 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007422 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007423 * @hide
7424 */
7425 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007426 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007427 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007428
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007429 if (!mApp.getResources().getBoolean(
7430 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7432 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7433 }
joonhunshin4ac60942023-11-15 15:23:39 +00007434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007436 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 try {
Miaoa84611c2019-03-15 09:21:10 +08007438 if (phone != null) {
7439 return phone.hasMatchedTetherApnSetting();
7440 } else {
7441 return false;
7442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 } finally {
7444 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007445 }
Junda Liu475951f2014-11-07 16:45:03 -08007446 }
7447
7448 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007449 * Get the user enabled state of Mobile Data.
7450 *
7451 * TODO: remove and use isUserDataEnabled.
7452 * This can't be removed now because some vendor codes
7453 * calls through ITelephony directly while they should
7454 * use TelephonyManager.
7455 *
7456 * @return true on enabled
7457 */
7458 @Override
7459 public boolean getDataEnabled(int subId) {
7460 return isUserDataEnabled(subId);
7461 }
7462
7463 /**
7464 * Get whether mobile data is enabled per user setting.
7465 *
7466 * There are other factors deciding whether mobile data is actually enabled, but they are
7467 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007468 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007469 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7470 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007471 *
7472 * @return {@code true} if data is enabled else {@code false}
7473 */
7474 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007475 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007476 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007477 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007478 try {
7479 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7480 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007481 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007482 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7483 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007484 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007486 mApp, subId, functionName);
7487
Robert Greenwalt646120a2014-05-23 11:54:03 -07007488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
Jack Yu285100e2022-12-02 22:48:35 -08007492 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7494 Phone phone = PhoneFactory.getPhone(phoneId);
7495 if (phone != null) {
7496 boolean retVal = phone.isUserDataEnabled();
7497 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7498 return retVal;
7499 } else {
7500 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7501 return false;
7502 }
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007505 }
7506 }
7507
7508 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007509 * Checks if the device is capable of mobile data by considering whether whether the
7510 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7511 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007512 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007513 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007514 */
7515 @Override
7516 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007517 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007518 try {
7519 try {
7520 mApp.enforceCallingOrSelfPermission(
7521 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007523 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007524 try {
7525 mApp.enforceCallingOrSelfPermission(
7526 android.Manifest.permission.READ_PHONE_STATE,
7527 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007528 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007529 mApp.enforceCallingOrSelfPermission(
7530 permission.READ_BASIC_PHONE_STATE, functionName);
7531 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007532 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007533 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007534 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536
joonhunshin4ac60942023-11-15 15:23:39 +00007537 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7538 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 final long identity = Binder.clearCallingIdentity();
7541 try {
Jack Yu285100e2022-12-02 22:48:35 -08007542 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007544 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007545 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007546 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 return retVal;
7548 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007549 if (DBG) {
7550 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7551 + subId + " retVal=false");
7552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return false;
7554 }
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007557 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007558 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007559
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007560 /**
7561 * Check if data is enabled for a specific reason
7562 * @param subId Subscription index
7563 * @param reason the reason the data enable change is taking place
7564 * @return {@code true} if the overall data is enabled; {@code false} if not.
7565 */
7566 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007567 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007568 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007569 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007570 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007571 try {
7572 mApp.enforceCallingOrSelfPermission(
7573 android.Manifest.permission.ACCESS_NETWORK_STATE,
7574 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007575 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007576 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7577 functionName);
7578 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007579 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007580 try {
7581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007582 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007583 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007585 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007586 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007587 }
7588
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007589 if (!mApp.getResources().getBoolean(
7590 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7592 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7593 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007594
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
Jack Yu285100e2022-12-02 22:48:35 -08007597 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007598 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007599 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 + " reason=" + reason);
7601 }
7602 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007603 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007604 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007605 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007606 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007607 return retVal;
7608 } else {
7609 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007610 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007611 + subId + " retVal=false");
7612 }
7613 return false;
7614 }
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
7619
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007620 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007621 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007622 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7623 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7624
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007625 // No permission needed; this only lets the caller inspect their own status.
7626 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007627 }
Junda Liu29340342014-07-10 15:23:27 -07007628
7629 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007630 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007631 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007632
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007633 if (!mApp.getResources().getBoolean(
7634 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7635 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7636 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7637 "getCarrierPrivilegeStatusForUid");
7638 }
joonhunshin4ac60942023-11-15 15:23:39 +00007639
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007640 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7641 }
7642
7643 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7644 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007645 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007646 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7648 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007649 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7650 if (cpt == null) {
7651 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007652 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7653 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007654 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007655 }
7656
7657 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007658 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007659 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007660
7661 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7662 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7663
chen xuf7e9fe82019-05-09 19:31:02 -07007664 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007665 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007666 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007667 Phone phone = getPhone(subId);
7668 if (phone == null) {
7669 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7670 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7671 }
7672 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7673 if (cpt == null) {
7674 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007675 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7676 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007677 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007678 }
7679
7680 @Override
7681 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007682 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007683
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007684 if (!mApp.getResources().getBoolean(
7685 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7687 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7688 "checkCarrierPrivilegesForPackageAnyPhone");
7689 }
joonhunshin4ac60942023-11-15 15:23:39 +00007690
Rambo Wange7209ce2022-02-23 13:41:02 -08007691 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7692 }
7693
7694 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007695 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007696 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007697 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007698 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007699 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7700 Phone phone = PhoneFactory.getPhone(phoneId);
7701 if (phone == null) {
7702 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007703 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007704 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7705 if (cpt == null) {
7706 continue;
7707 }
7708 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007709 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7710 break;
7711 }
7712 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007713 return result;
Junda Liu29340342014-07-10 15:23:27 -07007714 }
Derek Tan89e89d42014-07-08 17:00:10 -07007715
7716 @Override
Junda Liue64de782015-04-16 17:19:16 -07007717 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007718 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007719
7720 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7721 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7722 "getCarrierPackageNamesForIntentAndPhone");
7723
Rambo Wang8a247eb2022-02-08 21:11:18 +00007724 Phone phone = PhoneFactory.getPhone(phoneId);
7725 if (phone == null) {
7726 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007727 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007728 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7729 if (cpt == null) {
7730 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007731 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007732 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007733 }
7734
Amith Yamasani6e118872016-02-19 12:53:51 -08007735 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007736 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007737 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007738
7739 enforceTelephonyFeatureWithException(
7740 getCurrentPackageName(),
7741 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7742 "getPackagesWithCarrierPrivileges");
7743
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007744 Phone phone = PhoneFactory.getPhone(phoneId);
7745 if (phone == null) {
7746 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007747 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007748 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7749 if (cpt == null) {
7750 return Collections.emptyList();
7751 }
7752 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007753 }
7754
chen xuf7e9fe82019-05-09 19:31:02 -07007755 @Override
7756 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007757 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007758
7759 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7760 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7761 "getPackagesWithCarrierPrivilegesForAllPhones");
7762
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007763 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007764 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007765 try {
7766 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7767 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7768 }
7769 } finally {
7770 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007771 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007772 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007773 }
7774
Rambo Wang6812ffb2022-03-15 16:54:17 -07007775 @Override
7776 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7777 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7778
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007779 if (!mApp.getResources().getBoolean(
7780 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7782 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7783 "getCarrierServicePackageNameForLogicalSlot");
7784 }
joonhunshin4ac60942023-11-15 15:23:39 +00007785
Rambo Wang6812ffb2022-03-15 16:54:17 -07007786 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7787 if (phone == null) {
7788 return null;
7789 }
7790 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7791 if (cpt == null) {
7792 return null;
7793 }
7794 return cpt.getCarrierServicePackageName();
7795 }
7796
Wink Savilleb564aae2014-10-23 10:18:09 -07007797 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007798 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007799 UiccPort port = phone == null ? null : phone.getUiccPort();
7800 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007801 return null;
7802 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007803 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007804 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007805 return null;
7806 }
7807 return iccId;
7808 }
7809
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007810 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007811 public void setCallComposerStatus(int subId, int status) {
7812 enforceModifyPermission();
7813
joonhunshin4ac60942023-11-15 15:23:39 +00007814 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7815 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7816
Shuo Qiane4e11672020-12-15 22:15:33 -08007817 final long identity = Binder.clearCallingIdentity();
7818 try {
7819 Phone phone = getPhone(subId);
7820 if (phone != null) {
7821 Phone defaultPhone = phone.getImsPhone();
7822 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7823 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7824 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7826 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007827 }
7828 }
Shuo Qian284ae752020-12-22 19:10:14 -08007829 } catch (ImsException e) {
7830 throw new ServiceSpecificException(e.getCode());
7831 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007832 Binder.restoreCallingIdentity(identity);
7833 }
7834 }
7835
7836 @Override
7837 public int getCallComposerStatus(int subId) {
7838 enforceReadPrivilegedPermission("getCallComposerStatus");
7839
joonhunshin4ac60942023-11-15 15:23:39 +00007840 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7841 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7842
Shuo Qiane4e11672020-12-15 22:15:33 -08007843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 Phone phone = getPhone(subId);
7846 if (phone != null) {
7847 Phone defaultPhone = phone.getImsPhone();
7848 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7849 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7850 return imsPhone.getCallComposerStatus();
7851 }
7852 }
7853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
7856 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7857 }
7858
7859 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007860 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7861 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007862 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007863 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007864
joonhunshin4ac60942023-11-15 15:23:39 +00007865 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7866 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7867 "setLine1NumberForDisplayForSubscriber");
7868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 final String iccId = getIccId(subId);
7872 final Phone phone = getPhone(subId);
7873 if (phone == null) {
7874 return false;
7875 }
arunvoddub1365e62024-07-31 09:42:31 +00007876 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7877 Rlog.e(LOG_TAG, "Number is too long");
7878 return false;
7879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final String subscriberId = phone.getSubscriberId();
7881
7882 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007883 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 + subscriberId + " to " + number);
7885 }
7886
7887 if (TextUtils.isEmpty(iccId)) {
7888 return false;
7889 }
7890
7891 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7892
7893 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7894 if (alphaTag == null) {
7895 editor.remove(alphaTagPrefKey);
7896 } else {
7897 editor.putString(alphaTagPrefKey, alphaTag);
7898 }
7899
7900 // Record both the line number and IMSI for this ICCID, since we need to
7901 // track all merged IMSIs based on line number
7902 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7903 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7904 if (number == null) {
7905 editor.remove(numberPrefKey);
7906 editor.remove(subscriberPrefKey);
7907 } else {
7908 editor.putString(numberPrefKey, number);
7909 editor.putString(subscriberPrefKey, subscriberId);
7910 }
7911
7912 editor.commit();
7913 return true;
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007916 }
Derek Tan7226c842014-07-02 17:42:23 -07007917 }
7918
7919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007920 public String getLine1NumberForDisplay(int subId, String callingPackage,
7921 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007922 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007924 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007925 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007926 return null;
7927 }
Derek Tan97ebb422014-09-05 16:55:38 -07007928
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007929 if (!mApp.getResources().getBoolean(
7930 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7931 enforceTelephonyFeatureWithException(callingPackage,
7932 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7933 }
joonhunshin4ac60942023-11-15 15:23:39 +00007934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 String iccId = getIccId(subId);
7938 if (iccId != null) {
7939 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7940 if (DBG_MERGE) {
7941 log("getLine1NumberForDisplay returning "
7942 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7943 }
7944 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7947 return null;
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007950 }
Derek Tan7226c842014-07-02 17:42:23 -07007951 }
7952
7953 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007954 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7955 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007957 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007958 return null;
7959 }
Derek Tan97ebb422014-09-05 16:55:38 -07007960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 final long identity = Binder.clearCallingIdentity();
7962 try {
7963 String iccId = getIccId(subId);
7964 if (iccId != null) {
7965 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7966 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7967 }
7968 return null;
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007971 }
Derek Tan7226c842014-07-02 17:42:23 -07007972 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007973
7974 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007975 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7976 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007977 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7978 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007980 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007981 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007982 return null;
7983 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007984
Jordan Liub49b04b2019-05-06 14:45:15 -07007985 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7986 // the process, where TelephonyManager was instantiated.
7987 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007988 final long identity = Binder.clearCallingIdentity();
7989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007990 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 final TelephonyManager tele = TelephonyManager.from(context);
7992 final SubscriptionManager sub = SubscriptionManager.from(context);
7993
7994 // Figure out what subscribers are currently active
7995 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996
Jordan Liub49b04b2019-05-06 14:45:15 -07007997 // Only consider subs which match the current subId
7998 // This logic can be simplified. See b/131189269 for progress.
7999 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008000 activeSubscriberIds.add(tele.getSubscriberId(subId));
8001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002
8003 // First pass, find a number override for an active subscriber
8004 String mergeNumber = null;
8005 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8006 for (String key : prefs.keySet()) {
8007 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8008 final String subscriberId = (String) prefs.get(key);
8009 if (activeSubscriberIds.contains(subscriberId)) {
8010 final String iccId = key.substring(
8011 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8012 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8013 mergeNumber = (String) prefs.get(numberKey);
8014 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008015 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 + " for active subscriber " + subscriberId);
8017 }
8018 if (!TextUtils.isEmpty(mergeNumber)) {
8019 break;
8020 }
8021 }
8022 }
8023 }
8024
8025 // Shortcut when no active merged subscribers
8026 if (TextUtils.isEmpty(mergeNumber)) {
8027 return null;
8028 }
8029
8030 // Second pass, find all subscribers under that line override
8031 final ArraySet<String> result = new ArraySet<>();
8032 for (String key : prefs.keySet()) {
8033 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8034 final String number = (String) prefs.get(key);
8035 if (mergeNumber.equals(number)) {
8036 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8037 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8038 final String subscriberId = (String) prefs.get(subscriberKey);
8039 if (!TextUtils.isEmpty(subscriberId)) {
8040 result.add(subscriberId);
8041 }
8042 }
8043 }
8044 }
8045
8046 final String[] resultArray = result.toArray(new String[result.size()]);
8047 Arrays.sort(resultArray);
8048 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008049 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8051 }
8052 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008053 } finally {
8054 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008055 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008056 }
8057
8058 @Override
zoey chen38003472019-12-13 17:16:31 +08008059 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8060 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008061
joonhunshin4ac60942023-11-15 15:23:39 +00008062 enforceTelephonyFeatureWithException(callingPackage,
8063 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8064
Malcolm Chen6ca97372019-07-01 16:28:21 -07008065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 final TelephonyManager telephonyManager = mApp.getSystemService(
8068 TelephonyManager.class);
8069 String subscriberId = telephonyManager.getSubscriberId(subId);
8070 if (subscriberId == null) {
8071 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008072 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008073 + subId);
8074 }
8075 return null;
8076 }
8077
Jack Yu3beaf9d2023-04-14 09:17:27 -07008078 final SubscriptionInfo info = getSubscriptionManagerService()
8079 .getSubscriptionInfo(subId);
8080 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008081 // If it doesn't belong to any group, return just subscriberId of itself.
8082 if (groupUuid == null) {
8083 return new String[]{subscriberId};
8084 }
8085
8086 // Get all subscriberIds from the group.
8087 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008088 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8089 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8090 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008091 for (SubscriptionInfo subInfo : groupInfos) {
8092 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8093 if (subscriberId != null) {
8094 mergedSubscriberIds.add(subscriberId);
8095 }
8096 }
8097
8098 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101
8102 }
8103 }
8104
8105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008106 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008107 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008108 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109
joonhunshin4ac60942023-11-15 15:23:39 +00008110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8111 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 final Phone phone = getPhone(subId);
8116 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
8119 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008120 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008121
8122 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008123 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008124 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8125 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008126 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8127 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128
8129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 final Phone phone = getPhone(subId);
8132 if (phone == null) {
8133 return false;
8134 }
8135 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8136 cdmaNonRoamingList);
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008139 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008140 }
8141
8142 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008143 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008144 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008145 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008146 if (phone == null) {
8147 return raf;
8148 }
8149
Shuo Qiandee53402020-05-29 14:08:15 -07008150 try {
8151 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008152 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008153 mApp, phone.getSubId(), "getRadioAccessFamily");
8154 } catch (SecurityException e) {
8155 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8156 throw e;
8157 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008158
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008159 if (!mApp.getResources().getBoolean(
8160 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8161 enforceTelephonyFeatureWithException(callingPackage,
8162 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8163 }
joonhunshin4ac60942023-11-15 15:23:39 +00008164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 final long identity = Binder.clearCallingIdentity();
8166 try {
chen xub97461a2018-10-26 14:17:57 -07008167 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 } finally {
8169 Binder.restoreCallingIdentity(identity);
8170 }
chen xub97461a2018-10-26 14:17:57 -07008171 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008172 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008173
8174 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008175 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008176 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008177 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8178 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008179 enforceTelephonyFeatureWithException(callingPackage,
8180 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8181
Hall Liu82694d52020-12-11 18:22:04 -08008182 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008183 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008184 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8185 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008186 if (!dialerRoleHolders.contains(callingPackage)) {
8187 throw new SecurityException("App must be the dialer role holder to"
8188 + " upload a call composer pic");
8189 }
8190
8191 Executors.newSingleThreadExecutor().execute(() -> {
8192 ByteArrayOutputStream output = new ByteArrayOutputStream(
8193 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8194 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8195 boolean readUntilEnd = false;
8196 int totalBytesRead = 0;
8197 byte[] buffer = new byte[16 * 1024];
8198 while (true) {
8199 int numRead;
8200 try {
8201 numRead = input.read(buffer);
8202 } catch (IOException e) {
8203 try {
8204 fd.checkError();
8205 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8206 null);
8207 } catch (IOException e1) {
8208 // This means that the other side closed explicitly with an error. If this
8209 // happens, log and ignore.
8210 loge("Remote end of call composer picture pipe closed: " + e1);
8211 }
8212 break;
8213 }
8214 if (numRead == -1) {
8215 readUntilEnd = true;
8216 break;
8217 }
8218 totalBytesRead += numRead;
8219 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8220 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8221 try {
8222 input.close();
8223 } catch (IOException e) {
8224 // ignore
8225 }
8226 break;
8227 }
8228 output.write(buffer, 0, numRead);
8229 }
8230 // Generally, the remote end will close the file descriptors. The only case where we
8231 // close is above, where the picture size is too big.
8232
8233 try {
8234 fd.checkError();
8235 } catch (IOException e) {
8236 loge("Remote end for call composer closed with an error: " + e);
8237 return;
8238 }
8239
Hall Liuaa4211e2021-01-20 15:43:39 -08008240 if (!readUntilEnd) {
8241 loge("Did not finish reading entire image; aborting");
8242 return;
8243 }
Hall Liu82694d52020-12-11 18:22:04 -08008244
Hall Liuaa4211e2021-01-20 15:43:39 -08008245 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8246 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8247 new CallComposerPictureTransfer.Factory() {},
8248 imageData,
8249 (result) -> {
8250 if (result.first != null) {
8251 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8252 Bundle outputResult = new Bundle();
8253 outputResult.putParcelable(
8254 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8255 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8256 outputResult);
8257 } else {
8258 callback.send(result.second, null);
8259 }
8260 }
8261 );
Hall Liu82694d52020-12-11 18:22:04 -08008262 });
8263 }
8264
8265 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008266 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008267 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008268 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269
joonhunshin4ac60942023-11-15 15:23:39 +00008270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8271 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 final long identity = Binder.clearCallingIdentity();
8274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008275 ImsManager.getInstance(defaultPhone.getContext(),
8276 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008280 }
8281
8282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008284 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8286 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008287 return false;
8288 }
Svet Ganovb320e182015-04-16 12:30:10 -07008289
joonhunshin4ac60942023-11-15 15:23:39 +00008290 enforceTelephonyFeatureWithException(callingPackage,
8291 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 // Check the user preference and the system-level IMS setting. Even if the user has
8296 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8297 // In the long run, we may instead need to check if there exists a connection service
8298 // which can support video calling.
8299 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 return imsManager.isVtEnabledByPlatform()
8302 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8303 && imsManager.isVtEnabledByUser();
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008307 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008308
Andrew Leea1239f22015-03-02 17:44:07 -08008309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008310 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8311 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008313 mApp, subId, callingPackage, callingFeatureId,
8314 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 return false;
8316 }
8317
joonhunshin4ac60942023-11-15 15:23:39 +00008318 enforceTelephonyFeatureWithException(callingPackage,
8319 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 final long identity = Binder.clearCallingIdentity();
8322 try {
8323 CarrierConfigManager configManager =
8324 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008325 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
Andrew Leea1239f22015-03-02 17:44:07 -08008330 }
8331
8332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008333 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008335 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 return false;
8337 }
8338
joonhunshin4ac60942023-11-15 15:23:39 +00008339 enforceTelephonyFeatureWithException(callingPackage,
8340 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008342 final long identity = Binder.clearCallingIdentity();
8343 try {
8344 CarrierConfigManager configManager =
8345 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008346 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
Andrew Leea1239f22015-03-02 17:44:07 -08008351 }
8352
Andrew Lee9431b832015-03-09 18:46:45 -07008353 @Override
8354 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008355 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008356 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008357 }
8358
8359 @Override
8360 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8362 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364 final long identity = Binder.clearCallingIdentity();
8365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008366 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Andrew Lee9431b832015-03-09 18:46:45 -07008370 }
8371
Hall Liuf6668912018-10-31 17:05:23 -07008372 /**
8373 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8374 * support for the feature and device firmware support.
8375 *
8376 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8377 */
8378 @Override
8379 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8381 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008384 final Phone phone = getPhone(subscriptionId);
8385 if (phone == null) {
8386 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8387 return false;
8388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008390 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008392 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8393 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8394 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 return isCarrierSupported && isDeviceSupported;
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
Hall Liu98187582018-01-22 19:15:32 -08008399 }
8400
Hall Liuf6668912018-10-31 17:05:23 -07008401 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008402 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8403 * RTT setting, will return true if the device and carrier both support RTT.
8404 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008405 */
8406 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 final long identity = Binder.clearCallingIdentity();
8408 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008409 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8410 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8411 return false;
8412 }
8413 }
8414
Hall Liu5bab75c2019-12-11 23:58:20 +00008415 boolean isRttSupported = isRttSupported(subscriptionId);
8416 boolean isUserRttSettingOn = Settings.Secure.getInt(
8417 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8418 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8419 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8420 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008424 }
8425
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008426 @Deprecated
8427 @Override
8428 public String getDeviceId(String callingPackage) {
8429 return getDeviceIdWithFeature(callingPackage, null);
8430 }
8431
Sanket Padawe7310cc72015-01-14 09:53:20 -08008432 /**
8433 * Returns the unique device ID of phone, for example, the IMEI for
8434 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8435 *
8436 * <p>Requires Permission:
8437 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8438 */
8439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008441 try {
8442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8443 } catch (SecurityException se) {
8444 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8445 throw new SecurityException("Package " + callingPackage + " does not belong to "
8446 + Binder.getCallingUid());
8447 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008448 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008449 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008450 return null;
8451 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008452 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008453 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008454 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008455 return null;
8456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return phone.getDeviceId();
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008464 }
8465
Ping Sunc67b7c22016-03-02 19:16:45 +08008466 /**
8467 * {@hide}
8468 * Returns the IMS Registration Status on a particular subid
8469 *
8470 * @param subId
8471 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008472 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008473 Phone phone = getPhone(subId);
8474 if (phone != null) {
8475 return phone.isImsRegistered();
8476 } else {
8477 return false;
8478 }
8479 }
8480
Santos Cordon7a1885b2015-02-03 11:15:19 -08008481 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008482 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008483 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008485 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008486 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8487 }
8488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
8496 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008497 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008498 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008499 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008500 mApp,
8501 subscriptionId,
8502 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8503 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008504
8505 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8506 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8507
Tyler Gunnf70ed162019-04-03 15:28:53 -07008508 final long identity = Binder.clearCallingIdentity();
8509 try {
8510 Phone phone = getPhone(subscriptionId);
8511 if (phone == null) {
8512 return null;
8513 }
8514 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
8519
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008520 /**
8521 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008522 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008523 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 final long identity = Binder.clearCallingIdentity();
8525 try {
8526 Phone phone = getPhone(subId);
8527 if (phone != null) {
8528 return phone.isWifiCallingEnabled();
8529 } else {
8530 return false;
8531 }
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008534 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008535 }
8536
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008537 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008538 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008539 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008540 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 Phone phone = getPhone(subId);
8544 if (phone != null) {
8545 return phone.isVideoEnabled();
8546 } else {
8547 return false;
8548 }
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008551 }
8552 }
8553
8554 /**
8555 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8556 * defined in {@link ImsRegistrationImplBase}.
8557 */
8558 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 final long identity = Binder.clearCallingIdentity();
8560 try {
8561 Phone phone = getPhone(subId);
8562 if (phone != null) {
8563 return phone.getImsRegistrationTech();
8564 } else {
8565 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8566 }
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008569 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008570 }
8571
Stuart Scott8eef64f2015-04-08 15:13:54 -07008572 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008573 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008574 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008575
8576 enforceTelephonyFeatureWithException(callingPackage,
8577 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8578
Stuart Scott981d8582015-04-21 14:09:50 -07008579 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8580 return;
8581 }
Kai Shif70f46f2021-03-03 13:59:46 -08008582 Phone defaultPhone = getDefaultPhone();
8583 if (defaultPhone != null) {
8584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8585 mApp, getDefaultPhone().getSubId(), "factoryReset");
8586 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008587 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008588
Svet Ganovcc087f82015-05-12 20:35:54 -07008589 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008590 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8591 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008592 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008593 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008594 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008595 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008596 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008597 setDataRoamingEnabled(subId, phone == null ? false
8598 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008599 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008600 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008601 // There has been issues when Sms raw table somehow stores orphan
8602 // fragments. They lead to garbled message when new fragments come
8603 // in and combined with those stale ones. In case this happens again,
8604 // user can reset all network settings which will clean up this table.
8605 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008606 // Clean up IMS settings as well here.
8607 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008608 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008609 ImsManager.getInstance(mApp, slotId).factoryReset();
8610 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008611
Kai Shif70f46f2021-03-03 13:59:46 -08008612 if (defaultPhone == null) {
8613 return;
8614 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008615 // Erase modem config if erase modem on network setting is enabled.
8616 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8617 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8618 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008619 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008620 }
Kai Shif70f46f2021-03-03 13:59:46 -08008621
8622 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008623 } finally {
8624 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008625 }
8626 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008627
SongFerngWangfd89b102021-05-27 22:44:54 +08008628 @VisibleForTesting
8629 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8630 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8631 return;
8632 }
8633 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8634 RILConstants.PREFERRED_NETWORK_MODE);
8635 SubscriptionManager.setSubscriptionProperty(subId,
8636 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8637 "user=" + defaultNetworkType);
8638 phone.loadAllowedNetworksFromSubscriptionDatabase();
8639 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8640 defaultNetworkType, null);
8641 }
8642
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008643 private void cleanUpSmsRawTable(Context context) {
8644 ContentResolver resolver = context.getContentResolver();
8645 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8646 resolver.delete(uri, null, null);
8647 }
8648
Narayan Kamath1c496c22015-04-16 14:40:19 +01008649 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008650 public String getSimLocaleForSubscriber(int subId) {
8651 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008652
8653 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8654 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8655
chen xu5d3637b2019-01-21 23:31:38 -08008656 final Phone phone = getPhone(subId);
8657 if (phone == null) {
8658 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008659 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661 final long identity = Binder.clearCallingIdentity();
8662 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008663 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8664 phone.getContext().getOpPackageName(),
8665 phone.getContext().getAttributionTag());
8666 if (info == null) {
8667 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8668 return null;
chen xu6291c472019-02-04 12:55:53 -08008669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 // Try and fetch the locale from the carrier properties or from the SIM language
8671 // preferences (EF-PL and EF-LI)...
8672 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008674 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8675 if (localeFromDefaultSim != null) {
8676 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8677 if (DBG) log("Using locale from subId: " + subId + " locale: "
8678 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008679 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008680 } else {
8681 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008682 }
8683 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008685 // The SIM language preferences only store a language (e.g. fr = French), not an
8686 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8687 // the SIM and carrier preferences does not include a country we add the country
8688 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008689 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008691 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008692 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008693 }
8694
8695 if (DBG) log("No locale found - returning null");
8696 return null;
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008700 }
8701
tom hsu0b59d292022-09-29 23:49:21 +08008702 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008703 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008704 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008705 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008706 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008707 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8708 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008709 Locale.forLanguageTag(localeTag).getCountry())) {
8710 return localeTag;
8711 }
8712 }
8713 return inputLocale.toLanguageTag();
8714 }
8715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008716 /**
8717 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8718 */
8719 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008720 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008721 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008722 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008723
Gary Jian3aa9a762022-01-24 16:41:19 +08008724 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8725 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008726
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008727 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008728 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8729 * representing the state of the modem.
8730 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008731 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8732 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008733 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008734 */
8735 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008736 public void requestModemActivityInfo(ResultReceiver result) {
8737 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008738
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008739 if (!mApp.getResources().getBoolean(
8740 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8741 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8742 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8743 }
joonhunshin4ac60942023-11-15 15:23:39 +00008744
vagdeviaf9a5b92018-08-15 16:01:53 -07008745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008749 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 } finally {
8751 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008752 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008753 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008754
Gary Jian76280a42022-12-07 16:18:33 +08008755 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008756 // less than total activity duration.
8757 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8758 if (info == null) {
8759 return false;
8760 }
8761 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008762 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008763 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8764
Hall Liu49656c02020-10-09 19:00:11 -07008765 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8766
Siddharth Rayb8114062018-06-17 15:02:38 -07008767 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008768 && (info.getSleepTimeMillis() <= activityDurationMs)
8769 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008770 }
8771
Gary Jian3aa9a762022-01-24 16:41:19 +08008772 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8773 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8774 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8775 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8776
8777 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8778 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8779 }
8780
8781 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8782 mLastModemActivityInfo.setReceiveTimeMillis(
8783 rat,
8784 freq,
8785 info.getReceiveTimeMillis(rat, freq)
8786 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8787 }
8788
8789 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8790 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8791 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8792 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8793
8794 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8795 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8796 }
8797 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8798 mLastModemActivityInfo.setReceiveTimeMillis(
8799 rat,
8800 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8801 }
8802
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008803 /**
8804 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8805 * @param info recent ModemActivityInfo
8806 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008807 private void mergeModemActivityInfo(ModemActivityInfo info) {
8808 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008809 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008810 boolean matched;
8811 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8812 matched = false;
8813 int rat = info.getSpecificInfoRat(i);
8814 int freq = info.getSpecificInfoFrequencyRange(i);
8815 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8816 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8817 //if it already exists
8818 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8819 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8820 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8821 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8822 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8823 updateLastModemActivityInfo(info, rat, freq);
8824 matched = true;
8825 }
8826 } else {
8827 updateLastModemActivityInfo(info, rat);
8828 matched = true;
8829 }
8830 }
8831 }
8832
8833 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008834 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008835 new ActivityStatsTechSpecificInfo(
8836 rat,
8837 freq,
8838 info.getTransmitTimeMillis(rat, freq),
8839 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008840 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008841 }
8842 }
8843 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8844 mLastModemActivitySpecificInfo =
8845 new ActivityStatsTechSpecificInfo[merged.size()];
8846 merged.toArray(mLastModemActivitySpecificInfo);
8847
8848 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8849 mLastModemActivityInfo.setSleepTimeMillis(
8850 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008851 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008852 mLastModemActivityInfo.setIdleTimeMillis(
8853 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008854 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008855
8856 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008857 new ModemActivityInfo(
8858 mLastModemActivityInfo.getTimestampMillis(),
8859 mLastModemActivityInfo.getSleepTimeMillis(),
8860 mLastModemActivityInfo.getIdleTimeMillis(),
8861 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008862 }
8863
8864 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8865 ActivityStatsTechSpecificInfo[] info) {
8866 int infoSize = info.length;
8867 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8868 for (int i = 0; i < infoSize; i++) {
8869 ret[i] = new ActivityStatsTechSpecificInfo(
8870 info[i].getRat(), info[i].getFrequencyRange(),
8871 info[i].getTransmitTimeMillis(),
8872 (int) info[i].getReceiveTimeMillis());
8873 }
8874 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008875 }
8876
Jack Yu85bd38a2015-11-09 11:34:32 -08008877 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008878 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008879 */
8880 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008881 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8882 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8883 Phone phone = PhoneFactory.getPhone(slotIndex);
8884 if (phone == null) {
8885 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8886 return null;
8887 }
8888
8889 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008891 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008892 return null;
8893 }
8894
joonhunshin4ac60942023-11-15 15:23:39 +00008895 enforceTelephonyFeatureWithException(callingPackage,
8896 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8897
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008898 boolean hasFinePermission = false;
8899 boolean hasCoarsePermission = false;
8900 if (!renounceFineLocationAccess) {
8901 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8902 LocationAccessPolicy.checkLocationPermission(mApp,
8903 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8904 .setCallingPackage(callingPackage)
8905 .setCallingFeatureId(callingFeatureId)
8906 .setCallingPid(Binder.getCallingPid())
8907 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008908 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008909 .setLogAsInfo(true)
8910 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8911 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8912 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8913 .build());
8914 hasFinePermission =
8915 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8916 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008917
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008918 if (!renounceCoarseLocationAccess) {
8919 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8920 LocationAccessPolicy.checkLocationPermission(mApp,
8921 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8922 .setCallingPackage(callingPackage)
8923 .setCallingFeatureId(callingFeatureId)
8924 .setCallingPid(Binder.getCallingPid())
8925 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008926 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008927 .setLogAsInfo(true)
8928 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8929 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8930 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8931 .build());
8932 hasCoarsePermission =
8933 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8934 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008935
Jordan Liu0f2bc442020-11-18 16:47:37 -08008936 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008938 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8939 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008940 if (subInfo != null && !subInfo.isActive()) {
8941 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008942 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008943 }
8944
Hall Liuf19c44f2018-11-27 14:38:17 -08008945 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008946 boolean isCallingPackageDataService = phone.getDataServicePackages()
8947 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008948
8949 // Scrub out the location info in ServiceState depending on what level of access
8950 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008951 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008952 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8953 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008957 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008958
8959 /**
8960 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8961 *
8962 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8963 * voicemail ringtone.
8964 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8965 * PhoneAccount.
8966 */
8967 @Override
8968 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8970 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972 final long identity = Binder.clearCallingIdentity();
8973 try {
8974 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8975 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008976 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008983 }
8984
8985 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008986 * Sets the per-account voicemail ringtone.
8987 *
8988 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8989 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8990 *
8991 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8992 * voicemail ringtone.
8993 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8994 * PhoneAccount.
8995 */
8996 @Override
8997 public void setVoicemailRingtoneUri(String callingPackage,
8998 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008999 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009001 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9002 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9004 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9005 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007
joonhunshin4ac60942023-11-15 15:23:39 +00009008 enforceTelephonyFeatureWithException(callingPackage,
9009 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009011 final long identity = Binder.clearCallingIdentity();
9012 try {
9013 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9014 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009015 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016 }
9017 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9018 } finally {
9019 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009020 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009021 }
9022
9023 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009024 * Returns whether vibration is set for voicemail notification in Phone settings.
9025 *
9026 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9027 * voicemail vibration setting.
9028 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9029 */
9030 @Override
9031 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9033 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9038 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009039 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9043 } finally {
9044 Binder.restoreCallingIdentity(identity);
9045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009046 }
9047
Youhan Wange64578a2016-05-02 15:32:42 -07009048 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009049 * Sets the per-account voicemail vibration.
9050 *
9051 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9052 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9053 *
9054 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9055 * voicemail vibration setting.
9056 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9057 * specific PhoneAccount.
9058 */
9059 @Override
9060 public void setVoicemailVibrationEnabled(String callingPackage,
9061 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009062 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009064 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9065 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9067 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9068 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009069 }
9070
joonhunshin4ac60942023-11-15 15:23:39 +00009071 enforceTelephonyFeatureWithException(callingPackage,
9072 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 final long identity = Binder.clearCallingIdentity();
9075 try {
9076 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9077 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009078 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 }
9080 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009083 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009084 }
9085
9086 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009087 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9088 *
9089 * @throws SecurityException if the caller does not have the required permission
9090 */
arunvoddud7401012022-12-15 16:08:12 +00009091 @VisibleForTesting
9092 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009093 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009094 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009095 }
9096
9097 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009098 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9099 * permission.
9100 *
9101 * @throws SecurityException if the caller does not have the required permission
9102 */
9103 private void enforceSendSmsPermission() {
9104 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9105 }
9106
9107 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009108 * Make sure either called from same process as self (phone) or IPC caller has interact across
9109 * users permission.
9110 *
9111 * @throws SecurityException if the caller does not have the required permission
9112 */
9113 private void enforceInteractAcrossUsersPermission(String message) {
9114 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9115 }
9116
9117 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009118 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009119 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009120 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009121 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009122 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123 final long identity = Binder.clearCallingIdentity();
9124 try {
9125 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009126 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009127 if (componentName == null) {
9128 throw new SecurityException(
9129 "Caller not current active visual voicemail package[null]");
9130 }
9131 String vvmPackage = componentName.getPackageName();
9132 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009133 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 }
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009137 }
9138 }
9139
9140 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009141 * Return the application ID for the app type.
9142 *
9143 * @param subId the subscription ID that this request applies to.
9144 * @param appType the uicc app type.
9145 * @return Application ID for specificied app type, or null if no uicc.
9146 */
9147 @Override
9148 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009149 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009150
9151 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9152 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9153
Youhan Wange64578a2016-05-02 15:32:42 -07009154 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155
9156 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009157 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009158 if (phone == null) {
9159 return null;
9160 }
9161 String aid = null;
9162 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009163 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009164 .getApplicationByType(appType).getAid();
9165 } catch (Exception e) {
9166 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9167 }
9168 return aid;
9169 } finally {
9170 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009171 }
Youhan Wange64578a2016-05-02 15:32:42 -07009172 }
9173
Youhan Wang4001d252016-05-11 10:29:41 -07009174 /**
9175 * Return the Electronic Serial Number.
9176 *
9177 * @param subId the subscription ID that this request applies to.
9178 * @return ESN or null if error.
9179 */
9180 @Override
9181 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009182 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009183 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009184
9185 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009186 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187 if (phone == null) {
9188 return null;
9189 }
9190 String esn = null;
9191 try {
9192 esn = phone.getEsn();
9193 } catch (Exception e) {
9194 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9195 }
9196 return esn;
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009199 }
Youhan Wang4001d252016-05-11 10:29:41 -07009200 }
9201
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009202 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009203 * Return the Preferred Roaming List Version.
9204 *
9205 * @param subId the subscription ID that this request applies to.
9206 * @return PRLVersion or null if error.
9207 */
9208 @Override
9209 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009210 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009211
9212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9213 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9214
Youhan Wang66ad5d72016-07-18 17:56:58 -07009215 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009216
9217 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009218 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009219 if (phone == null) {
9220 return null;
9221 }
9222 String cdmaPrlVersion = null;
9223 try {
9224 cdmaPrlVersion = phone.getCdmaPrlVersion();
9225 } catch (Exception e) {
9226 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9227 }
9228 return cdmaPrlVersion;
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009231 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009232 }
9233
9234 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009235 * Get snapshot of Telephony histograms
9236 * @return List of Telephony histograms
9237 * @hide
9238 */
9239 @Override
9240 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9242 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009243
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 return RIL.getTelephonyRILTimingHistograms();
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009250 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009251
9252 /**
9253 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009254 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9255 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009256 * Require system privileges. In the future we may add this to carrier APIs.
9257 *
Michele Berionne482f8202018-11-27 18:57:59 -08009258 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009259 */
9260 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009261 @TelephonyManager.SetCarrierRestrictionResult
9262 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009263 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009264
9265 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9266 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9267
vagdeviaf9a5b92018-08-15 16:01:53 -07009268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009269
Michele Berionne482f8202018-11-27 18:57:59 -08009270 if (carrierRestrictionRules == null) {
9271 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009272 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009274 final long identity = Binder.clearCallingIdentity();
9275 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009276 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009277 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009278 } finally {
9279 Binder.restoreCallingIdentity(identity);
9280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009281 }
9282
9283 /**
9284 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009285 * Get the allowed carrier list and the excluded carrier list, including the priority between
9286 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009287 * Require system privileges. In the future we may add this to carrier APIs.
9288 *
Michele Berionne482f8202018-11-27 18:57:59 -08009289 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009290 */
9291 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009292 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009293 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009294
9295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9296 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9297
vagdeviaf9a5b92018-08-15 16:01:53 -07009298 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009299
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009302 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9303 if (response instanceof CarrierRestrictionRules) {
9304 return (CarrierRestrictionRules) response;
9305 }
9306 // Response is an Exception of some kind,
9307 // which is signalled to the user as a NULL retval
9308 return null;
9309 } catch (Exception e) {
9310 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9311 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009312 } finally {
9313 Binder.restoreCallingIdentity(identity);
9314 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009315 }
9316
fionaxu59545b42016-05-25 15:53:37 -07009317 /**
arunvoddud7401012022-12-15 16:08:12 +00009318 * Fetches the carrier restriction status of the device and sends the status to the caller
9319 * through the callback.
9320 *
9321 * @param callback The callback that will be used to send the result.
9322 * @throws SecurityException if the caller does not have the required permission/privileges or
9323 * the caller is not allowlisted.
9324 */
9325 @Override
9326 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009327 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009328 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009329 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9330 try {
9331 mApp.enforceCallingOrSelfPermission(
9332 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9333 functionName);
9334 } catch (SecurityException e) {
9335 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9336 functionName);
9337 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009338 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9339 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009340 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9341 throw new SecurityException("Not an authorized caller");
9342 }
9343 final long identity = Binder.clearCallingIdentity();
9344 try {
9345 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009346 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009347 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
arunvoddu567f2b42023-04-25 17:22:00 +00009353 @Override
9354 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9355 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9356 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9357 return allowListInfo.getShaIdList(pkgName, carrierId);
9358 }
9359
arunvoddud7401012022-12-15 16:08:12 +00009360 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009361 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009362 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009363 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009364 }
9365
9366 /**
fionaxu59545b42016-05-25 15:53:37 -07009367 * Action set from carrier signalling broadcast receivers to enable/disable radio
9368 * @param subId the subscription ID that this action applies to.
9369 * @param enabled control enable or disable radio.
9370 * {@hide}
9371 */
9372 @Override
9373 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9374 enforceModifyPermission();
9375 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009376
9377 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009378 if (phone == null) {
9379 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9380 return;
9381 }
9382 try {
9383 phone.carrierActionSetRadioEnabled(enabled);
9384 } catch (Exception e) {
9385 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009386 } finally {
9387 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009388 }
9389 }
9390
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009391 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009392 * Enable or disable Voice over NR (VoNR)
9393 * @param subId the subscription ID that this action applies to.
9394 * @param enabled enable or disable VoNR.
9395 * @return operation result.
9396 */
9397 @Override
9398 public int setVoNrEnabled(int subId, boolean enabled) {
9399 enforceModifyPermission();
9400 final Phone phone = getPhone(subId);
9401
9402 final long identity = Binder.clearCallingIdentity();
9403 if (phone == null) {
9404 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9405 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9406 }
9407
9408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9409 try {
9410 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9411 workSource);
9412 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009413
9414 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9415 if (DBG) {
9416 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9417 }
9418 SubscriptionManager.setSubscriptionProperty(
9419 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9420 (enabled ? "1" : "0"));
9421 }
9422
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009423 return result;
9424 } finally {
9425 Binder.restoreCallingIdentity(identity);
9426 }
9427 }
9428
9429 /**
9430 * Is voice over NR enabled
9431 * @return true if VoNR is enabled else false
9432 */
9433 @Override
9434 public boolean isVoNrEnabled(int subId) {
9435 enforceReadPrivilegedPermission("isVoNrEnabled");
9436 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
9439 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9440 null, subId, workSource);
9441 if (DBG) log("isVoNrEnabled: " + isEnabled);
9442 return isEnabled;
9443 } finally {
9444 Binder.restoreCallingIdentity(identity);
9445 }
9446 }
9447
9448 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009449 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9450 * network status based on which carrier apps could apply actions accordingly,
9451 * enable/disable default url handler for example.
9452 *
9453 * @param subId the subscription ID that this action applies to.
9454 * @param report control start/stop reporting the default network status.
9455 * {@hide}
9456 */
9457 @Override
9458 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9459 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009460
9461 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9462 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9463 "carrierActionReportDefaultNetworkStatus");
9464
fionaxu8da9cb12017-05-23 15:02:46 -07009465 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009466
9467 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009468 if (phone == null) {
9469 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9470 return;
9471 }
9472 try {
9473 phone.carrierActionReportDefaultNetworkStatus(report);
9474 } catch (Exception e) {
9475 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009476 } finally {
9477 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009478 }
9479 }
9480
9481 /**
fionaxud9622282017-07-17 17:51:30 -07009482 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9483 * @param subId the subscription ID that this action applies to.
9484 * {@hide}
9485 */
9486 @Override
9487 public void carrierActionResetAll(int subId) {
9488 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009489
9490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9491 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9492
fionaxud9622282017-07-17 17:51:30 -07009493 final Phone phone = getPhone(subId);
9494 if (phone == null) {
9495 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9496 return;
9497 }
9498 try {
9499 phone.carrierActionResetAll();
9500 } catch (Exception e) {
9501 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9502 }
9503 }
9504
9505 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009506 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9507 * bug report is being generated.
9508 */
9509 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009510 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009511 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9512 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009513 writer.println("Permission Denial: can't dump Phone from pid="
9514 + Binder.getCallingPid()
9515 + ", uid=" + Binder.getCallingUid()
9516 + "without permission "
9517 + android.Manifest.permission.DUMP);
9518 return;
9519 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009520 try {
9521 DumpsysHandler.dump(mApp, fd, writer, args);
9522 } catch (Exception e) {
9523 writer.println("Failed to dump phone information: " + e);
9524 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009525 }
Jack Yueb89b242016-06-22 13:27:47 -07009526
Brad Ebingerdac2f002018-04-03 15:17:52 -07009527 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009528 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9529 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9530 @NonNull String[] args) {
9531 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9532 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009533 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009534 }
9535
Jack Yueb89b242016-06-22 13:27:47 -07009536 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009537 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009538 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009539 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009540 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009541 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009542 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009543 */
9544 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009545 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009546 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009547 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9548 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9549 try {
9550 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009551 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009552 } catch (SecurityException se) {
9553 enforceModifyPermission();
9554 }
9555 } else {
9556 enforceModifyPermission();
9557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009558
joonhunshin4ac60942023-11-15 15:23:39 +00009559 enforceTelephonyFeatureWithException(callingPackage,
9560 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9561
Nate Myren116695d2024-02-09 09:36:01 -08009562 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009563 final long identity = Binder.clearCallingIdentity();
9564 try {
Nate Myren116695d2024-02-09 09:36:01 -08009565 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9566 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009567 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009568 callingUid, callingPackage, null, null);
9569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009570 Phone phone = getPhone(subId);
9571 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009572 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9573 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009574 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009575 phone.getDataSettingsManager().setDataEnabled(
9576 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009578 }
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009581 }
9582 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009583
9584 /**
9585 * Get Client request stats
9586 * @return List of Client Request Stats
9587 * @hide
9588 */
9589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009590 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9591 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009593 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009594 return null;
9595 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009596 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009598 final long identity = Binder.clearCallingIdentity();
9599 try {
9600 if (phone != null) {
9601 return phone.getClientRequestStats();
9602 }
9603
9604 return null;
9605 } finally {
9606 Binder.restoreCallingIdentity(identity);
9607 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009608 }
9609
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009610 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009611 PackageManager pm;
9612 if (mFeatureFlags.hsumPackageManager()) {
9613 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9614 .getPackageManager();
9615 } else {
9616 pm = mApp.getPackageManager();
9617 }
9618
9619 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009620 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009621 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9622 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9623 // exception. ROOT_UID seems not to have a valid package name returned by
9624 // PackageManager, so just fake it here to avoid issues when running telephony shell
9625 // commands that plumb through the RIL as root, like so:
9626 // $ adb root
9627 // $ adb shell cmd phone ...
9628 packageName = "root";
9629 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009630 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009631 }
Jack Yueb4124c2017-02-16 15:32:43 -08009632
9633 /**
Grace Chen70990072017-03-24 17:21:30 -07009634 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009635 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009636 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009637 * @param state State of SIM (power down, power up, pass through)
9638 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9639 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9640 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009641 *
9642 **/
9643 @Override
Grace Chen70990072017-03-24 17:21:30 -07009644 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009645 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009646
9647 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9648 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9649
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009650 Phone phone = PhoneFactory.getPhone(slotIndex);
9651
vagdeviaf9a5b92018-08-15 16:01:53 -07009652 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009654 final long identity = Binder.clearCallingIdentity();
9655 try {
9656 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009657 phone.setSimPowerState(state, null, workSource);
9658 }
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
9661 }
9662 }
9663
9664 /**
9665 * Set SIM card power state.
9666 *
9667 * @param slotIndex SIM slot id.
9668 * @param state State of SIM (power down, power up, pass through)
9669 * @param callback callback to trigger after success or failure
9670 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9671 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9672 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9673 *
9674 **/
9675 @Override
9676 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9677 IIntegerConsumer callback) {
9678 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009679
9680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9681 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9682 "setSimPowerStateForSlotWithCallback");
9683
Jordan Liu109698e2020-11-24 14:50:34 -08009684 Phone phone = PhoneFactory.getPhone(slotIndex);
9685
9686 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9687
9688 final long identity = Binder.clearCallingIdentity();
9689 try {
9690 if (phone != null) {
9691 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9692 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009693 }
9694 } finally {
9695 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009696 }
9697 }
Shuo Qiandd210312017-04-12 22:11:33 +00009698
Tyler Gunn65d45c22017-06-05 11:22:26 -07009699 private boolean isUssdApiAllowed(int subId) {
9700 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009701 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009702 if (configManager == null) {
9703 return false;
9704 }
9705 PersistableBundle pb = configManager.getConfigForSubId(subId);
9706 if (pb == null) {
9707 return false;
9708 }
9709 return pb.getBoolean(
9710 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9711 }
9712
Shuo Qiandd210312017-04-12 22:11:33 +00009713 /**
Ling Mac28f0212023-03-24 16:07:15 -07009714 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009715 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009716 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009717 */
goneil9c5f4872017-12-05 14:07:56 -08009718 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009719 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009720 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009721
9722 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9723 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009725 final long identity = Binder.clearCallingIdentity();
9726 try {
Ling Mac28f0212023-03-24 16:07:15 -07009727 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009728 } finally {
9729 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009730 }
9731 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009732
9733 /**
9734 * Get the current signal strength information for the given subscription.
9735 * Because this information is not updated when the device is in a low power state
9736 * it should not be relied-upon to be current.
9737 * @param subId Subscription index
9738 * @return the most recent cached signal strength info from the modem
9739 */
9740 @Override
9741 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9743 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 Phone p = getPhone(subId);
9748 if (p == null) {
9749 return null;
9750 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009752 return p.getSignalStrength();
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009756 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009757
Pengquan Meng77b7f132018-08-22 14:49:57 -07009758 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009759 * Get the current modem radio state for the given slot.
9760 * @param slotIndex slot index.
9761 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009762 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009763 * @return the current radio power state from the modem
9764 */
9765 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009766 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009767 Phone phone = PhoneFactory.getPhone(slotIndex);
9768 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9770 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009771 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9772 }
9773
joonhunshin4ac60942023-11-15 15:23:39 +00009774 enforceTelephonyFeatureWithException(callingPackage,
9775 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9776
Chen Xuf792fd62018-10-17 17:54:36 +00009777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 return phone.getRadioPowerState();
9780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 }
9784 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9785 }
9786
9787 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009788 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9789 *
9790 * <p>Requires one of the following permissions:
9791 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009792 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009793 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9794 * privileges.
9795 *
9796 * @param subId subscription id
9797 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9798 * {@code false}.
9799 */
9800 @Override
9801 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009802 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009803 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009804 try {
9805 mApp.enforceCallingOrSelfPermission(
9806 android.Manifest.permission.ACCESS_NETWORK_STATE,
9807 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009808 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009809 mApp.enforceCallingOrSelfPermission(
9810 permission.READ_BASIC_PHONE_STATE, functionName);
9811 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009812 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009813 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009814 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009815 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009816
joonhunshin4ac60942023-11-15 15:23:39 +00009817 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9818 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9819
Pengquan Menga1bb6272018-09-06 09:59:22 -07009820 boolean isEnabled = false;
9821 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009822 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009823 Phone phone = getPhone(subId);
9824 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009825 } finally {
9826 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009827 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009828 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009829 }
9830
9831
9832 /**
9833 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9834 *
9835 * <p> Requires permission:
9836 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9837 * privileges.
9838 *
9839 * @param subId subscription id
9840 * @param isEnabled {@code true} means enable, {@code false} means disable.
9841 */
9842 @Override
9843 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9845 mApp, subId, "setDataRoamingEnabled");
9846
joonhunshin4ac60942023-11-15 15:23:39 +00009847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9848 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9849
Pengquan Menga1bb6272018-09-06 09:59:22 -07009850 final long identity = Binder.clearCallingIdentity();
9851 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009852 Phone phone = getPhone(subId);
9853 if (phone != null) {
9854 phone.setDataRoamingEnabled(isEnabled);
9855 }
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009858 }
9859 }
9860
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009861 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009862 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009863 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009864 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009865 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009866
joonhunshin4ac60942023-11-15 15:23:39 +00009867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9868 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9869
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009870 boolean isAllowed = true;
9871 final long identity = Binder.clearCallingIdentity();
9872 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009873 Phone phone = getPhone(subId);
9874 if (phone != null) {
9875 isAllowed = phone.isCspPlmnEnabled();
9876 }
9877 } finally {
9878 Binder.restoreCallingIdentity(identity);
9879 }
9880 return isAllowed;
9881 }
9882
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009883 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9884 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009885 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009886 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009887 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009888 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9889 if (phone == null) {
9890 return false;
9891 }
9892 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9893 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9894 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009895 }
9896
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009897 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009898 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009899 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009900 mApp.getSystemService(AppOpsManager.class)
9901 .checkPackage(Binder.getCallingUid(), callingPackage);
9902
Jordan Liu1e142fc2019-04-22 15:10:43 -07009903 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009904 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009905 try {
9906 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009907 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009908 } catch (SecurityException e) {
9909 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9910 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009911 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009912 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009913 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009914 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009915 }
joonhunshin4ac60942023-11-15 15:23:39 +00009916
9917 enforceTelephonyFeatureWithException(callingPackage,
9918 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9919
sandeepjsb6c87872021-09-27 15:34:44 +00009920 // checking compatibility, if calling app's target SDK is T and beyond.
9921 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9922 Binder.getCallingUid())) {
9923 isIccIdAccessRestricted = true;
9924 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009925 final long identity = Binder.clearCallingIdentity();
9926 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009927 UiccController uiccController = UiccController.getInstance();
9928 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009929 if (hasReadPermission) {
9930 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009931 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009932
9933 // Remove private info if the caller doesn't have access
9934 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9935 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009936 //setting the value after compatibility check
9937 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009938 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9939 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009940 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009941 if (card == null) {
9942 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009943 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009944 continue;
9945 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009946 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9947 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009948 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009949 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009950 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009951 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9952 for (UiccPortInfo portInfo : portInfos) {
9953 UiccPort port = uiccController.getUiccPortForSlot(
9954 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9955 if (port == null) {
9956 // assume no access if port is null
9957 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9958 continue;
9959 }
9960 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9961 uiccPortInfos.add(portInfo);
9962 } else {
9963 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9964 }
9965 }
9966 filteredInfos.add(new UiccCardInfo(
9967 cardInfo.isEuicc(),
9968 cardInfo.getCardId(),
9969 null,
9970 cardInfo.getPhysicalSlotIndex(),
9971 cardInfo.isRemovable(),
9972 cardInfo.isMultipleEnabledProfilesSupported(),
9973 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009974 }
9975 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
sandeepjsb6c87872021-09-27 15:34:44 +00009981 /**
9982 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9983 * generally private and require carrier privileges to view.
9984 *
9985 * @hide
9986 */
9987 @NonNull
9988 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9989 List<UiccPortInfo> portinfo = new ArrayList<>();
9990 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9991 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9992 }
9993 return new UiccCardInfo(
9994 cardInfo.isEuicc(),
9995 cardInfo.getCardId(),
9996 null,
9997 cardInfo.getPhysicalSlotIndex(),
9998 cardInfo.isRemovable(),
9999 cardInfo.isMultipleEnabledProfilesSupported(),
10000 portinfo
10001 );
10002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010003
sandeepjsb6c87872021-09-27 15:34:44 +000010004 /**
10005 * @hide
10006 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10007 * These values are generally private and require carrier privileges to view.
10008 */
10009 @NonNull
10010 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10011 return new UiccPortInfo(
10012 UiccPortInfo.ICCID_REDACTED,
10013 portInfo.getPortIndex(),
10014 portInfo.getLogicalSlotIndex(),
10015 portInfo.isActive()
10016 );
10017 }
10018 @Override
10019 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010020 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010021 mApp.getSystemService(AppOpsManager.class)
10022 .checkPackage(Binder.getCallingUid(), callingPackage);
10023
sandeepjsb6c87872021-09-27 15:34:44 +000010024 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010025
Aman Guptaf3c90b32022-03-17 04:54:16 +000010026 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10027 // we are reading iccId which is PII data.
10028 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010029
joonhunshin4ac60942023-11-15 15:23:39 +000010030 enforceTelephonyFeatureWithException(callingPackage,
10031 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10032
sandeepjsb6c87872021-09-27 15:34:44 +000010033 // checking compatibility, if calling app's target SDK is T and beyond.
10034 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10035 Binder.getCallingUid())) {
10036 isLogicalSlotAccessRestricted = true;
10037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010038 final long identity = Binder.clearCallingIdentity();
10039 try {
10040 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010041 if (slots == null || slots.length == 0) {
10042 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010043 return null;
10044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010045 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10046 for (int i = 0; i < slots.length; i++) {
10047 UiccSlot slot = slots[i];
10048 if (slot == null) {
10049 continue;
10050 }
10051
Jordan Liu7be7e652019-05-06 18:55:02 +000010052 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010053 UiccCard card = slot.getUiccCard();
10054 if (card != null) {
10055 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010056 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010057 cardId = slot.getEid();
10058 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010059 // If cardId is null, use iccId of default port as cardId.
10060 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010062 }
10063
Jordan Liu857451f2019-05-09 16:35:35 -070010064 if (cardId != null) {
10065 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10066 // if cardId is an EID, it's all digits so this is fine
10067 cardId = IccUtils.stripTrailingFs(cardId);
10068 }
10069
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010070 int cardState = 0;
10071 switch (slot.getCardState()) {
10072 case CARDSTATE_ABSENT:
10073 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10074 break;
10075 case CARDSTATE_PRESENT:
10076 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10077 break;
10078 case CARDSTATE_ERROR:
10079 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10080 break;
10081 case CARDSTATE_RESTRICTED:
10082 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10083 break;
10084 default:
10085 break;
10086
10087 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010088 List<UiccPortInfo> portInfos = new ArrayList<>();
10089 int[] portIndexes = slot.getPortList();
10090 for (int portIdx : portIndexes) {
10091 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010092 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010093 portInfos.add(new UiccPortInfo(iccId, portIdx,
10094 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010096 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010097 slot.isEuicc(),
10098 cardId,
10099 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010100 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010101 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010102 //setting the value after compatibility check
10103 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010104 }
10105 return infos;
10106 } finally {
10107 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010108 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010109 }
10110
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010111 /* Returns null if doesn't have read permission or carrier privilege access. */
10112 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10113 boolean hasReadPermission) {
10114 String iccId = slot.getIccId(portIndex);
10115 if (hasReadPermission) { // if has read permission
10116 return iccId;
10117 } else {
10118 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10119 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10120 // if no read permission, checking carrier privilege access
10121 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10122 return iccId;
10123 }
10124 }
10125 }
10126 // No read permission or carrier privilege access.
10127 return UiccPortInfo.ICCID_REDACTED;
10128 }
10129
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010130 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010131 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010132 public boolean switchSlots(int[] physicalSlots) {
10133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010134
joonhunshin4ac60942023-11-15 15:23:39 +000010135 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10136 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10137
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010138 final long identity = Binder.clearCallingIdentity();
10139 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010140 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10141 for (int i = 0; i < physicalSlots.length; i++) {
10142 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10143 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10144 physicalSlots[i], i));
10145 }
10146 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010147 } finally {
10148 Binder.restoreCallingIdentity(identity);
10149 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010150 }
Jack Yu4c988042018-02-27 15:30:01 -080010151
10152 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010153 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10154 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10155 enforceModifyPermission();
10156
joonhunshin4ac60942023-11-15 15:23:39 +000010157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10158 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10159
sandeepjsb6c87872021-09-27 15:34:44 +000010160 final long identity = Binder.clearCallingIdentity();
10161 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010162 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 }
10167
10168 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010169 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010170 enforceTelephonyFeatureWithException(callingPackage,
10171 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10172
Jordan Liu7de49fa2018-12-06 14:48:49 -080010173 final long identity = Binder.clearCallingIdentity();
10174 try {
10175 return UiccController.getInstance().getCardIdForDefaultEuicc();
10176 } finally {
10177 Binder.restoreCallingIdentity(identity);
10178 }
10179 }
10180
Pengquan Meng85728fb2018-03-12 16:31:21 -070010181 /**
goneil47ffb6e2018-04-06 15:40:58 -070010182 * A test API to reload the UICC profile.
10183 *
10184 * <p>Requires that the calling app has permission
10185 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10186 * @hide
10187 */
10188 @Override
10189 public void refreshUiccProfile(int subId) {
10190 enforceModifyPermission();
10191
10192 final long identity = Binder.clearCallingIdentity();
10193 try {
10194 Phone phone = getPhone(subId);
10195 if (phone == null) {
10196 return;
10197 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010198 UiccPort uiccPort = phone.getUiccPort();
10199 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010200 return;
10201 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010202 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010203 if (uiccProfile == null) {
10204 return;
10205 }
10206 uiccProfile.refresh();
10207 } finally {
10208 Binder.restoreCallingIdentity(identity);
10209 }
10210 }
10211
10212 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010213 * Returns false if the mobile data is disabled by default, otherwise return true.
10214 */
10215 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010216 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010217 }
10218
10219 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010220 * Returns the default network type for the given {@code subId}, if the default network type is
10221 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10222 */
10223 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010224 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010225 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010226 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10227 return list.get(phoneId);
10228 }
10229 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010230 }
fionaxua13278b2018-03-21 00:08:13 -070010231
10232 @Override
10233 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010234 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010235 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010236
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 final Phone phone = getPhone(subId);
10240 if (phone == null) {
10241 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10242 return;
10243 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010244 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10245 if (cpt != null) {
10246 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10247 }
10248 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010249 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10250 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010251 if (carrierPrivilegeRules == null) {
10252 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10253 } else {
10254 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010256 } finally {
10257 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010258 }
fionaxua13278b2018-03-21 00:08:13 -070010259 }
10260
10261 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010262 public void setCarrierServicePackageOverride(
10263 int subId, String carrierServicePackage, String callingPackage) {
10264 TelephonyPermissions.enforceShellOnly(
10265 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10266
Benedict Wong66477622023-02-03 23:30:57 +000010267 final long identity = Binder.clearCallingIdentity();
10268 try {
10269 final Phone phone = getPhone(subId);
10270 if (phone == null || phone.getSubId() != subId) {
10271 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10272 throw new IllegalArgumentException("No phone for subid");
10273 }
10274 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10275 if (cpt == null) {
10276 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10277 throw new IllegalStateException("No CPT for phone");
10278 }
10279 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10280 } finally {
10281 Binder.restoreCallingIdentity(identity);
10282 }
10283 }
10284
10285 @Override
fionaxua13278b2018-03-21 00:08:13 -070010286 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010287 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010288
10289 final long identity = Binder.clearCallingIdentity();
10290 try {
10291 final Phone phone = getPhone(subId);
10292 if (phone == null) {
10293 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10294 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10295 }
10296 return phone.getCarrierIdListVersion();
10297 } finally {
10298 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010299 }
fionaxua13278b2018-03-21 00:08:13 -070010300 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010301
10302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010303 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10304 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010306 mApp, subId, callingPackage, callingFeatureId,
10307 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010308 return -1;
10309 }
10310
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010318
10319 @Override
10320 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010321 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010322 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010323 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010324
joonhunshin4ac60942023-11-15 15:23:39 +000010325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10326 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10327
Pengquan Menga1bb6272018-09-06 09:59:22 -070010328 final long identity = Binder.clearCallingIdentity();
10329 try {
10330 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
10336 @Override
10337 public boolean setCdmaRoamingMode(int subId, int mode) {
10338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10339 mApp, subId, "setCdmaRoamingMode");
10340
joonhunshin4ac60942023-11-15 15:23:39 +000010341 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10342 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10343
Pengquan Menga1bb6272018-09-06 09:59:22 -070010344 final long identity = Binder.clearCallingIdentity();
10345 try {
10346 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350 }
10351
10352 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010353 public int getCdmaSubscriptionMode(int subId) {
10354 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010355 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010356 mApp, subId, "getCdmaSubscriptionMode");
10357
joonhunshin4ac60942023-11-15 15:23:39 +000010358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10359 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10360
Sarah Chinbaab1432020-10-28 13:46:24 -070010361 final long identity = Binder.clearCallingIdentity();
10362 try {
10363 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10364 } finally {
10365 Binder.restoreCallingIdentity(identity);
10366 }
10367 }
10368
10369 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010370 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10372 mApp, subId, "setCdmaSubscriptionMode");
10373
joonhunshin4ac60942023-11-15 15:23:39 +000010374 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10375 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10376
Pengquan Menga1bb6272018-09-06 09:59:22 -070010377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010384
sqianc5eccab2018-10-19 18:46:41 -070010385 @Override
sqian8c685422019-02-22 15:55:18 -080010386 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010387 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010389 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10390 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010391 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10392 }
joonhunshin4ac60942023-11-15 15:23:39 +000010393
10394 enforceTelephonyFeatureWithException(callingPackage,
10395 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10396
sqian11b7a0e2018-12-05 18:48:28 -080010397 final long identity = Binder.clearCallingIdentity();
10398 try {
sqian854d44b2018-12-12 16:48:18 -080010399 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10400 for (Phone phone: PhoneFactory.getPhones()) {
10401 if (phone.getEmergencyNumberTracker() != null
10402 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10403 emergencyNumberListInternal.put(
10404 phone.getSubId(),
10405 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10406 }
sqian11b7a0e2018-12-05 18:48:28 -080010407 }
sqian854d44b2018-12-12 16:48:18 -080010408 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
sqianc5eccab2018-10-19 18:46:41 -070010412 }
10413
10414 @Override
sqian8c685422019-02-22 15:55:18 -080010415 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010416 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010417 if (!exactMatch) {
10418 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010419 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010420 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010421 }
joonhunshin4ac60942023-11-15 15:23:39 +000010422
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010423 if (!mApp.getResources().getBoolean(
10424 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10426 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10427 }
joonhunshin4ac60942023-11-15 15:23:39 +000010428
sqian11b7a0e2018-12-05 18:48:28 -080010429 final long identity = Binder.clearCallingIdentity();
10430 try {
sqian854d44b2018-12-12 16:48:18 -080010431 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010432 //Note: we ignore passed in param exactMatch. We can remove it once
10433 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010434 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010435 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010436 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010437 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010438 }
sqian11b7a0e2018-12-05 18:48:28 -080010439 }
10440 return false;
10441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 }
10445
sqianf4ca7ed2019-01-15 18:32:07 -080010446 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010447 * Start emergency callback mode for GsmCdmaPhone for testing.
10448 */
10449 @Override
10450 public void startEmergencyCallbackMode() {
10451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10452 "startEmergencyCallbackMode");
10453 enforceModifyPermission();
10454 final long identity = Binder.clearCallingIdentity();
10455 try {
10456 for (Phone phone : PhoneFactory.getPhones()) {
10457 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10458 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10459 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10460 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10461 gsmCdmaPhone.obtainMessage(
10462 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10463 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10464 }
10465 }
10466 } finally {
10467 Binder.restoreCallingIdentity(identity);
10468 }
10469 }
10470
10471 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010472 * Update emergency number list for test mode.
10473 */
10474 @Override
10475 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10476 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10477 "updateEmergencyNumberListTestMode");
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 for (Phone phone: PhoneFactory.getPhones()) {
10482 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10483 if (tracker != null) {
10484 tracker.executeEmergencyNumberTestModeCommand(action, num);
10485 }
10486 }
10487 } finally {
10488 Binder.restoreCallingIdentity(identity);
10489 }
10490 }
10491
10492 /**
10493 * Get the full emergency number list for test mode.
10494 */
10495 @Override
10496 public List<String> getEmergencyNumberListTestMode() {
10497 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10498 "getEmergencyNumberListTestMode");
10499
10500 final long identity = Binder.clearCallingIdentity();
10501 try {
10502 Set<String> emergencyNumbers = new HashSet<>();
10503 for (Phone phone: PhoneFactory.getPhones()) {
10504 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10505 if (tracker != null) {
10506 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10507 emergencyNumbers.add(num.getNumber());
10508 }
10509 }
10510 }
10511 return new ArrayList<>(emergencyNumbers);
10512 } finally {
10513 Binder.restoreCallingIdentity(identity);
10514 }
10515 }
10516
chen xud6b45bd2018-10-30 22:27:10 -070010517 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010518 public int getEmergencyNumberDbVersion(int subId) {
10519 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10520
joonhunshin4ac60942023-11-15 15:23:39 +000010521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10522 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10523
Shuo Qian3b6ee772019-11-13 17:43:31 -080010524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 final Phone phone = getPhone(subId);
10527 if (phone == null) {
10528 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10529 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10530 }
10531 return phone.getEmergencyNumberDbVersion();
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 @Override
10538 public void notifyOtaEmergencyNumberDbInstalled() {
10539 enforceModifyPermission();
10540
joonhunshin4ac60942023-11-15 15:23:39 +000010541 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10542 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10543
Shuo Qian3b6ee772019-11-13 17:43:31 -080010544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 for (Phone phone: PhoneFactory.getPhones()) {
10547 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10548 if (tracker != null) {
10549 tracker.updateOtaEmergencyNumberDatabase();
10550 }
10551 }
10552 } finally {
10553 Binder.restoreCallingIdentity(identity);
10554 }
10555 }
10556
10557 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010558 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010559 enforceActiveEmergencySessionPermission();
10560
joonhunshin4ac60942023-11-15 15:23:39 +000010561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10562 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10563
Shuo Qian3b6ee772019-11-13 17:43:31 -080010564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 for (Phone phone: PhoneFactory.getPhones()) {
10567 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10568 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010569 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10570 }
10571 }
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
10577 @Override
10578 public void resetOtaEmergencyNumberDbFilePath() {
10579 enforceActiveEmergencySessionPermission();
10580
joonhunshin4ac60942023-11-15 15:23:39 +000010581 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10582 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10583
Shuo Qianc373f112020-03-05 17:55:34 -080010584 final long identity = Binder.clearCallingIdentity();
10585 try {
10586 for (Phone phone: PhoneFactory.getPhones()) {
10587 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10588 if (tracker != null) {
10589 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010590 }
10591 }
10592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
10597 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010598 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10599 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10600 Phone phone = getPhone(subId);
10601 if (phone == null) {
10602 return null;
10603 }
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 UiccProfile profile = UiccController.getInstance()
10607 .getUiccProfileForPhone(phone.getPhoneId());
10608 if (profile != null) {
10609 return profile.getCertsFromCarrierPrivilegeAccessRules();
10610 }
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 return null;
10615 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010616
10617 /**
10618 * Enable or disable a modem stack.
10619 */
10620 @Override
10621 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10622 enforceModifyPermission();
10623
joonhunshin4ac60942023-11-15 15:23:39 +000010624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10625 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10626
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010627 final long identity = Binder.clearCallingIdentity();
10628 try {
10629 Phone phone = PhoneFactory.getPhone(slotIndex);
10630 if (phone == null) {
10631 return false;
10632 } else {
10633 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10634 }
10635 } finally {
10636 Binder.restoreCallingIdentity(identity);
10637 }
10638 }
Michelecea4cf22018-12-21 15:00:11 -080010639
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010640 /**
10641 * Whether a modem stack is enabled or not.
10642 */
10643 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010644 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10645 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010646 Phone phone = PhoneFactory.getPhone(slotIndex);
10647 if (phone == null) return false;
10648
10649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010650 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10651 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010652 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10653 }
10654
joonhunshin4ac60942023-11-15 15:23:39 +000010655 enforceTelephonyFeatureWithException(callingPackage,
10656 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10657
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010658 final long identity = Binder.clearCallingIdentity();
10659 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010660 try {
10661 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10662 } catch (NoSuchElementException ex) {
10663 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10664 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010665 } finally {
10666 Binder.restoreCallingIdentity(identity);
10667 }
10668 }
10669
Michelecea4cf22018-12-21 15:00:11 -080010670 @Override
Michele0ea7d782019-03-19 14:58:42 -070010671 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010672 enforceModifyPermission();
10673
joonhunshin4ac60942023-11-15 15:23:39 +000010674 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10675 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10676
Michelecea4cf22018-12-21 15:00:11 -080010677 final long identity = Binder.clearCallingIdentity();
10678 try {
10679 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010680 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010681 .commit();
10682 } finally {
10683 Binder.restoreCallingIdentity(identity);
10684 }
10685 }
10686
10687 @Override
Michele0ea7d782019-03-19 14:58:42 -070010688 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010689 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010691 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10692 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010693 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010694 }
Michelecea4cf22018-12-21 15:00:11 -080010695
joonhunshin4ac60942023-11-15 15:23:39 +000010696 enforceTelephonyFeatureWithException(callingPackage,
10697 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10698
Michelecea4cf22018-12-21 15:00:11 -080010699 final long identity = Binder.clearCallingIdentity();
10700 try {
Michele0ea7d782019-03-19 14:58:42 -070010701 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010702 } finally {
10703 Binder.restoreCallingIdentity(identity);
10704 }
10705 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010706
Michele0ea7d782019-03-19 14:58:42 -070010707 @TelephonyManager.IsMultiSimSupportedResult
10708 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010709 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10710 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10711 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010712 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10713 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010714 }
10715 // Check if the hardware supports multisim functionality. If usage of multisim is not
10716 // supported by the modem, indicate that it is restricted.
10717 PhoneCapability staticCapability =
10718 mPhoneConfigurationManager.getStaticPhoneCapability();
10719 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010720 loge("isMultiSimSupportedInternal: no static configuration available");
10721 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010722 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010723 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010724 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10725 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010726 }
10727 // Check if support of multiple SIMs is restricted by carrier
10728 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010729 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010730 }
10731
Michele0ea7d782019-03-19 14:58:42 -070010732 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010733 }
10734
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010735 /**
10736 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010737 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10738 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10739 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010740 * @param numOfSims number of active sims we want to switch to
10741 */
10742 @Override
10743 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010744 if (numOfSims == 1) {
10745 enforceModifyPermission();
10746 } else {
10747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10748 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10749 }
joonhunshin4ac60942023-11-15 15:23:39 +000010750
10751 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10752 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10753
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010754 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010755
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010756 try {
Michele30b57b22019-03-01 12:01:14 -080010757 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010758 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010759 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10760 return;
10761 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010762 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010768 @Override
10769 public boolean isApplicationOnUicc(int subId, int appType) {
10770 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010771
10772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10773 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10774
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010775 Phone phone = getPhone(subId);
10776 if (phone == null) {
10777 return false;
10778 }
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010781 UiccPort uiccPort = phone.getUiccPort();
10782 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010783 return false;
10784 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010785 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010786 if (uiccProfile == null) {
10787 return false;
10788 }
10789 if (TelephonyManager.APPTYPE_SIM <= appType
10790 && appType <= TelephonyManager.APPTYPE_ISIM) {
10791 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10792 }
10793 return false;
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010799 /**
chen xub4baa772019-04-03 10:23:41 -070010800 * Get whether making changes to modem configurations will trigger reboot.
10801 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010802 */
10803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010804 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10805 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010807 mApp, subId, callingPackage, callingFeatureId,
10808 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010809 return false;
10810 }
joonhunshin4ac60942023-11-15 15:23:39 +000010811
10812 enforceTelephonyFeatureWithException(callingPackage,
10813 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10814 "doesSwitchMultiSimConfigTriggerReboot");
10815
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10819 } finally {
10820 Binder.restoreCallingIdentity(identity);
10821 }
10822 }
10823
Nathan Harold29f5f052019-02-15 13:41:57 -080010824 private void updateModemStateMetrics() {
10825 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10826 // TODO: check the state for each modem if the api is ready.
10827 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10828 }
10829
Pengquan Meng3889a572019-01-23 11:16:29 -080010830 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010831 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010832 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010833 // Verify that the callingPackage belongs to the calling UID
10834 mApp.getSystemService(AppOpsManager.class)
10835 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010836
10837 enforceTelephonyFeatureWithException(callingPackage,
10838 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10839
Pengquan Meng3889a572019-01-23 11:16:29 -080010840 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010841 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010842 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010843 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10844 if (slotInfos != null) {
10845 for (int i = 0; i < slotInfos.length; i++) {
10846 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10847 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10848 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10849 portInfo.getLogicalSlotIndex()));
10850 }
10851 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010852 }
10853 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010854 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010855 } finally {
10856 Binder.restoreCallingIdentity(identity);
10857 }
10858 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010859
10860 /**
10861 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010862 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010863 */
jimsunf9ec1622022-09-13 21:18:43 +080010864 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010865 @Override
10866 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010867 return getHalVersion(HAL_SERVICE_RADIO);
10868 }
10869
10870 /**
10871 * Get the HAL Version of a specific service
10872 */
10873 @Override
10874 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010875 Phone phone = getDefaultPhone();
10876 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010877 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010878 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10879 return hv.major * 100 + hv.minor;
10880 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010881
10882 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010883 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010884 *
10885 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010886 */
10887 @Override
sangyun097dcf72024-01-04 10:35:49 +090010888 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010889 if (mFeatureFlags.hsumPackageManager()) {
10890 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10891 Binder.getCallingUserHandle(), 0).getPackageManager();
10892 if (pm == null) return null;
10893 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10894 return (callingUids == null) ? null : callingUids[0];
10895 }
10896 if (mPackageManager == null) return null;
10897 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10898 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010899 }
10900
10901 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010902 * @return The calling package name or "phone" if the caller is the phone process. This is done
10903 * because multiple Phone has multiple packages in it and the first element in the array is not
10904 * actually always the caller.
10905 * Note: This is for logging purposes only and should not be used for security checks.
10906 */
10907 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010908 PackageManager pm;
10909 if (mFeatureFlags.hsumPackageManager()) {
10910 pm = mApp.getBaseContext().createContextAsUser(
10911 Binder.getCallingUserHandle(), 0).getPackageManager();
10912 } else {
10913 pm = mApp.getPackageManager();
10914 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010915 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10916 if (uidName != null && !uidName.isEmpty()) return uidName;
10917 return getCurrentPackageName();
10918 }
10919
10920 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010921 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10922 * corresponding network requests on a subId.
10923 *
10924 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010925 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010926 * 2) APN is un-metered for this subscription, or
10927 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010928 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010929 *
10930 * @return whether data is allowed for a apn type.
10931 *
10932 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010933 */
10934 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010935 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010936 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10937 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010938
joonhunshin4ac60942023-11-15 15:23:39 +000010939 enforceTelephonyFeatureWithException(callingPackage,
10940 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10941
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010942 // Now that all security checks passes, perform the operation as ourselves.
10943 final long identity = Binder.clearCallingIdentity();
10944 try {
10945 Phone phone = getPhone(subId);
10946 if (phone == null) return false;
10947
Jack Yu27422a52022-03-21 10:38:05 -070010948 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010949 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010950 isMetered = phone.getDataNetworkController().getDataConfigManager()
10951 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10952 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010953 isDataEnabled = (phone.getDataSettingsManager() != null)
10954 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010955 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
10961 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010962 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010963 enforceReadPrivilegedPermission("isApnMetered");
10964
joonhunshin4ac60942023-11-15 15:23:39 +000010965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10966 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10967
Malcolm Chene5ad5792019-04-18 13:51:02 -070010968 // Now that all security checks passes, perform the operation as ourselves.
10969 final long identity = Binder.clearCallingIdentity();
10970 try {
10971 Phone phone = getPhone(subId);
10972 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010973 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10974 DataUtils.apnTypeToNetworkCapability(apnType),
10975 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010976 } finally {
10977 Binder.restoreCallingIdentity(identity);
10978 }
10979 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010980
10981 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010982 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10983 int subscriptionId, IBooleanConsumer resultCallback) {
10984 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010985
10986 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10987 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10988
Hall Liu73f5d362020-01-20 13:42:00 -080010989 long token = Binder.clearCallingIdentity();
10990 try {
10991 Phone phone = getPhone(subscriptionId);
10992 if (phone == null) {
10993 try {
10994 if (resultCallback != null) {
10995 resultCallback.accept(false);
10996 }
10997 } catch (RemoteException e) {
10998 // ignore
10999 }
11000 return;
11001 }
11002 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11003 Pair.create(specifiers, (x) -> {
11004 try {
11005 if (resultCallback != null) {
11006 resultCallback.accept(x);
11007 }
11008 } catch (RemoteException e) {
11009 // ignore
11010 }
11011 });
11012 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11013 } finally {
11014 Binder.restoreCallingIdentity(token);
11015 }
11016 }
11017
11018 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011019 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11020 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011021 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011022 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011023
11024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11025 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11026
Sarah Chin679c08a2020-11-18 13:39:35 -080011027 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011030 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11031 if (result instanceof IllegalStateException) {
11032 throw (IllegalStateException) result;
11033 }
11034 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011035 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11036 return specifiers;
11037 } finally {
11038 Binder.restoreCallingIdentity(identity);
11039 }
11040 }
11041
11042 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011043 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011044 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011045
11046 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11047 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11048
Jack Yu8b766fc2022-03-21 09:42:33 -070011049 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011050 }
11051
11052 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011053 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11054 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011055 if (callingPackage == null) {
11056 callingPackage = getCurrentPackageName();
11057 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011058 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11059 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011060 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11061 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011062 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11063 }
11064 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11065 Intent intent = new Intent();
11066 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11067 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11068 // Bring up choose default SMS subscription dialog right now
11069 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11070 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011071 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011072 }
chen xud5ca2d52019-05-28 15:20:57 -070011073
11074 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011075 public void showSwitchToManagedProfileDialog() {
11076 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011077 try {
11078 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11079 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11080 // for work telephony.
11081 Intent intent = new Intent(Intent.ACTION_SENDTO);
11082 intent.setData(Uri.parse("smsto:"));
11083 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011084 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011085 } catch (ActivityNotFoundException e) {
11086 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11087 Intent intent = new Intent();
11088 intent.setClass(mApp, ErrorDialogActivity.class);
11089 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011090 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011091 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011092 }
11093
11094 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011095 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11097 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11098
chen xud5ca2d52019-05-28 15:20:57 -070011099 //TODO investigate if this API should require proper permission check in R b/133791609
11100 final long identity = Binder.clearCallingIdentity();
11101 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011102 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11103 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11104 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11105 return carrierUAProfUrl;
11106 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011107 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11108 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
11114 @Override
11115 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11117 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11118
chen xud5ca2d52019-05-28 15:20:57 -070011119 //TODO investigate if this API should require proper permission check in R b/133791609
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011122 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11123 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11124 if (!TextUtils.isEmpty(carrierUserAgent)) {
11125 return carrierUserAgent;
11126 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011127 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11128 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011129 } finally {
11130 Binder.restoreCallingIdentity(identity);
11131 }
11132 }
Jack Yub07d4972019-05-28 16:12:25 -070011133
11134 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011135 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11136 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011137
joonhunshin4ac60942023-11-15 15:23:39 +000011138 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11139 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11140
Jack Yub07d4972019-05-28 16:12:25 -070011141 final long identity = Binder.clearCallingIdentity();
11142 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011143 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011144 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011145
Ling Maf188d502022-09-16 15:22:36 -070011146 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011147 } finally {
11148 Binder.restoreCallingIdentity(identity);
11149 }
11150 }
11151
11152 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011153 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011154 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011155 enforceModifyPermission();
11156
joonhunshin4ac60942023-11-15 15:23:39 +000011157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11158 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11159
changbettyd5c246e2019-12-24 15:40:37 +080011160 final long identity = Binder.clearCallingIdentity();
11161 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011162 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011163 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011164
Ling Maf188d502022-09-16 15:22:36 -070011165 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011166 } finally {
11167 Binder.restoreCallingIdentity(identity);
11168 }
11169 }
11170
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011171 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011172 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011173 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11174 * otherwise.
11175 */
11176 @Override
11177 public void setCepEnabled(boolean isCepEnabled) {
11178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11179
11180 final long identity = Binder.clearCallingIdentity();
11181 try {
11182 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11183 for (Phone phone : PhoneFactory.getPhones()) {
11184 Phone defaultPhone = phone.getImsPhone();
11185 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11186 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11187 ImsPhoneCallTracker imsPhoneCallTracker =
11188 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11189 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11190 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11191 + imsPhone.getMsisdn());
11192 }
11193 }
11194 } finally {
11195 Binder.restoreCallingIdentity(identity);
11196 }
11197 }
allenwtsu46dcc572020-01-08 18:24:03 +080011198
11199 /**
11200 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11201 *
11202 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11203 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11204 * before being read.
11205 */
11206 @Override
11207 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11208 isCompressed) {
11209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11210 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011211 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11212 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11213 }
joonhunshin4ac60942023-11-15 15:23:39 +000011214
11215 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11216 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11217 Binder.getCallingUserHandle())) {
11218 if (!isImsAvailableOnDevice()) {
11219 // ProvisioningManager can not handle ServiceSpecificException.
11220 // Throw the IllegalStateException and annotate ProvisioningManager.
11221 throw new IllegalStateException("IMS not available on device.");
11222 }
11223 } else {
11224 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11225 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11226 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011227 }
11228
11229 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011230 try {
Hui Wang761a6682020-10-31 05:12:53 +000011231 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11232 } finally {
11233 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011234 }
11235 }
zoey chene02881a2019-12-30 16:11:23 +080011236
11237 @Override
11238 public boolean isIccLockEnabled(int subId) {
11239 enforceReadPrivilegedPermission("isIccLockEnabled");
11240
joonhunshin4ac60942023-11-15 15:23:39 +000011241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11242 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11243
zoey chene02881a2019-12-30 16:11:23 +080011244 // Now that all security checks passes, perform the operation as ourselves.
11245 final long identity = Binder.clearCallingIdentity();
11246 try {
11247 Phone phone = getPhone(subId);
11248 if (phone != null && phone.getIccCard() != null) {
11249 return phone.getIccCard().getIccLockEnabled();
11250 } else {
11251 return false;
11252 }
11253 } finally {
11254 Binder.restoreCallingIdentity(identity);
11255 }
11256 }
11257
11258 /**
11259 * Set the ICC pin lock enabled or disabled.
11260 *
11261 * @return an integer representing the status of IccLock enabled or disabled in the following
11262 * three cases:
11263 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11264 * successfully.
11265 * - Positive number and zero for remaining password attempts.
11266 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11267 *
11268 */
11269 @Override
11270 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11271 enforceModifyPermission();
11272
joonhunshin4ac60942023-11-15 15:23:39 +000011273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11274 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11275
zoey chene02881a2019-12-30 16:11:23 +080011276 Phone phone = getPhone(subId);
11277 if (phone == null) {
11278 return 0;
11279 }
11280 // Now that all security checks passes, perform the operation as ourselves.
11281 final long identity = Binder.clearCallingIdentity();
11282 try {
11283 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11284 new Pair<Boolean, String>(enabled, password), phone, null);
11285 return attemptsRemaining;
11286
11287 } catch (Exception e) {
11288 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11289 } finally {
11290 Binder.restoreCallingIdentity(identity);
11291 }
11292 return 0;
11293 }
11294
11295 /**
11296 * Change the ICC password used in ICC pin lock.
11297 *
11298 * @return an integer representing the status of IccLock changed in the following three cases:
11299 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11300 * - Positive number and zero for remaining password attempts.
11301 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11302 *
11303 */
11304 @Override
11305 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11306 enforceModifyPermission();
11307
joonhunshin4ac60942023-11-15 15:23:39 +000011308 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11309 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11310
zoey chene02881a2019-12-30 16:11:23 +080011311 Phone phone = getPhone(subId);
11312 if (phone == null) {
11313 return 0;
11314 }
11315 // Now that all security checks passes, perform the operation as ourselves.
11316 final long identity = Binder.clearCallingIdentity();
11317 try {
11318 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11319 new Pair<String, String>(oldPassword, newPassword), phone, null);
11320 return attemptsRemaining;
11321
11322 } catch (Exception e) {
11323 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11324 } finally {
11325 Binder.restoreCallingIdentity(identity);
11326 }
11327 return 0;
11328 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011329
11330 /**
11331 * Request for receiving user activity notification
11332 */
11333 @Override
11334 public void requestUserActivityNotification() {
11335 if (!mNotifyUserActivity.get()
11336 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11337 mNotifyUserActivity.set(true);
11338 }
11339 }
11340
11341 /**
11342 * Called when userActivity is signalled in the power manager.
11343 * This is safe to call from any thread, with any window manager locks held or not.
11344 */
11345 @Override
11346 public void userActivity() {
11347 // ***************************************
11348 // * Inherited from PhoneWindowManager *
11349 // ***************************************
11350 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11351 // WITH ITS LOCKS HELD.
11352 //
11353 // This code must be VERY careful about the locks
11354 // it acquires.
11355 // In fact, the current code acquires way too many,
11356 // and probably has lurking deadlocks.
11357
Jack Yu86374492024-09-16 13:05:44 -070011358 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011359 throw new SecurityException("Only the OS may call notifyUserActivity()");
11360 }
11361
11362 if (mNotifyUserActivity.getAndSet(false)) {
11363 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11364 USER_ACTIVITY_NOTIFICATION_DELAY);
11365 }
11366 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011367
11368 @Override
11369 public boolean canConnectTo5GInDsdsMode() {
11370 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11371 }
Jack Yud10cdd42020-09-28 20:28:01 -070011372
11373 @Override
11374 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11375 String callingFeatureId) {
11376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11377 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11378 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11379 }
11380
joonhunshin4ac60942023-11-15 15:23:39 +000011381 enforceTelephonyFeatureWithException(callingPackage,
11382 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11383
Jack Yud10cdd42020-09-28 20:28:01 -070011384 Phone phone = getPhone(subId);
11385 if (phone == null) {
11386 throw new RuntimeException("phone is not available");
11387 }
11388 // Now that all security checks passes, perform the operation as ourselves.
11389 final long identity = Binder.clearCallingIdentity();
11390 try {
11391 return phone.getEquivalentHomePlmns();
11392 } finally {
11393 Binder.restoreCallingIdentity(identity);
11394 }
11395 }
Daniel Bright59e67312020-11-13 11:49:37 -080011396
11397 @Override
11398 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011399 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011400 if (!mApp.getResources().getBoolean(
11401 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11402 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11403 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11404 "isRadioInterfaceCapabilitySupported");
11405 }
joonhunshin4ac60942023-11-15 15:23:39 +000011406
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011407 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011408 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011409 if (radioInterfaceCapabilities == null) {
11410 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011411 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011412 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011413 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011414
Hui Wang641e81c2020-10-12 12:14:23 -070011415 @Override
11416 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11417 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011418 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11419 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11420 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11421 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11422 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011423
11424 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11425 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11426
Hui Wang641e81c2020-10-12 12:14:23 -070011427 if (DBG) {
11428 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11429 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11430 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11431 }
11432
11433 if (!SubscriptionManager.isValidSubscriptionId(subId)
11434 || appType < TelephonyManager.APPTYPE_UNKNOWN
11435 || appType > TelephonyManager.APPTYPE_ISIM
11436 || nafUrl == null || securityProtocol == null || callback == null) {
11437 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11438 if (callback != null) {
11439 try {
11440 callback.onAuthenticationFailure(
11441 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11442 } catch (RemoteException exception) {
11443 log("Fail to notify onAuthenticationFailure due to " + exception);
11444 }
11445 return;
11446 }
11447 }
11448
11449 final long token = Binder.clearCallingIdentity();
11450 try {
11451 getGbaManager(subId).bootstrapAuthenticationRequest(
11452 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011453 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011454 } finally {
11455 Binder.restoreCallingIdentity(token);
11456 }
11457 }
11458
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011459 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011460 * Attempts to set the radio power state for all phones for thermal reason.
11461 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011462 * requested radio power state will actually be set. See {@link
11463 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11464 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011465 * @param enable {@code true} if trying to turn radio on.
11466 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11467 * false}.
11468 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011469 private boolean setRadioPowerForThermal(boolean enable) {
11470 boolean isPhoneAvailable = false;
11471 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11472 Phone phone = PhoneFactory.getPhone(i);
11473 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011474 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011475 isPhoneAvailable = true;
11476 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011477 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011478
11479 // return true if successfully informed the phone object about the thermal radio power
11480 // request.
11481 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011482 }
11483
11484 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011485 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011486 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11487 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11488 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11489 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11490 throw new IllegalArgumentException("modem does not support data throttling");
11491 }
11492
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011493 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11494 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011495 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011496 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11497 }
11498
Sarah Chinecc78c42022-03-31 21:16:48 -070011499 setDataEnabledForReason(
11500 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011501
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011502 if (isDataThrottlingSupported) {
11503 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011504 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011505 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11506 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11507 } else if (thermalMitigationResult
11508 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011509 log("Modem likely does not support data throttling on secondary carrier. Data " +
11510 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11511 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011512 }
11513 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011514 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011515
11516 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011517 }
11518
Jack Nudelman644b91a2021-03-12 14:09:48 -080011519 private static List<String> getThermalMitigationAllowlist(Context context) {
11520 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11521 for (String pckg : context.getResources()
11522 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11523 sThermalMitigationAllowlistedPackages.add(pckg);
11524 }
11525 }
11526
11527 return sThermalMitigationAllowlistedPackages;
11528 }
11529
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011530 private boolean isAnyPhoneInEmergencyState() {
11531 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11532 if (tm.isInEmergencyCall()) {
11533 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11534 return true;
11535 }
11536 for (Phone phone : PhoneFactory.getPhones()) {
11537 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11538 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011539 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11540 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011541 return true;
11542 }
11543 }
11544
11545 return false;
11546 }
11547
Jack Nudelman644b91a2021-03-12 14:09:48 -080011548 /**
11549 * Used by shell commands to add an authorized package name for thermal mitigation.
11550 * @param packageName name of package to be allowlisted
11551 * @param context
11552 */
11553 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11554 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11555 sThermalMitigationAllowlistedPackages.add(packageName);
11556 }
11557
11558 /**
11559 * Used by shell commands to remove an authorized package name for thermal mitigation.
11560 * @param packageName name of package to remove from allowlist
11561 * @param context
11562 */
11563 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11564 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11565 sThermalMitigationAllowlistedPackages.remove(packageName);
11566 }
11567
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011568 /**
11569 * Thermal mitigation request to control functionalities at modem.
11570 *
11571 * @param subId the id of the subscription.
11572 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011573 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011574 *
11575 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11576 */
11577 @Override
11578 @ThermalMitigationResult
11579 public int sendThermalMitigationRequest(
11580 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011581 ThermalMitigationRequest thermalMitigationRequest,
11582 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011583 enforceModifyPermission();
11584
Jack Nudelman644b91a2021-03-12 14:09:48 -080011585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011586
11587 enforceTelephonyFeatureWithException(callingPackage,
11588 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11589
Jack Nudelman644b91a2021-03-12 14:09:48 -080011590 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11591 .contains(callingPackage)) {
11592 throw new SecurityException("Calling package must be configured in the device config. "
11593 + "calling package: " + callingPackage);
11594 }
11595
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11597 final long identity = Binder.clearCallingIdentity();
11598
11599 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11600 try {
11601 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11602 switch (thermalMitigationAction) {
11603 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11604 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011605 handleDataThrottlingRequest(subId,
11606 thermalMitigationRequest.getDataThrottlingRequest(),
11607 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011608 break;
11609 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11610 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11611 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11612 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11613 }
11614
11615 // Ensure that radio is on. If not able to power on due to phone being
11616 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011617 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011618 thermalMitigationResult =
11619 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11620 break;
11621 }
11622
11623 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011624 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011625 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11626 break;
11627 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11628 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11629 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11630 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11631 }
11632
11633 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11634 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011635 Phone phone = getPhone(subId);
11636 if (phone == null) {
11637 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011638 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011639 break;
11640 }
11641
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011642 TelephonyConnectionService service =
11643 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011644 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011645 Log.e(LOG_TAG, "An emergency call is pending");
11646 thermalMitigationResult =
11647 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11648 break;
11649 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011650 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011651 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011652 break;
11653 }
11654 } else {
11655 thermalMitigationResult =
11656 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11657 break;
11658 }
11659
11660 // Turn radio off. If not able to power off due to phone being unavailable,
11661 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011662 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011663 thermalMitigationResult =
11664 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11665 break;
11666 }
11667 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011668 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011669 break;
11670 default:
11671 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11672 + "not exist. Requested action: " + thermalMitigationAction);
11673 }
11674 } catch (IllegalArgumentException e) {
11675 throw e;
11676 } catch (Exception e) {
11677 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11678 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11679 } finally {
11680 Binder.restoreCallingIdentity(identity);
11681 }
11682
11683 if (DBG) {
11684 log("thermalMitigationRequest returning with thermalMitigationResult: "
11685 + thermalMitigationResult);
11686 }
11687
11688 return thermalMitigationResult;
11689 }
Hui Wang641e81c2020-10-12 12:14:23 -070011690
11691 /**
11692 * Set the GbaService Package Name that Telephony will bind to.
11693 *
11694 * @param subId The sim that the GbaService is associated with.
11695 * @param packageName The name of the package to be replaced with.
11696 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11697 */
11698 @Override
11699 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11700 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011701 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011702 final long identity = Binder.clearCallingIdentity();
11703 try {
Jack Yu02533f12024-10-03 18:44:32 -070011704 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011705 } finally {
11706 Binder.restoreCallingIdentity(identity);
11707 }
11708 }
11709
11710 /**
11711 * Return the package name of the currently bound GbaService.
11712 *
11713 * @param subId The sim that the GbaService is associated with.
11714 * @return the package name of the GbaService configuration, null if GBA is not supported.
11715 */
11716 @Override
11717 public String getBoundGbaService(int subId) {
11718 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11719
11720 final long identity = Binder.clearCallingIdentity();
11721 try {
11722 return getGbaManager(subId).getServicePackage();
11723 } finally {
11724 Binder.restoreCallingIdentity(identity);
11725 }
11726 }
11727
11728 /**
11729 * Set the release time for telephony to unbind GbaService.
11730 *
11731 * @param subId The sim that the GbaService is associated with.
11732 * @param interval The release time to unbind GbaService by millisecond.
11733 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11734 */
11735 @Override
11736 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11737 enforceModifyPermission();
11738
11739 final long identity = Binder.clearCallingIdentity();
11740 try {
11741 return getGbaManager(subId).overrideReleaseTime(interval);
11742 } finally {
11743 Binder.restoreCallingIdentity(identity);
11744 }
11745 }
11746
11747 /**
11748 * Return the release time for telephony to unbind GbaService.
11749 *
11750 * @param subId The sim that the GbaService is associated with.
11751 * @return The release time to unbind GbaService by millisecond.
11752 */
11753 @Override
11754 public int getGbaReleaseTime(int subId) {
11755 enforceReadPrivilegedPermission("getGbaReleaseTime");
11756
11757 final long identity = Binder.clearCallingIdentity();
11758 try {
11759 return getGbaManager(subId).getReleaseTime();
11760 } finally {
11761 Binder.restoreCallingIdentity(identity);
11762 }
11763 }
11764
11765 private GbaManager getGbaManager(int subId) {
11766 GbaManager instance = GbaManager.getInstance(subId);
11767 if (instance == null) {
11768 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11769 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11770 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11771 }
11772 return instance;
11773 }
Hui Wang761a6682020-10-31 05:12:53 +000011774
11775 /**
11776 * indicate whether the device and the carrier can support
11777 * RCS VoLTE single registration.
11778 */
11779 @Override
11780 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011781 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11782 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11783 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11784 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011785
11786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11787 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11788 }
11789
11790 final long identity = Binder.clearCallingIdentity();
11791 try {
11792 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11793 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011794 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11795 if (isCapable != null) {
11796 return isCapable;
11797 }
Hui Wang761a6682020-10-31 05:12:53 +000011798 }
Hui Wang67af90e2021-06-04 16:57:15 -070011799 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11800 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011801 } finally {
11802 Binder.restoreCallingIdentity(identity);
11803 }
11804 }
11805
11806 /**
11807 * Register RCS provisioning callback.
11808 */
11809 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011810 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011811 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011812 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011813 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011814 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11815 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011816
11817 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11818 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11819 }
joonhunshin4ac60942023-11-15 15:23:39 +000011820 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11821 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11822 Binder.getCallingUserHandle())) {
11823 if (!isImsAvailableOnDevice()) {
11824 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11825 "IMS not available on device.");
11826 }
11827 } else {
11828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11829 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011830 }
11831
11832 final long identity = Binder.clearCallingIdentity();
11833 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011834 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011835 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011836 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11837 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011838 }
Hui Wang761a6682020-10-31 05:12:53 +000011839 } finally {
11840 Binder.restoreCallingIdentity(identity);
11841 }
11842 }
11843
11844 /**
11845 * Unregister RCS provisioning callback.
11846 */
11847 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011848 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011849 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011850 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011851 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011852 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11853 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011854
11855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11856 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11857 }
joonhunshin4ac60942023-11-15 15:23:39 +000011858
11859 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11860 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11861 Binder.getCallingUserHandle())) {
11862 if (!isImsAvailableOnDevice()) {
11863 // operation failed silently
11864 Rlog.w(LOG_TAG, "IMS not available on device.");
11865 return;
11866 }
11867 } else {
11868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11869 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11870 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011871 }
11872
11873 final long identity = Binder.clearCallingIdentity();
11874 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011875 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011876 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011877 } finally {
11878 Binder.restoreCallingIdentity(identity);
11879 }
11880 }
11881
11882 /**
11883 * trigger RCS reconfiguration.
11884 */
11885 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011886 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11887 "triggerRcsReconfiguration",
11888 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011889
11890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11891 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11892 }
joonhunshin4ac60942023-11-15 15:23:39 +000011893 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11894 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11895 Binder.getCallingUserHandle())) {
11896 if (!isImsAvailableOnDevice()) {
11897 // ProvisioningManager can not handle ServiceSpecificException.
11898 // Throw the IllegalStateException and annotate ProvisioningManager.
11899 throw new IllegalStateException("IMS not available on device.");
11900 }
11901 } else {
11902 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11903 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011904 }
11905
11906 final long identity = Binder.clearCallingIdentity();
11907 try {
11908 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11909 } finally {
11910 Binder.restoreCallingIdentity(identity);
11911 }
11912 }
11913
11914 /**
11915 * Provide the client configuration parameters of the RCS application.
11916 */
11917 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011918 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11919 "setRcsClientConfiguration",
11920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011921
11922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11923 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11924 }
joonhunshin4ac60942023-11-15 15:23:39 +000011925 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11926 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11927 Binder.getCallingUserHandle())) {
11928 if (!isImsAvailableOnDevice()) {
11929 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11930 "IMS not available on device.");
11931 }
11932 } else {
11933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11934 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011935 }
11936
11937 final long identity = Binder.clearCallingIdentity();
11938
11939 try {
11940 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11941 if (configBinder == null) {
11942 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011943 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11944 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011945 } else {
11946 configBinder.setRcsClientConfiguration(rcc);
11947 }
joonhunshin3e154242021-09-17 06:33:39 +000011948
11949 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11950 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011951 } catch (RemoteException e) {
11952 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011953 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11954 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011955 } finally {
11956 Binder.restoreCallingIdentity(identity);
11957 }
11958 }
11959
11960 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011961 * Enables or disables the test mode for RCS VoLTE single registration.
11962 */
11963 @Override
11964 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11966 "setRcsSingleRegistrationTestModeEnabled");
11967
11968 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11969 }
11970
11971 /**
11972 * Gets the test mode for RCS VoLTE single registration.
11973 */
11974 @Override
11975 public boolean getRcsSingleRegistrationTestModeEnabled() {
11976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11977 "getRcsSingleRegistrationTestModeEnabled");
11978
11979 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11980 }
11981
11982 /**
Hui Wang761a6682020-10-31 05:12:53 +000011983 * Overrides the config of RCS VoLTE single registration enabled for the device.
11984 */
11985 @Override
11986 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11987 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11988 "setDeviceSingleRegistrationEnabledOverride");
11989 enforceModifyPermission();
11990
11991 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11992 : Boolean.parseBoolean(enabledStr);
11993 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011994 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011995 }
11996
11997 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011998 * Sends a device to device communication message. Only usable via shell.
11999 * @param message message to send.
12000 * @param value message value.
12001 */
12002 @Override
12003 public void sendDeviceToDeviceMessage(int message, int value) {
12004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012005 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012006 enforceModifyPermission();
12007
12008 final long identity = Binder.clearCallingIdentity();
12009 try {
12010 TelephonyConnectionService service =
12011 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12012 if (service == null) {
12013 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12014 return;
12015 }
12016 service.sendTestDeviceToDeviceMessage(message, value);
12017 } finally {
12018 Binder.restoreCallingIdentity(identity);
12019 }
12020 }
12021
Tyler Gunnbabbda02021-02-10 11:05:02 -080012022 /**
12023 * Sets the specified device to device transport active.
12024 * @param transport The transport to set active.
12025 */
12026 @Override
12027 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12028 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12029 "setActiveDeviceToDeviceTransport");
12030 enforceModifyPermission();
12031
12032 final long identity = Binder.clearCallingIdentity();
12033 try {
12034 TelephonyConnectionService service =
12035 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12036 if (service == null) {
12037 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12038 return;
12039 }
12040 service.setActiveDeviceToDeviceTransport(transport);
12041 } finally {
12042 Binder.restoreCallingIdentity(identity);
12043 }
12044 }
Tyler Gunn92479152021-01-20 16:30:10 -080012045
Tyler Gunnd4339262021-05-03 14:46:49 -070012046 @Override
12047 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12049 "setDeviceToDeviceForceEnabled");
12050
12051 final long identity = Binder.clearCallingIdentity();
12052 try {
12053 Arrays.stream(PhoneFactory.getPhones()).forEach(
12054 p -> {
12055 Phone thePhone = p.getImsPhone();
12056 if (thePhone != null && thePhone instanceof ImsPhone) {
12057 ImsPhone imsPhone = (ImsPhone) thePhone;
12058 CallTracker tracker = imsPhone.getCallTracker();
12059 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12060 ImsPhoneCallTracker imsPhoneCallTracker =
12061 (ImsPhoneCallTracker) tracker;
12062 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12063 }
12064 }
12065 }
12066 );
12067 } finally {
12068 Binder.restoreCallingIdentity(identity);
12069 }
12070 }
12071
Tyler Gunn92479152021-01-20 16:30:10 -080012072 /**
Hui Wang761a6682020-10-31 05:12:53 +000012073 * Gets the config of RCS VoLTE single registration enabled for the device.
12074 */
12075 @Override
12076 public boolean getDeviceSingleRegistrationEnabled() {
12077 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12078 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12079 }
12080
12081 /**
12082 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12083 */
12084 @Override
12085 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12087 "setCarrierSingleRegistrationEnabledOverride");
12088 enforceModifyPermission();
12089
12090 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12091 : Boolean.parseBoolean(enabledStr);
12092 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12093 subId, enabled);
12094 }
12095
12096 /**
12097 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12098 */
12099 @Override
12100 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12101 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12102 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12103 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012104
12105 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012106 * Overrides the ims feature validation result
12107 */
12108 @Override
12109 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12110 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12111 "setImsFeatureValidationOverride");
12112
12113 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12114 : Boolean.parseBoolean(enabledStr);
12115 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12116 subId, enabled);
12117 }
12118
12119 /**
12120 * Gets the ims feature validation override value
12121 */
12122 @Override
12123 public boolean getImsFeatureValidationOverride(int subId) {
12124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12125 "getImsFeatureValidationOverride");
12126 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12127 }
12128
12129 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012130 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12131 * their mobile plan.
12132 */
12133 @Override
12134 public String getMobileProvisioningUrl() {
12135 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12136 final long identity = Binder.clearCallingIdentity();
12137 try {
12138 return getDefaultPhone().getMobileProvisioningUrl();
12139 } finally {
12140 Binder.restoreCallingIdentity(identity);
12141 }
12142 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012143
James.cf Linbcdf8b32021-01-14 16:44:13 +080012144 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012145 * Get the EAB contact from the EAB database.
12146 */
12147 @Override
12148 public String getContactFromEab(String contact) {
12149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12150 enforceModifyPermission();
12151 final long identity = Binder.clearCallingIdentity();
12152 try {
12153 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12154 } finally {
12155 Binder.restoreCallingIdentity(identity);
12156 }
12157 }
12158
12159 /**
Calvin Pana1434322021-07-01 19:27:01 +080012160 * Get the EAB capability from the EAB database.
12161 */
12162 @Override
12163 public String getCapabilityFromEab(String contact) {
12164 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12165 enforceModifyPermission();
12166 final long identity = Binder.clearCallingIdentity();
12167 try {
12168 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12169 } finally {
12170 Binder.restoreCallingIdentity(identity);
12171 }
12172 }
12173
12174 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012175 * Remove the EAB contacts from the EAB database.
12176 */
12177 @Override
12178 public int removeContactFromEab(int subId, String contacts) {
12179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12180 enforceModifyPermission();
12181 final long identity = Binder.clearCallingIdentity();
12182 try {
12183 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12184 } finally {
12185 Binder.restoreCallingIdentity(identity);
12186 }
12187 }
12188
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012189 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012190 public boolean getDeviceUceEnabled() {
12191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12192 final long identity = Binder.clearCallingIdentity();
12193 try {
12194 return mApp.getDeviceUceEnabled();
12195 } finally {
12196 Binder.restoreCallingIdentity(identity);
12197 }
12198 }
12199
12200 @Override
12201 public void setDeviceUceEnabled(boolean isEnabled) {
12202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12203 final long identity = Binder.clearCallingIdentity();
12204 try {
12205 mApp.setDeviceUceEnabled(isEnabled);
12206 } finally {
12207 Binder.restoreCallingIdentity(identity);
12208 }
12209 }
12210
Brad Ebinger14d467f2021-02-12 06:18:28 +000012211 /**
12212 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12213 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12214 */
12215 // Used for SHELL command only right now.
12216 @Override
12217 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12218 List<String> featureTags) {
12219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12220 "addUceRegistrationOverrideShell");
12221 final long identity = Binder.clearCallingIdentity();
12222 try {
12223 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12224 new ArraySet<>(featureTags));
12225 } catch (ImsException e) {
12226 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12227 } finally {
12228 Binder.restoreCallingIdentity(identity);
12229 }
12230 }
12231
12232 /**
12233 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12234 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12235 */
12236 // Used for SHELL command only right now.
12237 @Override
12238 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12239 List<String> featureTags) {
12240 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12241 "removeUceRegistrationOverrideShell");
12242 final long identity = Binder.clearCallingIdentity();
12243 try {
12244 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12245 new ArraySet<>(featureTags));
12246 } catch (ImsException e) {
12247 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12248 } finally {
12249 Binder.restoreCallingIdentity(identity);
12250 }
12251 }
12252
12253 /**
12254 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12255 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12256 */
12257 // Used for SHELL command only right now.
12258 @Override
12259 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12260 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12261 "clearUceRegistrationOverrideShell");
12262 final long identity = Binder.clearCallingIdentity();
12263 try {
12264 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12265 } catch (ImsException e) {
12266 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12267 } finally {
12268 Binder.restoreCallingIdentity(identity);
12269 }
12270 }
12271
12272 /**
12273 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12274 */
12275 // Used for SHELL command only right now.
12276 @Override
12277 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12278 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12279 "getLatestRcsContactUceCapabilityShell");
12280 final long identity = Binder.clearCallingIdentity();
12281 try {
12282 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12283 } catch (ImsException e) {
12284 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12285 } finally {
12286 Binder.restoreCallingIdentity(identity);
12287 }
12288 }
12289
12290 /**
12291 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12292 * device does not have an active PUBLISH.
12293 */
12294 // Used for SHELL command only right now.
12295 @Override
12296 public String getLastUcePidfXmlShell(int subId) {
12297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12298 final long identity = Binder.clearCallingIdentity();
12299 try {
12300 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12301 } catch (ImsException e) {
12302 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12303 } finally {
12304 Binder.restoreCallingIdentity(identity);
12305 }
12306 }
12307
James.cf Line8713a42021-04-29 16:04:26 +080012308 /**
12309 * Remove UCE requests cannot be sent to the network status.
12310 */
12311 // Used for SHELL command only right now.
12312 @Override
12313 public boolean removeUceRequestDisallowedStatus(int subId) {
12314 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12315 final long identity = Binder.clearCallingIdentity();
12316 try {
12317 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12318 } catch (ImsException e) {
12319 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12320 } finally {
12321 Binder.restoreCallingIdentity(identity);
12322 }
12323 }
12324
James.cf Lin18bb9002021-05-25 01:37:38 +080012325 /**
12326 * Remove UCE requests cannot be sent to the network status.
12327 */
12328 // Used for SHELL command only.
12329 @Override
12330 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12331 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12332 final long identity = Binder.clearCallingIdentity();
12333 try {
12334 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12335 } catch (ImsException e) {
12336 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12337 } finally {
12338 Binder.restoreCallingIdentity(identity);
12339 }
12340 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012341
James.cf Lin4b784aa2021-01-31 03:25:15 +080012342 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012343 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12344 String callingPackage) {
12345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12346 mApp, subId, "setSignalStrengthUpdateRequest");
12347
joonhunshin4ac60942023-11-15 15:23:39 +000012348 enforceTelephonyFeatureWithException(callingPackage,
12349 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12350
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012351 final int callingUid = Binder.getCallingUid();
12352 // Verify that tha callingPackage belongs to the calling UID
12353 mApp.getSystemService(AppOpsManager.class)
12354 .checkPackage(callingUid, callingPackage);
12355
Rambo Wang3607f502021-02-01 21:51:40 -080012356 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012357
12358 final long identity = Binder.clearCallingIdentity();
12359 try {
12360 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12361 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12362
12363 if (result instanceof IllegalStateException) {
12364 throw (IllegalStateException) result;
12365 }
12366 } finally {
12367 Binder.restoreCallingIdentity(identity);
12368 }
12369 }
12370
12371 @Override
12372 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12373 String callingPackage) {
12374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12375 mApp, subId, "clearSignalStrengthUpdateRequest");
12376
joonhunshin4ac60942023-11-15 15:23:39 +000012377 enforceTelephonyFeatureWithException(callingPackage,
12378 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12379
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012380 final int callingUid = Binder.getCallingUid();
12381 // Verify that tha callingPackage belongs to the calling UID
12382 mApp.getSystemService(AppOpsManager.class)
12383 .checkPackage(callingUid, callingPackage);
12384
12385 final long identity = Binder.clearCallingIdentity();
12386 try {
12387 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12388 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12389
12390 if (result instanceof IllegalStateException) {
12391 throw (IllegalStateException) result;
12392 }
12393 } finally {
12394 Binder.restoreCallingIdentity(identity);
12395 }
12396 }
12397
Rambo Wang3607f502021-02-01 21:51:40 -080012398 private static void validateSignalStrengthUpdateRequest(Context context,
12399 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012400 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012401 // phone/system process do not have further restriction on request
12402 return;
12403 }
12404
12405 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012406 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012407 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012408 context.enforceCallingOrSelfPermission(
12409 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12410 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012411 }
12412
12413 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012414 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012415 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012416 || info.isEnabled()) {
12417 throw new IllegalArgumentException(
12418 "Only system can set hide fields in SignalThresholdInfo");
12419 }
12420
12421 // Thresholds length for each RAN need in range. This has been validated in
12422 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12423 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12424 final int[] thresholds = info.getThresholds();
12425 Objects.requireNonNull(thresholds);
12426 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12427 || thresholds.length
12428 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12429 throw new IllegalArgumentException(
12430 "thresholds length is out of range: " + thresholds.length);
12431 }
12432 }
12433 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012434
12435 /**
12436 * Gets the current phone capability.
12437 *
12438 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12439 * @return the PhoneCapability which describes the data connection capability of modem.
12440 * It's used to evaluate possible phone config change, for example from single
12441 * SIM device to multi-SIM device.
12442 */
12443 @Override
12444 public PhoneCapability getPhoneCapability() {
12445 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012446
12447 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12448 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12449
SongFerngWang8236caa2021-01-17 21:51:44 +080012450 final long identity = Binder.clearCallingIdentity();
12451 try {
12452 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12453 } finally {
12454 Binder.restoreCallingIdentity(identity);
12455 }
12456 }
Michele Berionne5e411512020-11-13 02:36:59 +000012457
12458 /**
12459 * Prepare TelephonyManager for an unattended reboot. The reboot is
12460 * required to be done shortly after the API is invoked.
12461 */
12462 @Override
12463 @TelephonyManager.PrepareUnattendedRebootResult
12464 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012466 enforceRebootPermission();
12467
joonhunshin4ac60942023-11-15 15:23:39 +000012468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12469 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12470
Michele Berionne5e411512020-11-13 02:36:59 +000012471 final long identity = Binder.clearCallingIdentity();
12472 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012473 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012474 } finally {
12475 Binder.restoreCallingIdentity(identity);
12476 }
12477 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012478
12479 /**
12480 * Request to get the current slicing configuration including URSP rules and
12481 * NSSAIs (configured, allowed and rejected).
12482 *
12483 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12484 */
12485 @Override
12486 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012487 TelephonyPermissions
12488 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12489 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012490
joonhunshin4ac60942023-11-15 15:23:39 +000012491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12492 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12493 "getSlicingConfig");
12494
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012495 final long identity = Binder.clearCallingIdentity();
12496 try {
12497 Phone phone = getDefaultPhone();
12498 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12499 } finally {
12500 Binder.restoreCallingIdentity(identity);
12501 }
12502 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012503
12504 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012505 * Check whether the given premium capability is available for purchase from the carrier.
12506 *
12507 * @param capability The premium capability to check.
12508 * @param subId The subId to check the premium capability for.
12509 *
12510 * @return Whether the given premium capability is available to purchase.
12511 */
12512 @Override
12513 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12514 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12515 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12516 log("Premium capability "
12517 + TelephonyManager.convertPremiumCapabilityToString(capability)
12518 + " is not available for purchase due to missing permissions.");
12519 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12520 + "permission READ_BASIC_PHONE_STATE.");
12521 }
12522
joonhunshin4ac60942023-11-15 15:23:39 +000012523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12524 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12525
Sarah Chin2ec39f62022-08-31 17:03:26 -070012526 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012527 if (phone == null) {
12528 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12529 return false;
12530 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012531 final long identity = Binder.clearCallingIdentity();
12532 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012533 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012534 .isPremiumCapabilityAvailableForPurchase(capability);
12535 } finally {
12536 Binder.restoreCallingIdentity(identity);
12537 }
12538 }
12539
12540 /**
12541 * Purchase the given premium capability from the carrier.
12542 *
12543 * @param capability The premium capability to purchase.
12544 * @param callback The result of the purchase request.
12545 * @param subId The subId to purchase the premium capability for.
12546 */
12547 @Override
12548 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12549 log("purchasePremiumCapability: capability="
12550 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12551 + getCurrentPackageName());
12552
12553 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12554 mApp, "purchasePremiumCapability")) {
12555 log("purchasePremiumCapability "
12556 + TelephonyManager.convertPremiumCapabilityToString(capability)
12557 + " failed due to missing permissions.");
12558 throw new SecurityException("purchasePremiumCapability requires permission "
12559 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012560 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12561 mApp, "purchasePremiumCapability")) {
12562 log("purchasePremiumCapability "
12563 + TelephonyManager.convertPremiumCapabilityToString(capability)
12564 + " failed due to missing permissions.");
12565 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012566 }
12567
joonhunshin4ac60942023-11-15 15:23:39 +000012568 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12569 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12570
Sarah Chin2ec39f62022-08-31 17:03:26 -070012571 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012572 if (phone == null) {
12573 try {
12574 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12575 callback.accept(result);
12576 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12577 } catch (RemoteException e) {
12578 String logStr = "Purchase premium capability "
12579 + TelephonyManager.convertPremiumCapabilityToString(capability)
12580 + " failed due to RemoteException handling null phone: " + e;
12581 if (DBG) log(logStr);
12582 AnomalyReporter.reportAnomaly(
12583 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12584 }
12585 return;
12586 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012587
12588 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012589 try {
Jack Yube3fa442024-09-16 14:39:45 -070012590 if (mFeatureFlags.hsumPackageManager()) {
12591 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12592 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12593 } else {
12594 callingProcess = mApp.getPackageManager().getApplicationInfo(
12595 getCurrentPackageName(), 0).processName;
12596 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012597 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012598 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012599 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012600
12601 boolean isVisible = false;
12602 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12603 if (am != null) {
12604 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12605 if (processes != null) {
12606 for (ActivityManager.RunningAppProcessInfo process : processes) {
12607 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012608 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012609 if (process.processName.equals(callingProcess) && process.importance
12610 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12611 isVisible = true;
12612 break;
12613 }
12614 }
12615 }
12616 }
12617
12618 if (!isVisible) {
12619 try {
12620 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12621 callback.accept(result);
12622 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12623 } catch (RemoteException e) {
12624 String logStr = "Purchase premium capability "
12625 + TelephonyManager.convertPremiumCapabilityToString(capability)
12626 + " failed due to RemoteException handling background application: " + e;
12627 if (DBG) log(logStr);
12628 AnomalyReporter.reportAnomaly(
12629 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12630 }
12631 return;
12632 }
12633
Sarah Chin71b3a852022-09-28 15:54:19 -070012634 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012635 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012636 }
12637
12638 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012639 * Register an IMS connection state callback
12640 */
12641 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012642 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12643 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012644 if (feature == ImsFeature.FEATURE_MMTEL) {
12645 // ImsMmTelManager
12646 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12647 TelephonyPermissions
12648 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12649 mApp, subId, "registerImsStateCallback");
12650 } else if (feature == ImsFeature.FEATURE_RCS) {
12651 // ImsRcsManager or SipDelegateManager
12652 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12653 Binder.getCallingUid(), "registerImsStateCallback",
12654 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12655 Manifest.permission.READ_PRECISE_PHONE_STATE,
12656 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12657 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12658 }
12659
12660 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12661 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12662 "IMS not available on device.");
12663 }
12664
12665 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12666 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12667 }
12668
12669 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12670 if (controller == null) {
12671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12672 "IMS not available on device.");
12673 }
12674
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012675 if (callingPackage == null) {
12676 callingPackage = getCurrentPackageName();
12677 }
12678
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012679 final long token = Binder.clearCallingIdentity();
12680 try {
12681 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012682 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012683 } catch (ImsException e) {
12684 throw new ServiceSpecificException(e.getCode());
12685 } finally {
12686 Binder.restoreCallingIdentity(token);
12687 }
12688 }
12689
12690 /**
12691 * Unregister an IMS connection state callback
12692 */
12693 @Override
12694 public void unregisterImsStateCallback(IImsStateCallback cb) {
12695 final long token = Binder.clearCallingIdentity();
12696 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12697 if (controller == null) {
12698 return;
12699 }
12700 try {
12701 controller.unregisterImsStateCallback(cb);
12702 } finally {
12703 Binder.restoreCallingIdentity(token);
12704 }
12705 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012706
12707 /**
12708 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12709 *
12710 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012711 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012712 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012713 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012714 * If there is current registered network this value will be same as the registered cell
12715 * identity. If the device goes out of service the previous cell identity is cached and
12716 * will be returned. If the cache age of the Cell identity is more than 24 hours
12717 * it will be cleared and null will be returned.
12718 *
12719 */
12720 @Override
12721 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12722 String callingFeatureId) {
12723 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12724 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12725 LocationAccessPolicy.checkLocationPermission(mApp,
12726 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12727 .setCallingPackage(callingPackage)
12728 .setCallingFeatureId(callingFeatureId)
12729 .setCallingPid(Binder.getCallingPid())
12730 .setCallingUid(Binder.getCallingUid())
12731 .setMethod("getLastKnownCellIdentity")
12732 .setLogAsInfo(true)
12733 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12734 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12735 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12736 .build());
12737
12738 boolean hasFinePermission =
12739 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12740 if (!hasFinePermission
12741 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12742 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012743 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012744 }
12745
12746 final long identity = Binder.clearCallingIdentity();
12747 try {
Ling Mac28f0212023-03-24 16:07:15 -070012748 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012749 if (sst == null) return null;
12750 return sst.getLastKnownCellIdentity();
12751 } finally {
12752 Binder.restoreCallingIdentity(identity);
12753 }
12754 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012755
jimsun3b9ccac2021-10-26 15:01:23 +080012756 /**
12757 * Sets the modem service class Name that Telephony will bind to.
12758 *
12759 * @param serviceName The class name of the modem service.
12760 * @return true if the operation is succeed, otherwise false.
12761 */
12762 public boolean setModemService(String serviceName) {
12763 Log.d(LOG_TAG, "setModemService - " + serviceName);
12764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012766 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12767 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012768 return mPhoneConfigurationManager.setModemService(serviceName);
12769 }
12770
12771 /**
12772 * Return the class name of the currently bounded modem service.
12773 *
12774 * @return the class name of the modem service.
12775 */
12776 public String getModemService() {
12777 String result;
12778 Log.d(LOG_TAG, "getModemService");
12779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12780 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012781 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012782 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12783 "getModemService");
12784 result = mPhoneConfigurationManager.getModemService();
12785 Log.d(LOG_TAG, "result = " + result);
12786 return result;
12787 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012788
Hakjun Choi3ee81112023-12-19 15:40:58 +000012789 /**
12790 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12791 * including carrier config, entitlement server, and config update.
12792 *
12793 * @param subId subId The subscription ID of the carrier.
12794 *
12795 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12796 * be returned.
12797 *
12798 * @throws SecurityException if the caller doesn't have the required permission.
12799 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012800 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12801 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012802 final long identity = Binder.clearCallingIdentity();
12803 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012804 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012805 } finally {
12806 Binder.restoreCallingIdentity(identity);
12807 }
12808 }
12809
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012810 @Override
12811 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12812 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12813 mApp.enforceCallingOrSelfPermission(
12814 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12815 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12816
12817 final long identity = Binder.clearCallingIdentity();
12818 try {
12819 Phone phone = getPhone(subId);
12820 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012821 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12822 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012823 phone.setVoiceServiceStateOverride(hasService);
12824 } finally {
12825 Binder.restoreCallingIdentity(identity);
12826 }
12827 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012828
12829 /**
12830 * set removable eSIM as default eUICC.
12831 *
12832 * @hide
12833 */
12834 @Override
12835 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12836 enforceModifyPermission();
12837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12838
12839 final long identity = Binder.clearCallingIdentity();
12840 try {
12841 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12842 } finally {
12843 Binder.restoreCallingIdentity(identity);
12844 }
12845 }
12846
12847 /**
12848 * Returns whether the removable eSIM is default eUICC or not.
12849 *
12850 * @hide
12851 */
12852 @Override
12853 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12854 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12855 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12856
12857 final long identity = Binder.clearCallingIdentity();
12858 try {
12859 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12860 } finally {
12861 Binder.restoreCallingIdentity(identity);
12862 }
12863 }
12864
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012865 /**
12866 * Get the component name of the default app to direct respond-via-message intent for the
12867 * user associated with this subscription, update the cache if there is no respond-via-message
12868 * application currently configured for this user.
12869 * @return component name of the app and class to direct Respond Via Message intent to, or
12870 * {@code null} if the functionality is not supported.
12871 * @hide
12872 */
12873 @Override
12874 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12875 boolean updateIfNeeded) {
12876 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012877
joonhunshin4ac60942023-11-15 15:23:39 +000012878 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12879 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12880 "getDefaultRespondViaMessageApplication");
12881
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012882 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12883
Grant Menkeb0372492024-09-19 18:01:29 -070012884 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12885 UserHandle mainUser = null;
12886 Context userContext = null;
12887 final long identity = Binder.clearCallingIdentity();
12888 try {
12889 mainUser = mUserManager.getMainUser();
12890 userContext = context.createContextAsUser(mainUser, 0);
12891 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12892 } finally {
12893 Binder.restoreCallingIdentity(identity);
12894 }
12895 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12896 updateIfNeeded, mainUser);
12897 } else {
12898 UserHandle userHandle = null;
12899 final long identity = Binder.clearCallingIdentity();
12900 try {
12901 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12902 } finally {
12903 Binder.restoreCallingIdentity(identity);
12904 }
12905 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12906 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012907 }
Grant Menkeb0372492024-09-19 18:01:29 -070012908
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012909 }
Jack Yuf5badd92022-12-08 00:50:53 -080012910
12911 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012912 * Set whether the device is able to connect with null ciphering or integrity
12913 * algorithms. This is a global setting and will apply to all active subscriptions
12914 * and all new subscriptions after this.
12915 *
12916 * @param enabled when true, null cipher and integrity algorithms are allowed.
12917 * @hide
12918 */
12919 @Override
12920 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12921 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12922 enforceModifyPermission();
12923 checkForNullCipherAndIntegritySupport();
12924
12925 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12926 // for listening to these preference changes and applying them immediately.
12927 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12928 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12929 editor.apply();
12930
12931 for (Phone phone: PhoneFactory.getPhones()) {
12932 phone.handleNullCipherEnabledChange();
12933 }
12934 }
12935
12936
12937 /**
12938 * Get whether the device is able to connect with null ciphering or integrity
12939 * algorithms. Note that this retrieves the phone-global preference and not
12940 * the state of the radio.
12941 *
12942 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12943 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12944 * version for this feature.
12945 * @hide
12946 */
12947 @Override
12948 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12949 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12950 enforceReadPermission();
12951 checkForNullCipherAndIntegritySupport();
12952 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12953 }
12954
12955 private void checkForNullCipherAndIntegritySupport() {
12956 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12957 throw new UnsupportedOperationException(
12958 "Null cipher and integrity operations require HAL 2.1 or above");
12959 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012960 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12961 throw new UnsupportedOperationException(
12962 "Null cipher and integrity operations unsupported by modem");
12963 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012964 }
12965
Gil Cukierman06403e12023-11-29 16:33:03 +000012966 private void checkForIdentifierDisclosureNotificationSupport() {
12967 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12968 throw new UnsupportedOperationException(
12969 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12970 + "above");
12971 }
12972 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12973 throw new UnsupportedOperationException(
12974 "Cellular identifier disclosure transparency operations unsupported by modem");
12975 }
12976 }
12977
Michael Groover826b71d2023-12-21 22:08:06 -060012978 private void checkForNullCipherNotificationSupport() {
12979 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12980 throw new UnsupportedOperationException(
12981 "Null cipher notification operations require HAL 2.2 or above");
12982 }
12983 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12984 throw new UnsupportedOperationException(
12985 "Null cipher notification operations unsupported by modem");
12986 }
12987 }
12988
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012989 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012990 * Get the SIM state for the slot index.
12991 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12992 *
12993 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12994 */
12995 @Override
12996 @SimState
12997 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012998 if (!mApp.getResources().getBoolean(
12999 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13001 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13002 }
joonhunshin4ac60942023-11-15 15:23:39 +000013003
Jack Yuf5badd92022-12-08 00:50:53 -080013004 IccCardConstants.State simState;
13005 if (slotIndex < 0) {
13006 simState = IccCardConstants.State.UNKNOWN;
13007 } else {
13008 Phone phone = null;
13009 try {
13010 phone = PhoneFactory.getPhone(slotIndex);
13011 } catch (IllegalStateException e) {
13012 // ignore
13013 }
13014 if (phone == null) {
13015 simState = IccCardConstants.State.UNKNOWN;
13016 } else {
13017 IccCard icc = phone.getIccCard();
13018 if (icc == null) {
13019 simState = IccCardConstants.State.UNKNOWN;
13020 } else {
13021 simState = icc.getState();
13022 }
13023 }
13024 }
13025 return simState.ordinal();
13026 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013027
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013028 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13029 boolean enableLogcat,
13030 long logcatStartTimestampMillis, boolean enableTelecomDump,
13031 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013032 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013033 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13034 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13035 ecdDataBuilder
13036 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13037 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013038 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013039 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013040 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013041 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13042 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013043 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13044 Executors.newCachedThreadPool(), db,
13045 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013046 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013047 }
13048
13049 /**
13050 * Request telephony to persist state for debugging emergency call failures.
13051 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013052 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013053 * @param enableLogcat whether to collect logcat output
13054 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13055 * @param enableTelecomDump whether to collect telecom dumpsys
13056 * @param enableTelephonyDump whether to collect telephony dumpsys
13057 */
13058 @Override
13059 @RequiresPermission(android.Manifest.permission.DUMP)
13060 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13061 long logcatStartTimestampMillis, boolean enableTelecomDump,
13062 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013063 // Verify that the caller has READ_DROPBOX_DATA permission.
13064 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13065 && Flags.enableReadDropboxPermission()) {
13066 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13067 "persistEmergencyCallDiagnosticData");
13068 } else {
13069 // Otherwise, enforce legacy permission.
13070 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13071 "persistEmergencyCallDiagnosticData");
13072 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013073 final long identity = Binder.clearCallingIdentity();
13074 try {
13075 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13076 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13077
13078 } finally {
13079 Binder.restoreCallingIdentity(identity);
13080 }
13081 }
13082
Hui Wang9b5793a2022-12-05 14:38:06 -060013083 /**
13084 * Get current cell broadcast ranges.
13085 */
13086 @Override
13087 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13088 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13089 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13090 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013091
13092 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13093 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13094
Hui Wang9b5793a2022-12-05 14:38:06 -060013095 final long identity = Binder.clearCallingIdentity();
13096 try {
13097 return getPhone(subId).getCellBroadcastIdRanges();
13098 } finally {
13099 Binder.restoreCallingIdentity(identity);
13100 }
13101 }
13102
13103 /**
13104 * Set reception of cell broadcast messages with the list of the given ranges
13105 *
13106 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13107 */
13108 @Override
13109 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13110 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13111 @Nullable IIntegerConsumer callback) {
13112 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13113 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013114
13115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13116 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13117
Hui Wang9b5793a2022-12-05 14:38:06 -060013118 final long identity = Binder.clearCallingIdentity();
13119 try {
13120 Phone phone = getPhoneFromSubId(subId);
13121 if (DBG) {
13122 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13123 }
13124 phone.setCellBroadcastIdRanges(ranges, result -> {
13125 if (callback != null) {
13126 try {
13127 callback.accept(result);
13128 } catch (RemoteException e) {
13129 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13130 }
13131 }
13132 });
13133 } finally {
13134 Binder.restoreCallingIdentity(identity);
13135 }
13136 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013137
13138 /**
13139 * Returns whether the device supports the domain selection service.
13140 *
13141 * @return {@code true} if the device supports the domain selection service.
13142 */
13143 @Override
13144 public boolean isDomainSelectionSupported() {
13145 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13146 "isDomainSelectionSupported");
13147
13148 final long identity = Binder.clearCallingIdentity();
13149 try {
13150 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13151 } finally {
13152 Binder.restoreCallingIdentity(identity);
13153 }
13154 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013155
13156 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013157 * Returns whether the AOSP domain selection service is supported.
13158 *
13159 * @return {@code true} if the AOSP domain selection service is supported,
13160 * {@code false} otherwise.
13161 */
13162 @Override
13163 public boolean isAospDomainSelectionService() {
13164 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13165 "isAospDomainSelectionService");
13166
13167 final long identity = Binder.clearCallingIdentity();
13168 try {
13169 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13170 String dssComponentName = mApp.getResources().getString(
13171 R.string.config_domain_selection_service_component_name);
13172 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13173 TelephonyDomainSelectionService.class.getName());
13174 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13175 + ", aosp=" + componentName.flattenToString());
13176 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13177 }
13178 } finally {
13179 Binder.restoreCallingIdentity(identity);
13180 }
13181 return false;
13182 }
13183
13184 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013185 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13186 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13187 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013188 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013189 * @param enableSatellite {@code true} to enable the satellite modem and
13190 * {@code false} to disable.
13191 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013192 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013193 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013194 *
13195 * @throws SecurityException if the caller doesn't have the required permission.
13196 */
13197 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013198 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013199 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013200 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013201 final long identity = Binder.clearCallingIdentity();
13202 try {
13203 if (enableSatellite) {
13204 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13205 @Override
13206 protected void onReceiveResult(int resultCode, Bundle resultData) {
13207 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13208 + ", resultData=" + resultData);
13209 boolean isAllowed = false;
13210 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13211 callback::accept);
13212 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13213 if (resultData != null
13214 && resultData.containsKey(
13215 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13216 isAllowed = resultData.getBoolean(
13217 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13218 } else {
13219 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13220 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013221 } else {
Hyosun322782b2024-10-24 11:37:59 +000013222 result.accept(resultCode);
13223 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013224 }
Hyosun322782b2024-10-24 11:37:59 +000013225 if (isAllowed) {
13226 mSatelliteController.requestSatelliteEnabled(
13227 enableSatellite, enableDemoMode, isEmergency, callback);
13228 } else {
13229 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13230 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013231 }
Hyosun322782b2024-10-24 11:37:59 +000013232 };
13233 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13234 resultReceiver, true);
13235 } else {
13236 // No need to check if satellite is allowed at current location when disabling
13237 // satellite
13238 mSatelliteController.requestSatelliteEnabled(
13239 enableSatellite, enableDemoMode, isEmergency, callback);
13240 }
13241 } finally {
13242 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013243 }
Sarah Chin503828c2023-02-01 23:54:20 -080013244 }
13245
13246 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013247 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013248 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013249 * @param result The result receiver that returns whether the satellite modem is enabled
13250 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013251 *
13252 * @throws SecurityException if the caller doesn't have the required permission.
13253 */
13254 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013255 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013256 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013257 final long identity = Binder.clearCallingIdentity();
13258 try {
13259 mSatelliteController.requestIsSatelliteEnabled(result);
13260 } finally {
13261 Binder.restoreCallingIdentity(identity);
13262 }
Sarah Chin503828c2023-02-01 23:54:20 -080013263 }
13264
13265 /**
Sarah Chin43457982023-02-15 17:50:38 -080013266 * Request to get whether the satellite service demo mode is enabled.
13267 *
Sarah Chin43457982023-02-15 17:50:38 -080013268 * @param result The result receiver that returns whether the satellite demo mode is enabled
13269 * if the request is successful or an error code if the request failed.
13270 *
13271 * @throws SecurityException if the caller doesn't have the required permission.
13272 */
13273 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013274 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013275 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013276 final long identity = Binder.clearCallingIdentity();
13277 try {
13278 mSatelliteController.requestIsDemoModeEnabled(result);
13279 } finally {
13280 Binder.restoreCallingIdentity(identity);
13281 }
Sarah Chin43457982023-02-15 17:50:38 -080013282 }
13283
13284 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013285 * Request to get whether the satellite service is enabled with emergency mode.
13286 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013287 * @param result The result receiver that returns whether the satellite emergency mode is
13288 * enabled if the request is successful or an error code if the request failed.
13289 *
13290 * @throws SecurityException if the caller doesn't have the required permission.
13291 */
13292 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013293 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013294 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013295 final long identity = Binder.clearCallingIdentity();
13296 try {
13297 mSatelliteController.requestIsEmergencyModeEnabled(result);
13298 } finally {
13299 Binder.restoreCallingIdentity(identity);
13300 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013301 }
13302
13303 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013304 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013305 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013306 * @param result The result receiver that returns whether the satellite service is supported on
13307 * the device if the request is successful or an error code if the request failed.
Hyosun322782b2024-10-24 11:37:59 +000013308 *
13309 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chin503828c2023-02-01 23:54:20 -080013310 */
13311 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013312 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013313 enforceSatelliteCommunicationPermission("requestIsSatelliteSupported");
13314 final long identity = Binder.clearCallingIdentity();
13315 try {
13316 mSatelliteController.requestIsSatelliteSupported(result);
13317 } finally {
13318 Binder.restoreCallingIdentity(identity);
13319 }
Sarah Chin503828c2023-02-01 23:54:20 -080013320 }
13321
13322 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013323 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013324 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013325 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13326 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013327 *
13328 * @throws SecurityException if the caller doesn't have required permission.
13329 */
13330 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013331 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013332 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013333 final long identity = Binder.clearCallingIdentity();
13334 try {
13335 mSatelliteController.requestSatelliteCapabilities(result);
13336 } finally {
13337 Binder.restoreCallingIdentity(identity);
13338 }
Sarah Chin503828c2023-02-01 23:54:20 -080013339 }
13340
13341 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013342 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013343 * This can be called by the pointing UI when the user starts pointing to the satellite.
13344 * Modem should continue to report the pointing input as the device or satellite moves.
13345 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013346 * @param resultCallback The callback to get the result of the request.
13347 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013348 *
13349 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013350 */
13351 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013352 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013353 @NonNull IIntegerConsumer resultCallback,
13354 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13355 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013356 final long identity = Binder.clearCallingIdentity();
13357 try {
13358 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13359 } finally {
13360 Binder.restoreCallingIdentity(identity);
13361 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013362 }
13363
13364 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013365 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013366 * This can be called by the pointing UI when the user stops pointing to the satellite.
13367 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013368 * @param resultCallback The callback to get the result of the request.
13369 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013370 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013371 *
13372 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013373 */
13374 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013375 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013376 @NonNull IIntegerConsumer resultCallback,
13377 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13378 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013379 final long identity = Binder.clearCallingIdentity();
13380 try {
13381 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13382 } finally {
13383 Binder.restoreCallingIdentity(identity);
13384 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013385 }
13386
13387 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013388 * Register the subscription with a satellite provider.
13389 * This is needed to register the subscription if the provider allows dynamic registration.
13390 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013391 * @param token The token to be used as a unique identifier for provisioning with satellite
13392 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013393 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013394 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013395 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013396 * @return The signal transport used by the caller to cancel the provision request,
13397 * or {@code null} if the request failed.
13398 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 * @throws SecurityException if the caller doesn't have the required permission.
13400 */
13401 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013402 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013403 @NonNull String token, @NonNull byte[] provisionData,
13404 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013405 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013406 final long identity = Binder.clearCallingIdentity();
13407 try {
13408 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013409 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013410 } finally {
13411 Binder.restoreCallingIdentity(identity);
13412 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013413 }
13414
13415 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013416 * Unregister the device/subscription with the satellite provider.
13417 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013418 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013419 * should report as deprovisioned.
13420 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013421 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013422 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013423 *
13424 * @throws SecurityException if the caller doesn't have the required permission.
13425 */
13426 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013427 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013428 @NonNull String token, @NonNull IIntegerConsumer callback) {
13429 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013430 final long identity = Binder.clearCallingIdentity();
13431 try {
13432 mSatelliteController.deprovisionSatelliteService(token, callback);
13433 } finally {
13434 Binder.restoreCallingIdentity(identity);
13435 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013436 }
13437
13438 /**
Sarah Chin43457982023-02-15 17:50:38 -080013439 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013440 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013441 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013442 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013443 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013444 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013445 * @throws SecurityException if the caller doesn't have the required permission.
13446 */
13447 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013448 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013449 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013450 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013451 final long identity = Binder.clearCallingIdentity();
13452 try {
13453 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13454 } finally {
13455 Binder.restoreCallingIdentity(identity);
13456 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013457 }
13458
13459 /**
Sarah Chin43457982023-02-15 17:50:38 -080013460 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013461 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013462 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013463 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013464 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013465 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013466 * @throws SecurityException if the caller doesn't have the required permission.
13467 */
13468 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013469 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013470 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013471 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013472 final long identity = Binder.clearCallingIdentity();
13473 try {
13474 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13475 } finally {
13476 Binder.restoreCallingIdentity(identity);
13477 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013478 }
13479
13480 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013481 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013482 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013483 * @param result The result receiver that returns whether the device is provisioned with a
13484 * satellite provider if the request is successful or an error code if the
13485 * request failed.
13486 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013487 * @throws SecurityException if the caller doesn't have the required permission.
13488 */
13489 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013490 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013491 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013492 final long identity = Binder.clearCallingIdentity();
13493 try {
13494 mSatelliteController.requestIsSatelliteProvisioned(result);
13495 } finally {
13496 Binder.restoreCallingIdentity(identity);
13497 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013498 }
13499
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013500 /**
Sarah Chin43457982023-02-15 17:50:38 -080013501 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013502 *
Sarah Chin43457982023-02-15 17:50:38 -080013503 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013504 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013505 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013506 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013507 * @throws SecurityException if the caller doesn't have the required permission.
13508 */
13509 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013510 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013511 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013512 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013513 final long identity = Binder.clearCallingIdentity();
13514 try {
13515 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13516 } finally {
13517 Binder.restoreCallingIdentity(identity);
13518 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013519 }
13520
13521 /**
Sarah Chin43457982023-02-15 17:50:38 -080013522 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013523 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013524 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013525 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013526 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013527 *
13528 * @throws SecurityException if the caller doesn't have the required permission.
13529 */
13530 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013531 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013532 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013533 final long identity = Binder.clearCallingIdentity();
13534 try {
13535 mSatelliteController.unregisterForModemStateChanged(callback);
13536 } finally {
13537 Binder.restoreCallingIdentity(identity);
13538 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013539 }
13540
13541 /**
13542 * Register to receive incoming datagrams over satellite.
13543 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013544 * @param callback The callback to handle incoming datagrams over satellite.
13545 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013546 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013547 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013548 * @throws SecurityException if the caller doesn't have the required permission.
13549 */
13550 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013551 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013552 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013553 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013554 final long identity = Binder.clearCallingIdentity();
13555 try {
13556 return mSatelliteController.registerForIncomingDatagram(callback);
13557 } finally {
13558 Binder.restoreCallingIdentity(identity);
13559 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013560 }
13561
13562 /**
13563 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013564 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013565 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013566 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013567 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013568 *
13569 * @throws SecurityException if the caller doesn't have the required permission.
13570 */
13571 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013572 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013573 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013574 final long identity = Binder.clearCallingIdentity();
13575 try {
13576 mSatelliteController.unregisterForIncomingDatagram(callback);
13577 } finally {
13578 Binder.restoreCallingIdentity(identity);
13579 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013580 }
13581
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013582 /**
13583 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013584 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013585 * This method requests modem to check if there are any pending datagrams to be received over
13586 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013587 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013588 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013589 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013590 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013591 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013592 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013593 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013594 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013595 final long identity = Binder.clearCallingIdentity();
13596 try {
13597 mSatelliteController.pollPendingDatagrams(callback);
13598 } finally {
13599 Binder.restoreCallingIdentity(identity);
13600 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013601 }
13602
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013603 /**
13604 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013605 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013606 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13607 * input to this method. Datagram received here will be passed down to modem without any
13608 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013609 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013610 * @param datagramType datagram type indicating whether the datagram is of type
13611 * SOS_SMS or LOCATION_SHARING.
13612 * @param datagram encoded gateway datagram which is encrypted by the caller.
13613 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013614 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13615 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013616 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013617 *
13618 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013619 */
13620 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013621 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013622 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13623 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013624 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013625 final long identity = Binder.clearCallingIdentity();
13626 try {
13627 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13628 callback);
13629 } finally {
13630 Binder.restoreCallingIdentity(identity);
13631 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013632 }
13633
Sarah Chindf715ec2023-02-13 13:46:24 -080013634 /**
13635 * Request to get whether satellite communication is allowed for the current location.
13636 *
13637 * @param subId The subId of the subscription to check whether satellite communication is
13638 * allowed for the current location for.
13639 * @param result The result receiver that returns whether satellite communication is allowed
13640 * for the current location if the request is successful or an error code
13641 * if the request failed.
13642 *
13643 * @throws SecurityException if the caller doesn't have the required permission.
13644 */
13645 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013646 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013647 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013648 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013649 final long identity = Binder.clearCallingIdentity();
13650 try {
13651 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13652 false);
13653 } finally {
13654 Binder.restoreCallingIdentity(identity);
13655 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013656 }
13657
13658 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013659 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013660 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013661 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013662 * be visible if the request is successful or an error code if the request failed.
13663 *
13664 * @throws SecurityException if the caller doesn't have the required permission.
13665 */
13666 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013667 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013668 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013669 final long identity = Binder.clearCallingIdentity();
13670 try {
13671 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13672 } finally {
13673 Binder.restoreCallingIdentity(identity);
13674 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013675 }
13676
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013677 /**
joonhunshin59104152024-09-11 09:55:35 +000013678 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013679 *
joonhunshin59104152024-09-11 09:55:35 +000013680 * @param isAligned {@code true} Device is aligned with the satellite.
13681 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013682 *
13683 * @throws SecurityException if the caller doesn't have required permission.
13684 */
13685 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13686
joonhunshin83da7cd2024-08-22 08:53:35 +000013687 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013688 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13689 final long identity = Binder.clearCallingIdentity();
13690 try {
13691 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13692 } finally {
13693 Binder.restoreCallingIdentity(identity);
13694 }
Hakjun Choiae365972023-04-25 11:00:31 +000013695 }
13696
13697 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013698 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13699 * by modem.
13700 *
13701 * @param subId The subId of the subscription to request for.
13702 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013703 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013704 * operation.
13705 *
13706 * @throws SecurityException if the caller doesn't have required permission.
13707 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013708 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013709 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13710 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013711 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013712 final long identity = Binder.clearCallingIdentity();
13713 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013714 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013715 } finally {
13716 Binder.restoreCallingIdentity(identity);
13717 }
13718 }
13719
13720 /**
13721 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13722 * by modem.
13723 *
13724 * @param subId The subId of the subscription to request for.
13725 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013726 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013727 * operation.
13728 *
13729 * @throws SecurityException if the caller doesn't have required permission.
13730 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013731 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013732 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13733 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013734 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013735 final long identity = Binder.clearCallingIdentity();
13736 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013737 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013738 } finally {
13739 Binder.restoreCallingIdentity(identity);
13740 }
13741 }
13742
13743 /**
13744 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013745 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013746 *
13747 * @param subId The subId of the subscription to request for.
13748 *
13749 * @return Integer array of reasons for disallowing satellite communication.
13750 *
13751 * @throws SecurityException if the caller doesn't have the required permission.
13752 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013753 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013754 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013755 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013756 final long identity = Binder.clearCallingIdentity();
13757 try {
13758 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013759 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013760 return reasonSet.stream().mapToInt(i->i).toArray();
13761 } finally {
13762 Binder.restoreCallingIdentity(identity);
13763 }
13764 }
13765
13766 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013767 * Request to get the signal strength of the satellite connection.
13768 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013769 * @param result Result receiver to get the error code of the request and the current signal
13770 * strength of the satellite connection.
13771 *
13772 * @throws SecurityException if the caller doesn't have required permission.
13773 */
13774 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013775 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013776 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13777 final long identity = Binder.clearCallingIdentity();
13778 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013779 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013780 } finally {
13781 Binder.restoreCallingIdentity(identity);
13782 }
13783 }
13784
13785 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013786 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13787 * is not successful, a {@link ServiceSpecificException} that contains
13788 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013789 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013790 * @param callback The callback to handle the NTN signal strength changed event. If the
13791 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13792 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13793 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13794 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013795 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013796 * @throws SecurityException If the caller doesn't have the required permission.
13797 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013798 */
13799 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013800 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013801 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013802 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13803 final long identity = Binder.clearCallingIdentity();
13804 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013805 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013806 } finally {
13807 Binder.restoreCallingIdentity(identity);
13808 }
13809 }
13810
13811 /**
13812 * Unregisters for NTN signal strength changed from satellite modem.
13813 * If callback was not registered before, the request will be ignored.
13814 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013815 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013816 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013817 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013818 *
13819 * @throws SecurityException if the caller doesn't have the required permission.
13820 */
13821 @Override
13822 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013823 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013824 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13825 final long identity = Binder.clearCallingIdentity();
13826 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013827 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013828 } finally {
13829 Binder.restoreCallingIdentity(identity);
13830 }
13831 }
13832
13833 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013834 * Registers for satellite capabilities change event from the satellite service.
13835 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013836 * @param callback The callback to handle the satellite capabilities changed event.
13837 *
13838 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13839 *
13840 * @throws SecurityException if the caller doesn't have required permission.
13841 */
13842 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013843 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013844 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013845 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013846 final long identity = Binder.clearCallingIdentity();
13847 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013848 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013849 } finally {
13850 Binder.restoreCallingIdentity(identity);
13851 }
13852 }
13853
13854 /**
13855 * Unregisters for satellite capabilities change event from the satellite service.
13856 * If callback was not registered before, the request will be ignored.
13857 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013858 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013859 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013860 *
13861 * @throws SecurityException if the caller doesn't have required permission.
13862 */
13863 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013864 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013865 @NonNull ISatelliteCapabilitiesCallback callback) {
13866 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013867 final long identity = Binder.clearCallingIdentity();
13868 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013869 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013870 } finally {
13871 Binder.restoreCallingIdentity(identity);
13872 }
13873 }
13874
13875 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013876 * Registers for the satellite supported state changed.
13877 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013878 * @param callback The callback to handle the satellite supported state changed event.
13879 *
13880 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13881 *
13882 * @throws SecurityException if the caller doesn't have the required permission.
13883 */
13884 @Override
13885 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013886 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013887 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013888 final long identity = Binder.clearCallingIdentity();
13889 try {
13890 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
13891 } finally {
13892 Binder.restoreCallingIdentity(identity);
13893 }
Hakjun Choif92ac752024-03-18 19:34:29 +000013894 }
13895
13896 /**
13897 * Unregisters for the satellite supported state changed.
13898 * If callback was not registered before, the request will be ignored.
13899 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013900 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013901 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000013902 *
13903 * @throws SecurityException if the caller doesn't have the required permission.
13904 */
13905 @Override
13906 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013907 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013908 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013909 final long identity = Binder.clearCallingIdentity();
13910 try {
13911 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
13912 } finally {
13913 Binder.restoreCallingIdentity(identity);
13914 }
Hakjun Choif92ac752024-03-18 19:34:29 +000013915 }
13916
13917 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013918 * This API can be used by only CTS to update satellite vendor service package name.
13919 *
13920 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013921 * @param provisioned Whether satellite should be provisioned or not.
13922 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013923 * @return {@code true} if the satellite vendor service is set successfully,
13924 * {@code false} otherwise.
13925 */
Hakjun Choic3393242024-06-26 18:02:08 +000013926 public boolean setSatelliteServicePackageName(String servicePackageName,
13927 String provisioned) {
13928 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13929 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013930 TelephonyPermissions.enforceShellOnly(
13931 Binder.getCallingUid(), "setSatelliteServicePackageName");
13932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13933 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13934 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000013935 final long identity = Binder.clearCallingIdentity();
13936 try {
13937 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13938 provisioned);
13939 } finally {
13940 Binder.restoreCallingIdentity(identity);
13941 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013942 }
13943
13944 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013945 * This API can be used by only CTS to update satellite gateway service package name.
13946 *
13947 * @param servicePackageName The package name of the satellite gateway service.
13948 * @return {@code true} if the satellite gateway service is set successfully,
13949 * {@code false} otherwise.
13950 */
13951 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13952 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13953 TelephonyPermissions.enforceShellOnly(
13954 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13956 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13957 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000013958 final long identity = Binder.clearCallingIdentity();
13959 try {
13960 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13961 } finally {
13962 Binder.restoreCallingIdentity(identity);
13963 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013964 }
13965
13966 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013967 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13968 *
13969 * @param packageName The package name of the satellite pointing UI app.
13970 * @param className The class name of the satellite pointing UI app.
13971 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13972 * {@code false} otherwise.
13973 */
13974 public boolean setSatellitePointingUiClassName(
13975 @Nullable String packageName, @Nullable String className) {
13976 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13977 + ", className=" + className);
13978 TelephonyPermissions.enforceShellOnly(
13979 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13981 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000013982 "setSatellitePointingUiClassName");
13983 final long identity = Binder.clearCallingIdentity();
13984 try {
13985 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13986 } finally {
13987 Binder.restoreCallingIdentity(identity);
13988 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070013989 }
13990
13991 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013992 * This API can be used by only CTS to update the timeout duration in milliseconds that
13993 * satellite should stay at listening mode to wait for the next incoming page before disabling
13994 * listening mode.
13995 *
13996 * @param timeoutMillis The timeout duration in millisecond.
13997 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13998 */
13999 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14000 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14001 TelephonyPermissions.enforceShellOnly(
14002 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14004 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14005 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014006 final long identity = Binder.clearCallingIdentity();
14007 try {
14008 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14009 } finally {
14010 Binder.restoreCallingIdentity(identity);
14011 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014012 }
14013
14014 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014015 * This API can be used by only CTS to control ingoring cellular service state event.
14016 *
14017 * @param enabled Whether to enable boolean config.
14018 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14019 */
14020 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014021 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014022 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014023 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14025 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014026 "setSatelliteIgnoreCellularServiceState");
14027 final long identity = Binder.clearCallingIdentity();
14028 try {
14029 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14030 } finally {
14031 Binder.restoreCallingIdentity(identity);
14032 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014033 }
14034
14035 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014036 * This API can be used by only CTS to override the timeout durations used by the
14037 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014038 *
14039 * @param timeoutMillis The timeout duration in millisecond.
14040 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14041 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014042 public boolean setDatagramControllerTimeoutDuration(
14043 boolean reset, int timeoutType, long timeoutMillis) {
14044 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14045 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014046 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014047 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14049 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014050 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014051 final long identity = Binder.clearCallingIdentity();
14052 try {
14053 return mSatelliteController.setDatagramControllerTimeoutDuration(
14054 reset, timeoutType, timeoutMillis);
14055 } finally {
14056 Binder.restoreCallingIdentity(identity);
14057 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014058 }
14059
14060 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014061 * This API can be used by only CTS to override the boolean configs used by the
14062 * DatagramController module.
14063 *
14064 * @param enable Whether to enable or disable boolean config.
14065 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14066 */
14067 public boolean setDatagramControllerBooleanConfig(
14068 boolean reset, int booleanType, boolean enable) {
14069 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14070 + ", reset=" + reset + ", enable=" + enable);
14071 TelephonyPermissions.enforceShellOnly(
14072 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14074 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14075 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014076 final long identity = Binder.clearCallingIdentity();
14077 try {
14078 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14079 enable);
14080 } finally {
14081 Binder.restoreCallingIdentity(identity);
14082 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014083 }
14084
14085
14086 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014087 * This API can be used by only CTS to override the timeout durations used by the
14088 * SatelliteController module.
14089 *
14090 * @param timeoutMillis The timeout duration in millisecond.
14091 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14092 */
14093 public boolean setSatelliteControllerTimeoutDuration(
14094 boolean reset, int timeoutType, long timeoutMillis) {
14095 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14096 + reset + ", timeoutMillis=" + timeoutMillis);
14097 TelephonyPermissions.enforceShellOnly(
14098 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14100 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14101 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014102 final long identity = Binder.clearCallingIdentity();
14103 try {
14104 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14105 reset, timeoutType, timeoutMillis);
14106 } finally {
14107 Binder.restoreCallingIdentity(identity);
14108 }
Hakjun Choiae365972023-04-25 11:00:31 +000014109 }
14110
14111 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014112 * This API can be used in only testing to override connectivity status in monitoring emergency
14113 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14114 *
14115 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14116 * of the following values to enable the override:
14117 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14118 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14119 * To disable the override, use -1 for handoverType.
14120 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14121 * delaySeconds after the emergency call starts.
14122 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14123 */
14124 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14125 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14126 TelephonyPermissions.enforceShellOnly(
14127 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14129 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14130 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014131 final long identity = Binder.clearCallingIdentity();
14132 try {
14133 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14134 handoverType, delaySeconds);
14135 } finally {
14136 Binder.restoreCallingIdentity(identity);
14137 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014138 }
14139
14140 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014141 * This API can be used in only testing to override oem-enabled satellite provision status.
14142 *
14143 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14144 * otherwise.
14145 * @param isProvisioned The overriding provision status.
14146 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14147 */
14148 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14149 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14150 + ", isProvisioned=" + isProvisioned);
14151 TelephonyPermissions.enforceShellOnly(
14152 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14154 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14155 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014156 final long identity = Binder.clearCallingIdentity();
14157 try {
14158 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14159 } finally {
14160 Binder.restoreCallingIdentity(identity);
14161 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014162 }
14163
14164 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014165 * This API should be used by only CTS tests to forcefully set telephony country codes.
14166 *
14167 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14168 */
14169 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14170 Map cachedNetworkCountryCodes, String locationCountryCode,
14171 long locationCountryCodeTimestampNanos) {
14172 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14173 + String.join(", ", currentNetworkCountryCodes)
14174 + ", locationCountryCode=" + locationCountryCode
14175 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14176 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14177 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014180 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14181 final long identity = Binder.clearCallingIdentity();
14182 try {
14183 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14184 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14185 cachedNetworkCountryCodes, locationCountryCode,
14186 locationCountryCodeTimestampNanos);
14187 } finally {
14188 Binder.restoreCallingIdentity(identity);
14189 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014190 }
14191
14192 /**
14193 * This API should be used by only CTS tests to override the overlay configs of satellite
14194 * access controller.
14195 *
14196 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14197 * otherwise.
14198 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14199 */
14200 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14201 String s2CellFile, long locationFreshDurationNanos,
14202 List<String> satelliteCountryCodes) {
14203 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14204 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14205 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14206 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
14207 ? String.join(", ", satelliteCountryCodes) : null));
14208 TelephonyPermissions.enforceShellOnly(
14209 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14211 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14212 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014213 final long identity = Binder.clearCallingIdentity();
14214 try {
14215 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
14216 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
14217 } finally {
14218 Binder.restoreCallingIdentity(identity);
14219 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014220 }
14221
14222 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014223 * This API can be used by only CTS to override the cached value for the device overlay config
14224 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14225 * outgoing satellite datagrams should be sent to modem in demo mode.
14226 *
14227 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14228 * satellite modem or not.
14229 *
14230 * @return {@code true} if the operation is successful, {@code false} otherwise.
14231 */
14232 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14233 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14234 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14235 + "disabled");
14236 return false;
14237 }
14238 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14239 TelephonyPermissions.enforceShellOnly(
14240 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14242 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14243 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014244 final long identity = Binder.clearCallingIdentity();
14245 try {
14246 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14247 shouldSendToModemInDemoMode);
14248 } finally {
14249 Binder.restoreCallingIdentity(identity);
14250 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014251 }
14252
14253 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014254 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14255 *
14256 * @param state a state indicates whether satellite access allowed state should be cached and
14257 * the allowed state.
14258 * @return {@code true} if the setting is successful, {@code false} otherwise.
14259 */
14260 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14261 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14262 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14263 + "oemEnabledSatelliteFlag is disabled");
14264 return false;
14265 }
14266
14267 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14268 + "state=" + state);
14269 TelephonyPermissions.enforceShellOnly(
14270 Binder.getCallingUid(),
14271 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14273 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14274 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014275 final long identity = Binder.clearCallingIdentity();
14276 try {
14277 return mSatelliteAccessController
14278 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14279 } finally {
14280 Binder.restoreCallingIdentity(identity);
14281 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014282 }
14283
14284 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014285 * Sets the service defined in ComponentName to be bound.
14286 *
14287 * This should only be used for testing.
14288 * @return {@code true} if the DomainSelectionService to bind to was set,
14289 * {@code false} otherwise.
14290 */
14291 @Override
14292 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14293 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14294
14295 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14296 "setDomainSelectionServiceOverride");
14297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14298 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14299
14300 final long identity = Binder.clearCallingIdentity();
14301 try {
14302 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14303 return DomainSelectionResolver.getInstance()
14304 .setDomainSelectionServiceOverride(componentName);
14305 }
14306 } finally {
14307 Binder.restoreCallingIdentity(identity);
14308 }
14309 return false;
14310 }
14311
14312 /**
14313 * Clears the DomainSelectionService override.
14314 *
14315 * This should only be used for testing.
14316 * @return {@code true} if the DomainSelectionService override was cleared,
14317 * {@code false} otherwise.
14318 */
14319 @Override
14320 public boolean clearDomainSelectionServiceOverride() {
14321 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14322
14323 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14324 "clearDomainSelectionServiceOverride");
14325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14326 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14327
14328 final long identity = Binder.clearCallingIdentity();
14329 try {
14330 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14331 return DomainSelectionResolver.getInstance()
14332 .clearDomainSelectionServiceOverride();
14333 }
14334 } finally {
14335 Binder.restoreCallingIdentity(identity);
14336 }
14337 return false;
14338 }
14339
14340 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014341 * Enable or disable notifications sent for cellular identifier disclosure events.
14342 *
14343 * Disclosure events are defined as instances where a device has sent a cellular identifier
14344 * on the Non-access stratum (NAS) before a security context is established. As a result the
14345 * identifier is sent in the clear, which has privacy implications for the user.
14346 *
14347 * @param enable if notifications about disclosure events should be enabled
14348 * @throws SecurityException if the caller does not have the required privileges
14349 * @throws UnsupportedOperationException if the modem does not support this feature.
14350 */
14351 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014352 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014353 enforceModifyPermission();
14354 checkForIdentifierDisclosureNotificationSupport();
14355
14356 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14357 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14358 editor.apply();
14359
14360 // Each phone instance is responsible for updating its respective modem immediately
14361 // after we've made a preference change.
14362 for (Phone phone : PhoneFactory.getPhones()) {
14363 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14364 }
14365 }
14366
14367 /**
14368 * Get whether or not cellular identifier disclosure notifications are enabled.
14369 *
14370 * @throws SecurityException if the caller does not have the required privileges
14371 * @throws UnsupportedOperationException if the modem does not support this feature.
14372 */
14373 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014374 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014375 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14376 checkForIdentifierDisclosureNotificationSupport();
14377 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14378 }
14379
14380 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014381 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14382 * are in use by the cellular modem.
14383 *
14384 * @throws IllegalStateException if the Telephony process is not currently available
14385 * @throws SecurityException if the caller does not have the required privileges
14386 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14387 * and integrity algorithms in use
14388 * @hide
14389 */
14390 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014391 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014392 enforceModifyPermission();
14393 checkForNullCipherNotificationSupport();
14394
14395 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14396 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14397 editor.apply();
14398
14399 // Each phone instance is responsible for updating its respective modem immediately
14400 // after a preference change.
14401 for (Phone phone : PhoneFactory.getPhones()) {
14402 phone.handleNullCipherNotificationPreferenceChanged();
14403 }
14404 }
14405
14406 /**
14407 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14408 * cellular modem.
14409 *
14410 * @throws IllegalStateException if the Telephony process is not currently available
14411 * @throws SecurityException if the caller does not have the required privileges
14412 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14413 * and integrity algorithms in use
14414 * @hide
14415 */
14416 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14417 public boolean isNullCipherNotificationsEnabled() {
14418 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14419 checkForNullCipherNotificationSupport();
14420 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14421 }
14422
14423 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014424 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14425 *
14426 * <p>This method behaves in one of the following ways:
14427 * <ul>
14428 * <li>return true : if the calling package has the appop permission {@link
14429 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14430 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14431 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14432 * Owner device identifier access check, or the calling package has carrier privileges</>
14433 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14434 * </ul>
14435 */
14436 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14437 String callingPackage, @Nullable String callingFeatureId, String message) {
14438 for (Phone phone : PhoneFactory.getPhones()) {
14439 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14440 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14441 return true;
14442 }
14443 }
14444 return false;
14445 }
arunvoddud7401012022-12-15 16:08:12 +000014446
14447 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014448 * @return The subscription manager service instance.
14449 */
14450 public SubscriptionManagerService getSubscriptionManagerService() {
14451 return SubscriptionManagerService.getInstance();
14452 }
14453
14454 /**
arunvoddud7401012022-12-15 16:08:12 +000014455 * Class binds the consumer[callback] and carrierId.
14456 */
14457 private static class CallerCallbackInfo {
14458 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014459 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014460
Steve Statia28b7cb32024-03-11 23:58:50 +000014461 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014462 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014463 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014464 }
14465
14466 public Consumer<Integer> getConsumer() {
14467 return mConsumer;
14468 }
14469
Steve Statia28b7cb32024-03-11 23:58:50 +000014470 public Set<Integer> getCarrierIds() {
14471 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014472 }
14473 }
joonhunshin4ac60942023-11-15 15:23:39 +000014474
14475 /*
14476 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14477 * But the context that is passed in is unused if the phone app is already alive.
14478 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14479 */
14480 @VisibleForTesting
14481 public void setPackageManager(PackageManager packageManager) {
14482 mPackageManager = packageManager;
14483 }
14484
14485 /*
Nate Myren453c3472024-03-13 11:28:11 -070014486 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14487 * But the context that is passed in is unused if the phone app is already alive.
14488 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14489 */
14490 @VisibleForTesting
14491 public void setAppOpsManager(AppOpsManager appOps) {
14492 mAppOps = appOps;
14493 }
14494
14495 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014496 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14497 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14498 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14499 */
14500 @VisibleForTesting
14501 public void setFeatureFlags(FeatureFlags featureFlags) {
14502 mFeatureFlags = featureFlags;
14503 }
14504
14505 /**
14506 * Make sure the device has required telephony feature
14507 *
14508 * @throws UnsupportedOperationException if the device does not have required telephony feature
14509 */
14510 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14511 @NonNull String telephonyFeature, @NonNull String methodName) {
14512 if (callingPackage == null || mPackageManager == null) {
14513 return;
14514 }
14515
14516 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14517 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014518 Binder.getCallingUserHandle())
14519 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14520 // Skip to check associated telephony feature,
14521 // if compatibility change is not enabled for the current process or
14522 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014523 return;
14524 }
14525
14526 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14527 throw new UnsupportedOperationException(
14528 methodName + " is unsupported without " + telephonyFeature);
14529 }
14530 }
youngtaecha5d483d52024-04-29 17:05:45 +000014531
14532 /**
14533 * Registers for the satellite communication allowed state changed.
14534 *
14535 * @param subId The subId of the subscription to register for the satellite communication
14536 * allowed state changed.
14537 * @param callback The callback to handle the satellite communication allowed
14538 * state changed event.
14539 *
14540 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14541 *
14542 * @throws SecurityException if the caller doesn't have the required permission.
14543 */
14544 @Override
14545 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14546 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14547 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014548 final long identity = Binder.clearCallingIdentity();
14549 try {
14550 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14551 subId, callback);
14552 } finally {
14553 Binder.restoreCallingIdentity(identity);
14554 }
youngtaecha5d483d52024-04-29 17:05:45 +000014555 }
14556
14557 /**
14558 * Unregisters for the satellite communication allowed state changed.
14559 * If callback was not registered before, the request will be ignored.
14560 *
14561 * @param subId The subId of the subscription to unregister for the satellite communication
14562 * allowed state changed.
14563 * @param callback The callback that was passed to
14564 * {@link #registerForCommunicationAllowedStateChanged(int,
14565 * ISatelliteCommunicationAllowedStateCallback)}. *
14566 * @throws SecurityException if the caller doesn't have the required permission.
14567 */
14568 @Override
14569 public void unregisterForCommunicationAllowedStateChanged(
14570 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14571 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014572 final long identity = Binder.clearCallingIdentity();
14573 try {
14574 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14575 callback);
14576 } finally {
14577 Binder.restoreCallingIdentity(identity);
14578 }
youngtaecha5d483d52024-04-29 17:05:45 +000014579 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014580
14581 /**
14582 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14583 *
14584 * @param subId The subId of the subscription to the satellite session stats for.
14585 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14586 * if the request is successful or an error code if the request failed.
14587 *
14588 * @throws SecurityException if the caller doesn't have required permission.
14589 */
14590 @Override
14591 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14592 enforceModifyPermission();
14593 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014594 final long identity = Binder.clearCallingIdentity();
14595 try {
14596 mSatelliteController.requestSatelliteSessionStats(subId, result);
14597 } finally {
14598 Binder.restoreCallingIdentity(identity);
14599 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014600 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014601
14602 /**
14603 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14604 *
14605 * @param result The result receiver, which returns the list of prioritized satellite tokens
14606 * to be used for provision if the request is successful or an error code if the request failed.
14607 *
14608 * @throws SecurityException if the caller doesn't have the required permission.
14609 */
14610 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014611 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14612 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014613 final long identity = Binder.clearCallingIdentity();
14614 try {
14615 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14616 } finally {
14617 Binder.restoreCallingIdentity(identity);
14618 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014619 }
14620
14621 /**
14622 * Deliver the list of provisioned satellite subscriber ids.
14623 *
14624 * @param list List of provisioned satellite subscriber ids.
14625 * @param result The result receiver that returns whether deliver success or fail.
14626 *
14627 * @throws SecurityException if the caller doesn't have the required permission.
14628 */
14629 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014630 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014631 @NonNull ResultReceiver result) {
14632 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014633 final long identity = Binder.clearCallingIdentity();
14634 try {
14635 mSatelliteController.provisionSatellite(list, result);
14636 } finally {
14637 Binder.restoreCallingIdentity(identity);
14638 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014639 }
Hyosund6aaf062024-08-23 23:02:10 +000014640
14641 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014642 * Deliver the list of deprovisioned satellite subscriber ids.
14643 *
14644 * @param list List of deprovisioned satellite subscriber ids.
14645 * @param result The result receiver that returns whether deliver success or fail.
14646 *
14647 * @throws SecurityException if the caller doesn't have the required permission.
14648 */
14649 @Override
14650 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14651 @NonNull ResultReceiver result) {
14652 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14653 final long identity = Binder.clearCallingIdentity();
14654 try {
14655 mSatelliteController.deprovisionSatellite(list, result);
14656 } finally {
14657 Binder.restoreCallingIdentity(identity);
14658 }
14659 }
14660
14661 /**
Hyosund6aaf062024-08-23 23:02:10 +000014662 * This API can be used by only CTS to override the cached value for the device overlay config
14663 * value :
14664 * config_satellite_gateway_service_package and
14665 * config_satellite_carrier_roaming_esos_provisioned_class.
14666 * These values are set before sending an intent to broadcast there are any change to list of
14667 * subscriber informations.
14668 *
14669 * @param name the name is one of the following that constitute an intent.
14670 * Component package name, or component class name.
14671 * @return {@code true} if the setting is successful, {@code false} otherwise.
14672 */
14673 @Override
14674 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14675 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14676 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14677 + " carrierRoamingNbIotNtn is disabled");
14678 return false;
14679 }
14680 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14681 TelephonyPermissions.enforceShellOnly(
14682 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14684 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14685 "setSatelliteSubscriberIdListChangedIntentComponent");
14686 final long identity = Binder.clearCallingIdentity();
14687 try {
14688 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14689 } finally {
14690 Binder.restoreCallingIdentity(identity);
14691 }
14692 }
Jack Yu26735292024-09-25 14:33:49 -070014693
14694 /**
14695 * This API can be used by only CTS to override the Euicc UI component.
14696 *
14697 * @param componentName ui component to be launched for testing. {@code null} to reset.
14698 *
14699 * @hide
14700 */
14701 @Override
14702 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14703 enforceModifyPermission();
14704 log("setTestEuiccUiComponent: " + componentName);
14705 mTestEuiccUiComponent = componentName;
14706 }
14707
14708 /**
14709 * This API can be used by only CTS to retrieve the Euicc UI component.
14710 *
14711 * @return Euicc UI component. {@code null} if not available.
14712 * @hide
14713 */
14714 @Override
14715 @Nullable
14716 public ComponentName getTestEuiccUiComponent() {
14717 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14718 return mTestEuiccUiComponent;
14719 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014720
14721 /**
14722 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14723 *
14724 * @param state to update Ntn Eligibility.
14725 * @param resetRequired to reset the overridden flag in satellite controller.
14726 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14727 */
14728 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14729 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014730 final long identity = Binder.clearCallingIdentity();
14731 try {
14732 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14733 resetRequired);
14734 } finally {
14735 Binder.restoreCallingIdentity(identity);
14736 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014737 }
Jack Yufa8ed012023-02-11 15:42:28 -080014738}