blob: d7f793953e0be89ccbcf35b27b002f8b3aa6c48c [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.
6643 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006644 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006645 * @param featureTypes An integer array of feature types associated with a packageName.
6646 * @param packageName The name of the package that the current configuration will be replaced
6647 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006648 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006649 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6651 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006654 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 final long identity = Binder.clearCallingIdentity();
6657 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006658 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006659 // may happen if the device does not support IMS.
6660 return false;
6661 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 Map<Integer, String> featureConfig = new HashMap<>();
6663 for (int featureType : featureTypes) {
6664 featureConfig.put(featureType, packageName);
6665 }
6666 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6667 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006671 }
6672
6673 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006674 * Clears any carrier ImsService overrides for the slot index specified that were previously
6675 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6676 *
6677 * This should only be used for testing.
6678 *
6679 * @param slotIndex the slot ID that the ImsService should bind for.
6680 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6681 */
6682 @Override
6683 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6685 "clearCarrierImsServiceOverride");
6686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006687 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006688
6689 final long identity = Binder.clearCallingIdentity();
6690 try {
6691 if (mImsResolver == null) {
6692 // may happen if the device does not support IMS.
6693 return false;
6694 }
6695 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6696 } finally {
6697 Binder.restoreCallingIdentity(identity);
6698 }
6699 }
6700
6701 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006702 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006703 *
6704 * @param slotId The slot that the ImsService is associated with.
6705 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6706 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006707 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006708 * @return the package name of the ImsService configuration.
6709 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006710 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6711 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006712 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006713 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6714 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006719 // may happen if the device does not support IMS.
6720 return "";
6721 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006722 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006723 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6724 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006728 }
6729
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006730 /**
6731 * Get the MmTelFeature state associated with the requested subscription id.
6732 * @param subId The subscription that the MmTelFeature is associated with.
6733 * @param callback A callback with an integer containing the
6734 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6735 */
6736 @Override
6737 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6738 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006739 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6741 "IMS not available on device.");
6742 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006743 final long token = Binder.clearCallingIdentity();
6744 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006745 int slotId = getSlotIndex(subId);
6746 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6747 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6748 + subId + "'");
6749 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6750 }
6751 verifyImsMmTelConfiguredOrThrow(slotId);
6752 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6753 try {
6754 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6755 } catch (RemoteException e) {
6756 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6757 + "Ignore");
6758 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006759 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006760 } catch (ImsException e) {
6761 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006762 } finally {
6763 Binder.restoreCallingIdentity(token);
6764 }
6765 }
6766
Daniel Brightbb5840b2021-01-12 15:48:18 -08006767 /**
6768 * Sets the ims registration state on all valid {@link Phone}s.
6769 */
6770 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006771 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006775 // NOTE: Before S, this method only set the default phone.
6776 for (final Phone phone : PhoneFactory.getPhones()) {
6777 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6778 phone.setImsRegistrationState(registered);
6779 }
6780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
Wink Saville36469e72014-06-11 15:17:00 -07006784 }
6785
6786 /**
Stuart Scott54788802015-03-30 13:18:01 -07006787 * Set the network selection mode to automatic.
6788 *
6789 */
6790 @Override
6791 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6793 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794
joonhunshin4ac60942023-11-15 15:23:39 +00006795 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6796 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 final long identity = Binder.clearCallingIdentity();
6799 try {
shilufc958392020-01-20 11:36:01 -08006800 if (!isActiveSubscription(subId)) {
6801 return;
6802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006804 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006805 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
Stuart Scott54788802015-03-30 13:18:01 -07006809 }
6810
Jack Yud10cdd42020-09-28 20:28:01 -07006811 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006812 * Ask the radio to connect to the input network and change selection mode to manual.
6813 *
6814 * @param subId the id of the subscription.
6815 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6816 * the operator to attach to.
6817 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6818 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6819 * normal network selection next time.
6820 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006821 */
6822 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006823 public boolean setNetworkSelectionModeManual(
6824 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6826 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006827
joonhunshin4ac60942023-11-15 15:23:39 +00006828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6829 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6830
Jack Yu285100e2022-12-02 22:48:35 -08006831 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006832 if (!isActiveSubscription(subId)) {
6833 return false;
6834 }
6835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006837 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006839 if (DBG) {
6840 log("setNetworkSelectionModeManual: subId: " + subId
6841 + " operator: " + operatorInfo);
6842 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006843 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6844 } finally {
6845 Binder.restoreCallingIdentity(identity);
6846 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006847 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006848 /**
shilu84f6e8b2019-12-19 13:58:01 -08006849 * Get the manual network selection
6850 *
6851 * @param subId the id of the subscription.
6852 *
6853 * @return the previously saved user selected PLMN
6854 */
6855 @Override
6856 public String getManualNetworkSelectionPlmn(int subId) {
6857 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006858 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6859 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006860
joonhunshin4ac60942023-11-15 15:23:39 +00006861 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6862 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6863
shilu84f6e8b2019-12-19 13:58:01 -08006864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006867 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006868 }
6869
6870 final Phone phone = getPhone(subId);
6871 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006872 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006873 }
6874 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6875 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006876 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006881
6882 /**
6883 * Scans for available networks.
6884 */
6885 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006886 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6887 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6889 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006890 LocationAccessPolicy.LocationPermissionResult locationResult =
6891 LocationAccessPolicy.checkLocationPermission(mApp,
6892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6893 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006895 .setCallingPid(Binder.getCallingPid())
6896 .setCallingUid(Binder.getCallingUid())
6897 .setMethod("getCellNetworkScanResults")
6898 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006899 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6900 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006901 .build());
6902 switch (locationResult) {
6903 case DENIED_HARD:
6904 throw new SecurityException("Not allowed to access scan results -- location");
6905 case DENIED_SOFT:
6906 return null;
6907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908
Pengquan Menga1bb6272018-09-06 09:59:22 -07006909 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 try {
6911 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006912 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006917 }
6918
6919 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006920 * Get the call forwarding info, given the call forwarding reason.
6921 */
6922 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006923 public void getCallForwarding(int subId, int callForwardingReason,
6924 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006925 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006926
6927 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6928 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6929
Shuo Qian4a594052020-01-23 11:59:30 -08006930 long identity = Binder.clearCallingIdentity();
6931 try {
6932 if (DBG) {
6933 log("getCallForwarding: subId " + subId
6934 + " callForwardingReason" + callForwardingReason);
6935 }
Hall Liu27d24262020-09-18 19:04:59 -07006936
6937 Phone phone = getPhone(subId);
6938 if (phone == null) {
6939 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006940 callback.onError(
6941 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006942 } catch (RemoteException e) {
6943 // ignore
6944 }
6945 return;
6946 }
6947
6948 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6949 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6950 @Override
6951 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6952 try {
6953 callback.onCallForwardingInfoAvailable(info);
6954 } catch (RemoteException e) {
6955 // ignore
6956 }
6957 }
6958
6959 @Override
6960 public void onError(int error) {
6961 try {
6962 callback.onError(error);
6963 } catch (RemoteException e) {
6964 // ignore
6965 }
6966 }
6967 });
6968 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
6972 }
6973
6974 /**
6975 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6976 * reason, the number to forward, and the timeout before the forwarding is attempted.
6977 */
6978 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006979 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6980 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006981 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006982
6983 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6984 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6985
Shuo Qian4a594052020-01-23 11:59:30 -08006986 long identity = Binder.clearCallingIdentity();
6987 try {
6988 if (DBG) {
6989 log("setCallForwarding: subId " + subId
6990 + " callForwardingInfo" + callForwardingInfo);
6991 }
Hall Liu27d24262020-09-18 19:04:59 -07006992
6993 Phone phone = getPhone(subId);
6994 if (phone == null) {
6995 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006996 callback.accept(
6997 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006998 } catch (RemoteException e) {
6999 // ignore
7000 }
7001 return;
7002 }
7003
7004 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7005 FunctionalUtils.ignoreRemoteException(callback::accept));
7006
7007 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
7012
7013 /**
Hall Liu27d24262020-09-18 19:04:59 -07007014 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007015 */
7016 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007017 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007018 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007019
7020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7021 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7022
Shuo Qian4a594052020-01-23 11:59:30 -08007023 long identity = Binder.clearCallingIdentity();
7024 try {
Hall Liu27d24262020-09-18 19:04:59 -07007025 Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 try {
7028 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7029 } catch (RemoteException e) {
7030 // ignore
7031 }
7032 return;
7033 }
SongFerngWang0e767992021-03-31 22:08:45 +08007034 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7035 PersistableBundle c = configManager.getConfigForSubId(subId);
7036 boolean requireUssd = c.getBoolean(
7037 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007038
Shuo Qian4a594052020-01-23 11:59:30 -08007039 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007040 if (requireUssd) {
7041 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7042 getSubscriptionCarrierId(subId));
7043 String newUssdCommand = "";
7044 try {
7045 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007046 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007047 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7048 } catch (NullPointerException e) {
7049 loge("Failed to generate USSD number" + e);
7050 }
7051 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7052 mMainThreadHandler, callback, carrierXmlParser,
7053 CarrierXmlParser.SsEntry.SSAction.QUERY);
7054 final String ussdCommand = newUssdCommand;
7055 Executors.newSingleThreadExecutor().execute(() -> {
7056 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7057 });
7058 } else {
7059 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7060 callback::accept);
7061 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7062 }
Shuo Qian4a594052020-01-23 11:59:30 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
7067
7068 /**
Hall Liu27d24262020-09-18 19:04:59 -07007069 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007070 */
7071 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007072 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007073 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007074
7075 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7076 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7077
Shuo Qian4a594052020-01-23 11:59:30 -08007078 long identity = Binder.clearCallingIdentity();
7079 try {
Hall Liu27d24262020-09-18 19:04:59 -07007080 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7081
7082 Phone phone = getPhone(subId);
7083 if (phone == null) {
7084 try {
7085 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7086 } catch (RemoteException e) {
7087 // ignore
7088 }
7089 return;
7090 }
7091
SongFerngWang0e767992021-03-31 22:08:45 +08007092 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7093 PersistableBundle c = configManager.getConfigForSubId(subId);
7094 boolean requireUssd = c.getBoolean(
7095 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007096
SongFerngWang0e767992021-03-31 22:08:45 +08007097 if (DBG) log("getCallWaitingStatus: subId " + subId);
7098 if (requireUssd) {
7099 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7100 getSubscriptionCarrierId(subId));
7101 CarrierXmlParser.SsEntry.SSAction ssAction =
7102 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7103 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7104 String newUssdCommand = "";
7105 try {
7106 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007107 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007108 .makeCommand(ssAction, null);
7109 } catch (NullPointerException e) {
7110 loge("Failed to generate USSD number" + e);
7111 }
7112 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7113 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7114 final String ussdCommand = newUssdCommand;
7115 Executors.newSingleThreadExecutor().execute(() -> {
7116 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7117 });
7118 } else {
7119 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7120 FunctionalUtils.ignoreRemoteException(callback::accept));
7121
7122 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7123 }
Shuo Qian4a594052020-01-23 11:59:30 -08007124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
7127 }
7128
7129 /**
yinxub1bed742017-04-17 11:45:04 -07007130 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007131 *
yinxub1bed742017-04-17 11:45:04 -07007132 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007133 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7134 * location related information which will be sent if the caller already possess
7135 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007136 * @param request contains the radio access networks with bands/channels to scan
7137 * @param messenger callback messenger for scan results or errors
7138 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007139 * @return the id of the requested scan which can be used to stop the scan.
7140 */
7141 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007142 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7143 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007144 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7146 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007147 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007148 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7149 if (!renounceFineLocationAccess) {
7150 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7152 .setCallingPackage(callingPackage)
7153 .setCallingFeatureId(callingFeatureId)
7154 .setCallingPid(Binder.getCallingPid())
7155 .setCallingUid(Binder.getCallingUid())
7156 .setMethod("requestNetworkScan")
7157 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7159 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7160 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007161 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007162 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007163 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7164 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007165 if (e != null) {
7166 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7167 throw e;
7168 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007169 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007170 return TelephonyScanManager.INVALID_SCAN_ID;
7171 }
7172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 }
joonhunshin4ac60942023-11-15 15:23:39 +00007174
7175 enforceTelephonyFeatureWithException(callingPackage,
7176 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7177
Hall Liu912dfd32019-04-25 14:02:26 -07007178 int callingUid = Binder.getCallingUid();
7179 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007183 renounceFineLocationAccess, request, messenger, binder,
7184 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007185 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
yinxu504e1392017-04-12 16:03:22 -07007189 }
7190
Hall Liub2ac8ef2019-02-28 15:56:23 -08007191 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007192 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007193 boolean hasCarrierPriv;
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7197 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
Hall Liu558027f2019-05-15 19:14:05 -07007201 boolean hasNetworkScanPermission =
7202 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007203 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007204
7205 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7206 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7207 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007208 }
7209
7210 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7211 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007212 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7213 return new SecurityException("Specific channels must not be"
7214 + " scanned without location access.");
7215 }
7216 }
7217 }
7218
Hall Liub2ac8ef2019-02-28 15:56:23 -08007219 return null;
7220 }
7221
yinxu504e1392017-04-12 16:03:22 -07007222 /**
7223 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007224 *
7225 * @param subId id of the subscription
7226 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007227 */
7228 @Override
7229 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7231 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232
Hall Liu912dfd32019-04-25 14:02:26 -07007233 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 final long identity = Binder.clearCallingIdentity();
7235 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007236 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 } finally {
7238 Binder.restoreCallingIdentity(identity);
7239 }
yinxu504e1392017-04-12 16:03:22 -07007240 }
7241
7242 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007243 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007244 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007245 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007246 */
7247 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007248 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007249 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007250 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007251 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252
joonhunshin4ac60942023-11-15 15:23:39 +00007253 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7254 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007258 if (DBG) log("getAllowedNetworkTypesBitmask");
7259 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7260 int networkTypesBitmask = (result != null ? result[0] : -1);
7261 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7262 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 } finally {
7264 Binder.restoreCallingIdentity(identity);
7265 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007266 }
7267
7268 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007269 * Get the allowed network types for certain reason.
7270 *
7271 * @param subId the id of the subscription.
7272 * @param reason the reason the allowed network type change is taking place
7273 * @return the allowed network types.
7274 */
7275 @Override
7276 public long getAllowedNetworkTypesForReason(int subId,
7277 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007279 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007280
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007281 if (!mApp.getResources().getBoolean(
7282 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7284 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7285 "getAllowedNetworkTypesForReason");
7286 }
joonhunshin4ac60942023-11-15 15:23:39 +00007287
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007288 final long identity = Binder.clearCallingIdentity();
7289 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007290 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295
7296 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007297 * Enable/Disable E-UTRA-NR Dual Connectivity
7298 * @param subId subscription id of the sim card
7299 * @param nrDualConnectivityState expected NR dual connectivity state
7300 * This can be passed following states
7301 * <ol>
7302 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7303 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7304 * <li>Disable NR dual connectivity and force secondary cell to be released
7305 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7306 * </ol>
7307 * @return operation result.
7308 */
7309 @Override
7310 public int setNrDualConnectivityState(int subId,
7311 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7313 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007314 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007315 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7316 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7317 }
7318
Sooraj Sasindran37444802020-08-11 10:40:43 -07007319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7323 nrDualConnectivityState, subId,
7324 workSource);
7325 if (DBG) log("enableNRDualConnectivity result: " + result);
7326 return result;
7327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
7331
7332 /**
7333 * Is E-UTRA-NR Dual Connectivity enabled
7334 * @return true if dual connectivity is enabled else false
7335 */
7336 @Override
7337 public boolean isNrDualConnectivityEnabled(int subId) {
7338 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007339 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007340 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007341 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007342 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7343 return false;
7344 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007345 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7349 null, subId, workSource);
7350 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7351 return isEnabled;
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
7355 }
7356
7357 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007358 * Set the allowed network types of the device and
7359 * provide the reason triggering the allowed network change.
7360 *
7361 * @param subId the id of the subscription.
7362 * @param reason the reason the allowed network type change is taking place
7363 * @param allowedNetworkTypes the allowed network types.
7364 * @return true on success; false on any failure.
7365 */
7366 @Override
7367 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007368 @TelephonyManager.AllowedNetworkTypesReason int reason,
7369 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7371 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007372 // If the caller only has carrier privileges, then they should not be able to override
7373 // any network types which were set for security reasons.
7374 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7375 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007376 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007377 throw new SecurityException(
7378 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007379 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007380 }
joonhunshin4ac60942023-11-15 15:23:39 +00007381
7382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7383 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7384
SongFerngWang3ef3e072020-12-21 16:41:52 +08007385 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007386 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007387 return false;
7388 }
7389 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7390 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007391 return false;
7392 }
7393
Jack Yu5b494332023-01-23 18:18:04 +00007394 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7395 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007396
Jack Yue37dd262022-12-16 11:53:37 -08007397 Phone phone = getPhone(subId);
7398 if (phone == null) {
7399 return false;
7400 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007401
Jack Yue37dd262022-12-16 11:53:37 -08007402 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007403 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007404 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007405 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007406
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007407 final long identity = Binder.clearCallingIdentity();
7408 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007409 Boolean success = (Boolean) sendRequest(
7410 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7411 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7412
7413 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7414 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 }
7419
7420 /**
Miaoa84611c2019-03-15 09:21:10 +08007421 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007422 *
Miaoa84611c2019-03-15 09:21:10 +08007423 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007424 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007425 * @hide
7426 */
7427 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007428 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007429 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007430
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007431 if (!mApp.getResources().getBoolean(
7432 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7434 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7435 }
joonhunshin4ac60942023-11-15 15:23:39 +00007436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 try {
Miaoa84611c2019-03-15 09:21:10 +08007440 if (phone != null) {
7441 return phone.hasMatchedTetherApnSetting();
7442 } else {
7443 return false;
7444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 } finally {
7446 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007447 }
Junda Liu475951f2014-11-07 16:45:03 -08007448 }
7449
7450 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007451 * Get the user enabled state of Mobile Data.
7452 *
7453 * TODO: remove and use isUserDataEnabled.
7454 * This can't be removed now because some vendor codes
7455 * calls through ITelephony directly while they should
7456 * use TelephonyManager.
7457 *
7458 * @return true on enabled
7459 */
7460 @Override
7461 public boolean getDataEnabled(int subId) {
7462 return isUserDataEnabled(subId);
7463 }
7464
7465 /**
7466 * Get whether mobile data is enabled per user setting.
7467 *
7468 * There are other factors deciding whether mobile data is actually enabled, but they are
7469 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007470 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7472 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007473 *
7474 * @return {@code true} if data is enabled else {@code false}
7475 */
7476 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007477 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007478 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007479 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007480 try {
7481 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7482 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007483 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007484 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7485 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007486 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007488 mApp, subId, functionName);
7489
Robert Greenwalt646120a2014-05-23 11:54:03 -07007490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
Jack Yu285100e2022-12-02 22:48:35 -08007494 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7496 Phone phone = PhoneFactory.getPhone(phoneId);
7497 if (phone != null) {
7498 boolean retVal = phone.isUserDataEnabled();
7499 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7500 return retVal;
7501 } else {
7502 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7503 return false;
7504 }
7505 } finally {
7506 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007507 }
7508 }
7509
7510 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007511 * Checks if the device is capable of mobile data by considering whether whether the
7512 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7513 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007514 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007515 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007516 */
7517 @Override
7518 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007519 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007520 try {
7521 try {
7522 mApp.enforceCallingOrSelfPermission(
7523 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007524 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007525 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 try {
7527 mApp.enforceCallingOrSelfPermission(
7528 android.Manifest.permission.READ_PHONE_STATE,
7529 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007530 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007531 mApp.enforceCallingOrSelfPermission(
7532 permission.READ_BASIC_PHONE_STATE, functionName);
7533 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007534 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007535 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007536 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538
joonhunshin4ac60942023-11-15 15:23:39 +00007539 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7540 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 final long identity = Binder.clearCallingIdentity();
7543 try {
Jack Yu285100e2022-12-02 22:48:35 -08007544 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007546 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007547 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007548 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 return retVal;
7550 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007551 if (DBG) {
7552 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7553 + subId + " retVal=false");
7554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 return false;
7556 }
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007559 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007560 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007561
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007562 /**
7563 * Check if data is enabled for a specific reason
7564 * @param subId Subscription index
7565 * @param reason the reason the data enable change is taking place
7566 * @return {@code true} if the overall data is enabled; {@code false} if not.
7567 */
7568 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007569 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007570 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007571 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007572 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007573 try {
7574 mApp.enforceCallingOrSelfPermission(
7575 android.Manifest.permission.ACCESS_NETWORK_STATE,
7576 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007577 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007578 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7579 functionName);
7580 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007581 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007582 try {
7583 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007584 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007585 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007587 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007588 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007589 }
7590
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007591 if (!mApp.getResources().getBoolean(
7592 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7593 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7594 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7595 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007596
7597 final long identity = Binder.clearCallingIdentity();
7598 try {
Jack Yu285100e2022-12-02 22:48:35 -08007599 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007601 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 + " reason=" + reason);
7603 }
7604 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007605 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007606 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007607 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007608 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007609 return retVal;
7610 } else {
7611 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007612 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007613 + subId + " retVal=false");
7614 }
7615 return false;
7616 }
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007622 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007623 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7626
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007627 // No permission needed; this only lets the caller inspect their own status.
7628 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007629 }
Junda Liu29340342014-07-10 15:23:27 -07007630
7631 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007632 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007633 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007634
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007635 if (!mApp.getResources().getBoolean(
7636 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7637 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7638 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7639 "getCarrierPrivilegeStatusForUid");
7640 }
joonhunshin4ac60942023-11-15 15:23:39 +00007641
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007642 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7643 }
7644
7645 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7646 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007647 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007648 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007649 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7650 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007651 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7652 if (cpt == null) {
7653 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007654 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7655 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007656 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007657 }
7658
7659 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007660 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007661 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007662
7663 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7664 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7665
chen xuf7e9fe82019-05-09 19:31:02 -07007666 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007668 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007669 Phone phone = getPhone(subId);
7670 if (phone == null) {
7671 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7672 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7673 }
7674 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7675 if (cpt == null) {
7676 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007677 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7678 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007679 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007680 }
7681
7682 @Override
7683 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007684 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007685
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007686 if (!mApp.getResources().getBoolean(
7687 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7689 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7690 "checkCarrierPrivilegesForPackageAnyPhone");
7691 }
joonhunshin4ac60942023-11-15 15:23:39 +00007692
Rambo Wange7209ce2022-02-23 13:41:02 -08007693 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7694 }
7695
7696 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007697 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007699 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007700 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7702 Phone phone = PhoneFactory.getPhone(phoneId);
7703 if (phone == null) {
7704 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007705 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007706 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7707 if (cpt == null) {
7708 continue;
7709 }
7710 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007711 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7712 break;
7713 }
7714 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007715 return result;
Junda Liu29340342014-07-10 15:23:27 -07007716 }
Derek Tan89e89d42014-07-08 17:00:10 -07007717
7718 @Override
Junda Liue64de782015-04-16 17:19:16 -07007719 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007720 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007721
7722 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7723 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7724 "getCarrierPackageNamesForIntentAndPhone");
7725
Rambo Wang8a247eb2022-02-08 21:11:18 +00007726 Phone phone = PhoneFactory.getPhone(phoneId);
7727 if (phone == null) {
7728 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007729 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007730 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7731 if (cpt == null) {
7732 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007733 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007734 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007735 }
7736
Amith Yamasani6e118872016-02-19 12:53:51 -08007737 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007738 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007739 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007740
7741 enforceTelephonyFeatureWithException(
7742 getCurrentPackageName(),
7743 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7744 "getPackagesWithCarrierPrivileges");
7745
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007746 Phone phone = PhoneFactory.getPhone(phoneId);
7747 if (phone == null) {
7748 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007749 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007750 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7751 if (cpt == null) {
7752 return Collections.emptyList();
7753 }
7754 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007755 }
7756
chen xuf7e9fe82019-05-09 19:31:02 -07007757 @Override
7758 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007759 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007760
7761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7762 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7763 "getPackagesWithCarrierPrivilegesForAllPhones");
7764
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007765 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007766 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007767 try {
7768 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7769 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7770 }
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007773 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007774 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007775 }
7776
Rambo Wang6812ffb2022-03-15 16:54:17 -07007777 @Override
7778 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7779 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7780
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007781 if (!mApp.getResources().getBoolean(
7782 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7784 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7785 "getCarrierServicePackageNameForLogicalSlot");
7786 }
joonhunshin4ac60942023-11-15 15:23:39 +00007787
Rambo Wang6812ffb2022-03-15 16:54:17 -07007788 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7789 if (phone == null) {
7790 return null;
7791 }
7792 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7793 if (cpt == null) {
7794 return null;
7795 }
7796 return cpt.getCarrierServicePackageName();
7797 }
7798
Wink Savilleb564aae2014-10-23 10:18:09 -07007799 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007800 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007801 UiccPort port = phone == null ? null : phone.getUiccPort();
7802 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007803 return null;
7804 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007805 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007806 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007807 return null;
7808 }
7809 return iccId;
7810 }
7811
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007812 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007813 public void setCallComposerStatus(int subId, int status) {
7814 enforceModifyPermission();
7815
joonhunshin4ac60942023-11-15 15:23:39 +00007816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7817 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7818
Shuo Qiane4e11672020-12-15 22:15:33 -08007819 final long identity = Binder.clearCallingIdentity();
7820 try {
7821 Phone phone = getPhone(subId);
7822 if (phone != null) {
7823 Phone defaultPhone = phone.getImsPhone();
7824 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7825 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7826 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007827 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7828 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007829 }
7830 }
Shuo Qian284ae752020-12-22 19:10:14 -08007831 } catch (ImsException e) {
7832 throw new ServiceSpecificException(e.getCode());
7833 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007834 Binder.restoreCallingIdentity(identity);
7835 }
7836 }
7837
7838 @Override
7839 public int getCallComposerStatus(int subId) {
7840 enforceReadPrivilegedPermission("getCallComposerStatus");
7841
joonhunshin4ac60942023-11-15 15:23:39 +00007842 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7843 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7844
Shuo Qiane4e11672020-12-15 22:15:33 -08007845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 Phone phone = getPhone(subId);
7848 if (phone != null) {
7849 Phone defaultPhone = phone.getImsPhone();
7850 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7851 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7852 return imsPhone.getCallComposerStatus();
7853 }
7854 }
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
7857 }
7858 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7859 }
7860
7861 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007862 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7863 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007864 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007865 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007866
joonhunshin4ac60942023-11-15 15:23:39 +00007867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7868 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7869 "setLine1NumberForDisplayForSubscriber");
7870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 final String iccId = getIccId(subId);
7874 final Phone phone = getPhone(subId);
7875 if (phone == null) {
7876 return false;
7877 }
arunvoddub1365e62024-07-31 09:42:31 +00007878 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7879 Rlog.e(LOG_TAG, "Number is too long");
7880 return false;
7881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final String subscriberId = phone.getSubscriberId();
7883
7884 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007885 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 + subscriberId + " to " + number);
7887 }
7888
7889 if (TextUtils.isEmpty(iccId)) {
7890 return false;
7891 }
7892
7893 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7894
7895 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7896 if (alphaTag == null) {
7897 editor.remove(alphaTagPrefKey);
7898 } else {
7899 editor.putString(alphaTagPrefKey, alphaTag);
7900 }
7901
7902 // Record both the line number and IMSI for this ICCID, since we need to
7903 // track all merged IMSIs based on line number
7904 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7905 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7906 if (number == null) {
7907 editor.remove(numberPrefKey);
7908 editor.remove(subscriberPrefKey);
7909 } else {
7910 editor.putString(numberPrefKey, number);
7911 editor.putString(subscriberPrefKey, subscriberId);
7912 }
7913
7914 editor.commit();
7915 return true;
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007918 }
Derek Tan7226c842014-07-02 17:42:23 -07007919 }
7920
7921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 public String getLine1NumberForDisplay(int subId, String callingPackage,
7923 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007924 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007926 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007927 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007928 return null;
7929 }
Derek Tan97ebb422014-09-05 16:55:38 -07007930
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007931 if (!mApp.getResources().getBoolean(
7932 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7933 enforceTelephonyFeatureWithException(callingPackage,
7934 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7935 }
joonhunshin4ac60942023-11-15 15:23:39 +00007936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 final long identity = Binder.clearCallingIdentity();
7938 try {
7939 String iccId = getIccId(subId);
7940 if (iccId != null) {
7941 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7942 if (DBG_MERGE) {
7943 log("getLine1NumberForDisplay returning "
7944 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7945 }
7946 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7949 return null;
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007952 }
Derek Tan7226c842014-07-02 17:42:23 -07007953 }
7954
7955 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007956 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7957 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007959 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007960 return null;
7961 }
Derek Tan97ebb422014-09-05 16:55:38 -07007962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 String iccId = getIccId(subId);
7966 if (iccId != null) {
7967 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7968 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7969 }
7970 return null;
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007973 }
Derek Tan7226c842014-07-02 17:42:23 -07007974 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007975
7976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007977 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7978 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007979 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7980 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007982 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007983 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007984 return null;
7985 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007986
Jordan Liub49b04b2019-05-06 14:45:15 -07007987 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7988 // the process, where TelephonyManager was instantiated.
7989 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007990 final long identity = Binder.clearCallingIdentity();
7991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 final TelephonyManager tele = TelephonyManager.from(context);
7994 final SubscriptionManager sub = SubscriptionManager.from(context);
7995
7996 // Figure out what subscribers are currently active
7997 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998
Jordan Liub49b04b2019-05-06 14:45:15 -07007999 // Only consider subs which match the current subId
8000 // This logic can be simplified. See b/131189269 for progress.
8001 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008002 activeSubscriberIds.add(tele.getSubscriberId(subId));
8003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004
8005 // First pass, find a number override for an active subscriber
8006 String mergeNumber = null;
8007 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8008 for (String key : prefs.keySet()) {
8009 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8010 final String subscriberId = (String) prefs.get(key);
8011 if (activeSubscriberIds.contains(subscriberId)) {
8012 final String iccId = key.substring(
8013 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8014 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8015 mergeNumber = (String) prefs.get(numberKey);
8016 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008017 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 + " for active subscriber " + subscriberId);
8019 }
8020 if (!TextUtils.isEmpty(mergeNumber)) {
8021 break;
8022 }
8023 }
8024 }
8025 }
8026
8027 // Shortcut when no active merged subscribers
8028 if (TextUtils.isEmpty(mergeNumber)) {
8029 return null;
8030 }
8031
8032 // Second pass, find all subscribers under that line override
8033 final ArraySet<String> result = new ArraySet<>();
8034 for (String key : prefs.keySet()) {
8035 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8036 final String number = (String) prefs.get(key);
8037 if (mergeNumber.equals(number)) {
8038 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8039 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8040 final String subscriberId = (String) prefs.get(subscriberKey);
8041 if (!TextUtils.isEmpty(subscriberId)) {
8042 result.add(subscriberId);
8043 }
8044 }
8045 }
8046 }
8047
8048 final String[] resultArray = result.toArray(new String[result.size()]);
8049 Arrays.sort(resultArray);
8050 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008051 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8053 }
8054 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008055 } finally {
8056 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008057 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008058 }
8059
8060 @Override
zoey chen38003472019-12-13 17:16:31 +08008061 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8062 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008063
joonhunshin4ac60942023-11-15 15:23:39 +00008064 enforceTelephonyFeatureWithException(callingPackage,
8065 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8066
Malcolm Chen6ca97372019-07-01 16:28:21 -07008067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 final TelephonyManager telephonyManager = mApp.getSystemService(
8070 TelephonyManager.class);
8071 String subscriberId = telephonyManager.getSubscriberId(subId);
8072 if (subscriberId == null) {
8073 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008074 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008075 + subId);
8076 }
8077 return null;
8078 }
8079
Jack Yu3beaf9d2023-04-14 09:17:27 -07008080 final SubscriptionInfo info = getSubscriptionManagerService()
8081 .getSubscriptionInfo(subId);
8082 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008083 // If it doesn't belong to any group, return just subscriberId of itself.
8084 if (groupUuid == null) {
8085 return new String[]{subscriberId};
8086 }
8087
8088 // Get all subscriberIds from the group.
8089 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008090 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8091 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8092 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008093 for (SubscriptionInfo subInfo : groupInfos) {
8094 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8095 if (subscriberId != null) {
8096 mergedSubscriberIds.add(subscriberId);
8097 }
8098 }
8099
8100 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103
8104 }
8105 }
8106
8107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008108 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008109 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008110 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111
joonhunshin4ac60942023-11-15 15:23:39 +00008112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8113 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 final long identity = Binder.clearCallingIdentity();
8116 try {
8117 final Phone phone = getPhone(subId);
8118 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
8121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008122 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008123
8124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008125 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008126 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8127 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8129 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 final Phone phone = getPhone(subId);
8134 if (phone == null) {
8135 return false;
8136 }
8137 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8138 cdmaNonRoamingList);
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008141 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008142 }
8143
8144 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008145 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008146 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008147 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008148 if (phone == null) {
8149 return raf;
8150 }
8151
Shuo Qiandee53402020-05-29 14:08:15 -07008152 try {
8153 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008154 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008155 mApp, phone.getSubId(), "getRadioAccessFamily");
8156 } catch (SecurityException e) {
8157 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8158 throw e;
8159 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008160
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008161 if (!mApp.getResources().getBoolean(
8162 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8163 enforceTelephonyFeatureWithException(callingPackage,
8164 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8165 }
joonhunshin4ac60942023-11-15 15:23:39 +00008166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 final long identity = Binder.clearCallingIdentity();
8168 try {
chen xub97461a2018-10-26 14:17:57 -07008169 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 } finally {
8171 Binder.restoreCallingIdentity(identity);
8172 }
chen xub97461a2018-10-26 14:17:57 -07008173 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008174 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008175
8176 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008177 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008178 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008179 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8180 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008181 enforceTelephonyFeatureWithException(callingPackage,
8182 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8183
Hall Liu82694d52020-12-11 18:22:04 -08008184 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008185 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008186 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8187 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008188 if (!dialerRoleHolders.contains(callingPackage)) {
8189 throw new SecurityException("App must be the dialer role holder to"
8190 + " upload a call composer pic");
8191 }
8192
8193 Executors.newSingleThreadExecutor().execute(() -> {
8194 ByteArrayOutputStream output = new ByteArrayOutputStream(
8195 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8196 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8197 boolean readUntilEnd = false;
8198 int totalBytesRead = 0;
8199 byte[] buffer = new byte[16 * 1024];
8200 while (true) {
8201 int numRead;
8202 try {
8203 numRead = input.read(buffer);
8204 } catch (IOException e) {
8205 try {
8206 fd.checkError();
8207 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8208 null);
8209 } catch (IOException e1) {
8210 // This means that the other side closed explicitly with an error. If this
8211 // happens, log and ignore.
8212 loge("Remote end of call composer picture pipe closed: " + e1);
8213 }
8214 break;
8215 }
8216 if (numRead == -1) {
8217 readUntilEnd = true;
8218 break;
8219 }
8220 totalBytesRead += numRead;
8221 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8222 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8223 try {
8224 input.close();
8225 } catch (IOException e) {
8226 // ignore
8227 }
8228 break;
8229 }
8230 output.write(buffer, 0, numRead);
8231 }
8232 // Generally, the remote end will close the file descriptors. The only case where we
8233 // close is above, where the picture size is too big.
8234
8235 try {
8236 fd.checkError();
8237 } catch (IOException e) {
8238 loge("Remote end for call composer closed with an error: " + e);
8239 return;
8240 }
8241
Hall Liuaa4211e2021-01-20 15:43:39 -08008242 if (!readUntilEnd) {
8243 loge("Did not finish reading entire image; aborting");
8244 return;
8245 }
Hall Liu82694d52020-12-11 18:22:04 -08008246
Hall Liuaa4211e2021-01-20 15:43:39 -08008247 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8248 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8249 new CallComposerPictureTransfer.Factory() {},
8250 imageData,
8251 (result) -> {
8252 if (result.first != null) {
8253 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8254 Bundle outputResult = new Bundle();
8255 outputResult.putParcelable(
8256 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8257 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8258 outputResult);
8259 } else {
8260 callback.send(result.second, null);
8261 }
8262 }
8263 );
Hall Liu82694d52020-12-11 18:22:04 -08008264 });
8265 }
8266
8267 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008268 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008270 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271
joonhunshin4ac60942023-11-15 15:23:39 +00008272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8273 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 final long identity = Binder.clearCallingIdentity();
8276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 ImsManager.getInstance(defaultPhone.getContext(),
8278 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008282 }
8283
8284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008286 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8288 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008289 return false;
8290 }
Svet Ganovb320e182015-04-16 12:30:10 -07008291
joonhunshin4ac60942023-11-15 15:23:39 +00008292 enforceTelephonyFeatureWithException(callingPackage,
8293 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 // Check the user preference and the system-level IMS setting. Even if the user has
8298 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8299 // In the long run, we may instead need to check if there exists a connection service
8300 // which can support video calling.
8301 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008302 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 return imsManager.isVtEnabledByPlatform()
8304 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8305 && imsManager.isVtEnabledByUser();
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008309 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008310
Andrew Leea1239f22015-03-02 17:44:07 -08008311 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008312 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8313 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008315 mApp, subId, callingPackage, callingFeatureId,
8316 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 return false;
8318 }
8319
joonhunshin4ac60942023-11-15 15:23:39 +00008320 enforceTelephonyFeatureWithException(callingPackage,
8321 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 CarrierConfigManager configManager =
8326 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008327 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
Andrew Leea1239f22015-03-02 17:44:07 -08008332 }
8333
8334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008335 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008337 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 return false;
8339 }
8340
joonhunshin4ac60942023-11-15 15:23:39 +00008341 enforceTelephonyFeatureWithException(callingPackage,
8342 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 CarrierConfigManager configManager =
8347 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008348 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
Andrew Leea1239f22015-03-02 17:44:07 -08008353 }
8354
Andrew Lee9431b832015-03-09 18:46:45 -07008355 @Override
8356 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008357 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008358 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008359 }
8360
8361 @Override
8362 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008363 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8364 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 final long identity = Binder.clearCallingIdentity();
8367 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008368 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
Andrew Lee9431b832015-03-09 18:46:45 -07008372 }
8373
Hall Liuf6668912018-10-31 17:05:23 -07008374 /**
8375 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8376 * support for the feature and device firmware support.
8377 *
8378 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8379 */
8380 @Override
8381 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8383 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008386 final Phone phone = getPhone(subscriptionId);
8387 if (phone == null) {
8388 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8389 return false;
8390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008392 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008394 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8395 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8396 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397 return isCarrierSupported && isDeviceSupported;
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
8400 }
Hall Liu98187582018-01-22 19:15:32 -08008401 }
8402
Hall Liuf6668912018-10-31 17:05:23 -07008403 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008404 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8405 * RTT setting, will return true if the device and carrier both support RTT.
8406 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008407 */
8408 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409 final long identity = Binder.clearCallingIdentity();
8410 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008411 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8412 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8413 return false;
8414 }
8415 }
8416
Hall Liu5bab75c2019-12-11 23:58:20 +00008417 boolean isRttSupported = isRttSupported(subscriptionId);
8418 boolean isUserRttSettingOn = Settings.Secure.getInt(
8419 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8420 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8421 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8422 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008426 }
8427
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008428 @Deprecated
8429 @Override
8430 public String getDeviceId(String callingPackage) {
8431 return getDeviceIdWithFeature(callingPackage, null);
8432 }
8433
Sanket Padawe7310cc72015-01-14 09:53:20 -08008434 /**
8435 * Returns the unique device ID of phone, for example, the IMEI for
8436 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8437 *
8438 * <p>Requires Permission:
8439 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8440 */
8441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008443 try {
8444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8445 } catch (SecurityException se) {
8446 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8447 throw new SecurityException("Package " + callingPackage + " does not belong to "
8448 + Binder.getCallingUid());
8449 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008450 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008451 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008452 return null;
8453 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008454 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008455 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008457 return null;
8458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459
8460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 return phone.getDeviceId();
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008466 }
8467
Ping Sunc67b7c22016-03-02 19:16:45 +08008468 /**
8469 * {@hide}
8470 * Returns the IMS Registration Status on a particular subid
8471 *
8472 * @param subId
8473 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008474 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008475 Phone phone = getPhone(subId);
8476 if (phone != null) {
8477 return phone.isImsRegistered();
8478 } else {
8479 return false;
8480 }
8481 }
8482
Santos Cordon7a1885b2015-02-03 11:15:19 -08008483 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008484 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008485 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008487 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008488 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8489 }
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
8496 }
8497
8498 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008499 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008502 mApp,
8503 subscriptionId,
8504 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8505 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008506
8507 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8508 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8509
Tyler Gunnf70ed162019-04-03 15:28:53 -07008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 Phone phone = getPhone(subscriptionId);
8513 if (phone == null) {
8514 return null;
8515 }
8516 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008522 /**
8523 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008524 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008525 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 Phone phone = getPhone(subId);
8529 if (phone != null) {
8530 return phone.isWifiCallingEnabled();
8531 } else {
8532 return false;
8533 }
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008536 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008537 }
8538
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008540 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008541 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008542 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 Phone phone = getPhone(subId);
8546 if (phone != null) {
8547 return phone.isVideoEnabled();
8548 } else {
8549 return false;
8550 }
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008553 }
8554 }
8555
8556 /**
8557 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8558 * defined in {@link ImsRegistrationImplBase}.
8559 */
8560 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 Phone phone = getPhone(subId);
8564 if (phone != null) {
8565 return phone.getImsRegistrationTech();
8566 } else {
8567 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8568 }
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008571 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008572 }
8573
Stuart Scott8eef64f2015-04-08 15:13:54 -07008574 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008575 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008576 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008577
8578 enforceTelephonyFeatureWithException(callingPackage,
8579 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8580
Stuart Scott981d8582015-04-21 14:09:50 -07008581 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8582 return;
8583 }
Kai Shif70f46f2021-03-03 13:59:46 -08008584 Phone defaultPhone = getDefaultPhone();
8585 if (defaultPhone != null) {
8586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8587 mApp, getDefaultPhone().getSubId(), "factoryReset");
8588 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008589 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008590
Svet Ganovcc087f82015-05-12 20:35:54 -07008591 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008592 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8593 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008594 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008595 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008596 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008597 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008598 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008599 setDataRoamingEnabled(subId, phone == null ? false
8600 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008601 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008602 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008603 // There has been issues when Sms raw table somehow stores orphan
8604 // fragments. They lead to garbled message when new fragments come
8605 // in and combined with those stale ones. In case this happens again,
8606 // user can reset all network settings which will clean up this table.
8607 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008608 // Clean up IMS settings as well here.
8609 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008610 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008611 ImsManager.getInstance(mApp, slotId).factoryReset();
8612 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008613
Kai Shif70f46f2021-03-03 13:59:46 -08008614 if (defaultPhone == null) {
8615 return;
8616 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008617 // Erase modem config if erase modem on network setting is enabled.
8618 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8619 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8620 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008621 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008622 }
Kai Shif70f46f2021-03-03 13:59:46 -08008623
8624 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008625 } finally {
8626 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008627 }
8628 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008629
SongFerngWangfd89b102021-05-27 22:44:54 +08008630 @VisibleForTesting
8631 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8632 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8633 return;
8634 }
8635 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8636 RILConstants.PREFERRED_NETWORK_MODE);
8637 SubscriptionManager.setSubscriptionProperty(subId,
8638 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8639 "user=" + defaultNetworkType);
8640 phone.loadAllowedNetworksFromSubscriptionDatabase();
8641 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8642 defaultNetworkType, null);
8643 }
8644
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008645 private void cleanUpSmsRawTable(Context context) {
8646 ContentResolver resolver = context.getContentResolver();
8647 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8648 resolver.delete(uri, null, null);
8649 }
8650
Narayan Kamath1c496c22015-04-16 14:40:19 +01008651 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008652 public String getSimLocaleForSubscriber(int subId) {
8653 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008654
8655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8657
chen xu5d3637b2019-01-21 23:31:38 -08008658 final Phone phone = getPhone(subId);
8659 if (phone == null) {
8660 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008661 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663 final long identity = Binder.clearCallingIdentity();
8664 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008665 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8666 phone.getContext().getOpPackageName(),
8667 phone.getContext().getAttributionTag());
8668 if (info == null) {
8669 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8670 return null;
chen xu6291c472019-02-04 12:55:53 -08008671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672 // Try and fetch the locale from the carrier properties or from the SIM language
8673 // preferences (EF-PL and EF-LI)...
8674 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008676 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8677 if (localeFromDefaultSim != null) {
8678 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8679 if (DBG) log("Using locale from subId: " + subId + " locale: "
8680 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008681 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008682 } else {
8683 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008684 }
8685 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 // The SIM language preferences only store a language (e.g. fr = French), not an
8688 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8689 // the SIM and carrier preferences does not include a country we add the country
8690 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008691 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008692 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008693 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008694 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695 }
8696
8697 if (DBG) log("No locale found - returning null");
8698 return null;
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008702 }
8703
tom hsu0b59d292022-09-29 23:49:21 +08008704 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008705 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008706 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008707 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008708 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008709 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8710 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008711 Locale.forLanguageTag(localeTag).getCountry())) {
8712 return localeTag;
8713 }
8714 }
8715 return inputLocale.toLanguageTag();
8716 }
8717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008718 /**
8719 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8720 */
8721 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008722 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008723 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008724 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008725
Gary Jian3aa9a762022-01-24 16:41:19 +08008726 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8727 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008728
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008729 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008730 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8731 * representing the state of the modem.
8732 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008733 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8734 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008735 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008736 */
8737 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008738 public void requestModemActivityInfo(ResultReceiver result) {
8739 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008740
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008741 if (!mApp.getResources().getBoolean(
8742 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8744 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8745 }
joonhunshin4ac60942023-11-15 15:23:39 +00008746
vagdeviaf9a5b92018-08-15 16:01:53 -07008747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008748
8749 final long identity = Binder.clearCallingIdentity();
8750 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008751 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752 } finally {
8753 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008754 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008755 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008756
Gary Jian76280a42022-12-07 16:18:33 +08008757 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008758 // less than total activity duration.
8759 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8760 if (info == null) {
8761 return false;
8762 }
8763 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008764 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008765 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8766
Hall Liu49656c02020-10-09 19:00:11 -07008767 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8768
Siddharth Rayb8114062018-06-17 15:02:38 -07008769 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008770 && (info.getSleepTimeMillis() <= activityDurationMs)
8771 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008772 }
8773
Gary Jian3aa9a762022-01-24 16:41:19 +08008774 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8775 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8776 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8777 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8778
8779 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8780 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8781 }
8782
8783 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8784 mLastModemActivityInfo.setReceiveTimeMillis(
8785 rat,
8786 freq,
8787 info.getReceiveTimeMillis(rat, freq)
8788 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8789 }
8790
8791 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8792 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8793 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8794 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8795
8796 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8797 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8798 }
8799 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8800 mLastModemActivityInfo.setReceiveTimeMillis(
8801 rat,
8802 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8803 }
8804
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008805 /**
8806 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8807 * @param info recent ModemActivityInfo
8808 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008809 private void mergeModemActivityInfo(ModemActivityInfo info) {
8810 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008811 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008812 boolean matched;
8813 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8814 matched = false;
8815 int rat = info.getSpecificInfoRat(i);
8816 int freq = info.getSpecificInfoFrequencyRange(i);
8817 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8818 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8819 //if it already exists
8820 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8821 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8822 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8823 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8824 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8825 updateLastModemActivityInfo(info, rat, freq);
8826 matched = true;
8827 }
8828 } else {
8829 updateLastModemActivityInfo(info, rat);
8830 matched = true;
8831 }
8832 }
8833 }
8834
8835 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008836 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008837 new ActivityStatsTechSpecificInfo(
8838 rat,
8839 freq,
8840 info.getTransmitTimeMillis(rat, freq),
8841 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008842 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008843 }
8844 }
8845 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8846 mLastModemActivitySpecificInfo =
8847 new ActivityStatsTechSpecificInfo[merged.size()];
8848 merged.toArray(mLastModemActivitySpecificInfo);
8849
8850 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8851 mLastModemActivityInfo.setSleepTimeMillis(
8852 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008853 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008854 mLastModemActivityInfo.setIdleTimeMillis(
8855 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008856 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008857
8858 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008859 new ModemActivityInfo(
8860 mLastModemActivityInfo.getTimestampMillis(),
8861 mLastModemActivityInfo.getSleepTimeMillis(),
8862 mLastModemActivityInfo.getIdleTimeMillis(),
8863 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008864 }
8865
8866 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8867 ActivityStatsTechSpecificInfo[] info) {
8868 int infoSize = info.length;
8869 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8870 for (int i = 0; i < infoSize; i++) {
8871 ret[i] = new ActivityStatsTechSpecificInfo(
8872 info[i].getRat(), info[i].getFrequencyRange(),
8873 info[i].getTransmitTimeMillis(),
8874 (int) info[i].getReceiveTimeMillis());
8875 }
8876 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008877 }
8878
Jack Yu85bd38a2015-11-09 11:34:32 -08008879 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008880 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008881 */
8882 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008883 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8884 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8885 Phone phone = PhoneFactory.getPhone(slotIndex);
8886 if (phone == null) {
8887 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8888 return null;
8889 }
8890
8891 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008894 return null;
8895 }
8896
joonhunshin4ac60942023-11-15 15:23:39 +00008897 enforceTelephonyFeatureWithException(callingPackage,
8898 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8899
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008900 boolean hasFinePermission = false;
8901 boolean hasCoarsePermission = false;
8902 if (!renounceFineLocationAccess) {
8903 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8904 LocationAccessPolicy.checkLocationPermission(mApp,
8905 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8906 .setCallingPackage(callingPackage)
8907 .setCallingFeatureId(callingFeatureId)
8908 .setCallingPid(Binder.getCallingPid())
8909 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008910 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008911 .setLogAsInfo(true)
8912 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8913 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8914 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8915 .build());
8916 hasFinePermission =
8917 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8918 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008919
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008920 if (!renounceCoarseLocationAccess) {
8921 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8922 LocationAccessPolicy.checkLocationPermission(mApp,
8923 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8924 .setCallingPackage(callingPackage)
8925 .setCallingFeatureId(callingFeatureId)
8926 .setCallingPid(Binder.getCallingPid())
8927 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008928 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008929 .setLogAsInfo(true)
8930 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8931 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8932 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8933 .build());
8934 hasCoarsePermission =
8935 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8936 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008937
Jordan Liu0f2bc442020-11-18 16:47:37 -08008938 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008939 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008940 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8941 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008942 if (subInfo != null && !subInfo.isActive()) {
8943 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008944 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008945 }
8946
Hall Liuf19c44f2018-11-27 14:38:17 -08008947 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008948 boolean isCallingPackageDataService = phone.getDataServicePackages()
8949 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008950
8951 // Scrub out the location info in ServiceState depending on what level of access
8952 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008953 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008954 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8955 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 } finally {
8957 Binder.restoreCallingIdentity(identity);
8958 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008960
8961 /**
8962 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8963 *
8964 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8965 * voicemail ringtone.
8966 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8967 * PhoneAccount.
8968 */
8969 @Override
8970 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8972 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8977 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008978 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008985 }
8986
8987 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 * Sets the per-account voicemail ringtone.
8989 *
8990 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8991 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8992 *
8993 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8994 * voicemail ringtone.
8995 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8996 * PhoneAccount.
8997 */
8998 @Override
8999 public void setVoicemailRingtoneUri(String callingPackage,
9000 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009001 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009003 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9004 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9006 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9007 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009
joonhunshin4ac60942023-11-15 15:23:39 +00009010 enforceTelephonyFeatureWithException(callingPackage,
9011 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009017 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018 }
9019 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9020 } finally {
9021 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009022 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009023 }
9024
9025 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009026 * Returns whether vibration is set for voicemail notification in Phone settings.
9027 *
9028 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9029 * voicemail vibration setting.
9030 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9031 */
9032 @Override
9033 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9035 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9040 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009041 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009048 }
9049
Youhan Wange64578a2016-05-02 15:32:42 -07009050 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009051 * Sets the per-account voicemail vibration.
9052 *
9053 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9054 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9055 *
9056 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9057 * voicemail vibration setting.
9058 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9059 * specific PhoneAccount.
9060 */
9061 @Override
9062 public void setVoicemailVibrationEnabled(String callingPackage,
9063 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009064 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009066 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9067 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9069 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9070 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009071 }
9072
joonhunshin4ac60942023-11-15 15:23:39 +00009073 enforceTelephonyFeatureWithException(callingPackage,
9074 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009080 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009081 }
9082 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9083 } finally {
9084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009086 }
9087
9088 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009089 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9090 *
9091 * @throws SecurityException if the caller does not have the required permission
9092 */
arunvoddud7401012022-12-15 16:08:12 +00009093 @VisibleForTesting
9094 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009095 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009096 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009097 }
9098
9099 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009100 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9101 * permission.
9102 *
9103 * @throws SecurityException if the caller does not have the required permission
9104 */
9105 private void enforceSendSmsPermission() {
9106 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9107 }
9108
9109 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009110 * Make sure either called from same process as self (phone) or IPC caller has interact across
9111 * users permission.
9112 *
9113 * @throws SecurityException if the caller does not have the required permission
9114 */
9115 private void enforceInteractAcrossUsersPermission(String message) {
9116 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9117 }
9118
9119 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009120 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009121 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009122 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009123 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009124 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125 final long identity = Binder.clearCallingIdentity();
9126 try {
9127 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009128 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129 if (componentName == null) {
9130 throw new SecurityException(
9131 "Caller not current active visual voicemail package[null]");
9132 }
9133 String vvmPackage = componentName.getPackageName();
9134 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009135 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136 }
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009139 }
9140 }
9141
9142 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009143 * Return the application ID for the app type.
9144 *
9145 * @param subId the subscription ID that this request applies to.
9146 * @param appType the uicc app type.
9147 * @return Application ID for specificied app type, or null if no uicc.
9148 */
9149 @Override
9150 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009151 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009152
9153 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9154 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9155
Youhan Wange64578a2016-05-02 15:32:42 -07009156 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009157
9158 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009159 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009160 if (phone == null) {
9161 return null;
9162 }
9163 String aid = null;
9164 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009165 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166 .getApplicationByType(appType).getAid();
9167 } catch (Exception e) {
9168 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9169 }
9170 return aid;
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009173 }
Youhan Wange64578a2016-05-02 15:32:42 -07009174 }
9175
Youhan Wang4001d252016-05-11 10:29:41 -07009176 /**
9177 * Return the Electronic Serial Number.
9178 *
9179 * @param subId the subscription ID that this request applies to.
9180 * @return ESN or null if error.
9181 */
9182 @Override
9183 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009184 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009185 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186
9187 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009188 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009189 if (phone == null) {
9190 return null;
9191 }
9192 String esn = null;
9193 try {
9194 esn = phone.getEsn();
9195 } catch (Exception e) {
9196 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9197 }
9198 return esn;
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009201 }
Youhan Wang4001d252016-05-11 10:29:41 -07009202 }
9203
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009204 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009205 * Return the Preferred Roaming List Version.
9206 *
9207 * @param subId the subscription ID that this request applies to.
9208 * @return PRLVersion or null if error.
9209 */
9210 @Override
9211 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009212 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009213
9214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9215 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9216
Youhan Wang66ad5d72016-07-18 17:56:58 -07009217 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009218
9219 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009220 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221 if (phone == null) {
9222 return null;
9223 }
9224 String cdmaPrlVersion = null;
9225 try {
9226 cdmaPrlVersion = phone.getCdmaPrlVersion();
9227 } catch (Exception e) {
9228 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9229 }
9230 return cdmaPrlVersion;
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009233 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009234 }
9235
9236 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009237 * Get snapshot of Telephony histograms
9238 * @return List of Telephony histograms
9239 * @hide
9240 */
9241 @Override
9242 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9244 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 return RIL.getTelephonyRILTimingHistograms();
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009252 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009253
9254 /**
9255 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009256 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9257 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009258 * Require system privileges. In the future we may add this to carrier APIs.
9259 *
Michele Berionne482f8202018-11-27 18:57:59 -08009260 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009261 */
9262 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009263 @TelephonyManager.SetCarrierRestrictionResult
9264 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009265 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009266
9267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9268 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9269
vagdeviaf9a5b92018-08-15 16:01:53 -07009270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009271
Michele Berionne482f8202018-11-27 18:57:59 -08009272 if (carrierRestrictionRules == null) {
9273 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009274 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 final long identity = Binder.clearCallingIdentity();
9277 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009278 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009279 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280 } finally {
9281 Binder.restoreCallingIdentity(identity);
9282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009283 }
9284
9285 /**
9286 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009287 * Get the allowed carrier list and the excluded carrier list, including the priority between
9288 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009289 * Require system privileges. In the future we may add this to carrier APIs.
9290 *
Michele Berionne482f8202018-11-27 18:57:59 -08009291 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009292 */
9293 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009294 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009295 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009296
9297 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9298 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9299
vagdeviaf9a5b92018-08-15 16:01:53 -07009300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009301
9302 final long identity = Binder.clearCallingIdentity();
9303 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009304 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9305 if (response instanceof CarrierRestrictionRules) {
9306 return (CarrierRestrictionRules) response;
9307 }
9308 // Response is an Exception of some kind,
9309 // which is signalled to the user as a NULL retval
9310 return null;
9311 } catch (Exception e) {
9312 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9313 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009317 }
9318
fionaxu59545b42016-05-25 15:53:37 -07009319 /**
arunvoddud7401012022-12-15 16:08:12 +00009320 * Fetches the carrier restriction status of the device and sends the status to the caller
9321 * through the callback.
9322 *
9323 * @param callback The callback that will be used to send the result.
9324 * @throws SecurityException if the caller does not have the required permission/privileges or
9325 * the caller is not allowlisted.
9326 */
9327 @Override
9328 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009329 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009330 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009331 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9332 try {
9333 mApp.enforceCallingOrSelfPermission(
9334 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9335 functionName);
9336 } catch (SecurityException e) {
9337 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9338 functionName);
9339 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009340 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9341 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009342 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9343 throw new SecurityException("Not an authorized caller");
9344 }
9345 final long identity = Binder.clearCallingIdentity();
9346 try {
9347 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009348 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009349 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9350 } finally {
9351 Binder.restoreCallingIdentity(identity);
9352 }
9353 }
9354
arunvoddu567f2b42023-04-25 17:22:00 +00009355 @Override
9356 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9357 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9358 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9359 return allowListInfo.getShaIdList(pkgName, carrierId);
9360 }
9361
arunvoddud7401012022-12-15 16:08:12 +00009362 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009363 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009364 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009365 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009366 }
9367
9368 /**
fionaxu59545b42016-05-25 15:53:37 -07009369 * Action set from carrier signalling broadcast receivers to enable/disable radio
9370 * @param subId the subscription ID that this action applies to.
9371 * @param enabled control enable or disable radio.
9372 * {@hide}
9373 */
9374 @Override
9375 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9376 enforceModifyPermission();
9377 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009378
9379 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009380 if (phone == null) {
9381 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9382 return;
9383 }
9384 try {
9385 phone.carrierActionSetRadioEnabled(enabled);
9386 } catch (Exception e) {
9387 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009388 } finally {
9389 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009390 }
9391 }
9392
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009393 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009394 * Enable or disable Voice over NR (VoNR)
9395 * @param subId the subscription ID that this action applies to.
9396 * @param enabled enable or disable VoNR.
9397 * @return operation result.
9398 */
9399 @Override
9400 public int setVoNrEnabled(int subId, boolean enabled) {
9401 enforceModifyPermission();
9402 final Phone phone = getPhone(subId);
9403
9404 final long identity = Binder.clearCallingIdentity();
9405 if (phone == null) {
9406 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9407 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9408 }
9409
9410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9411 try {
9412 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9413 workSource);
9414 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009415
9416 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9417 if (DBG) {
9418 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9419 }
9420 SubscriptionManager.setSubscriptionProperty(
9421 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9422 (enabled ? "1" : "0"));
9423 }
9424
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009425 return result;
9426 } finally {
9427 Binder.restoreCallingIdentity(identity);
9428 }
9429 }
9430
9431 /**
9432 * Is voice over NR enabled
9433 * @return true if VoNR is enabled else false
9434 */
9435 @Override
9436 public boolean isVoNrEnabled(int subId) {
9437 enforceReadPrivilegedPermission("isVoNrEnabled");
9438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9439 final long identity = Binder.clearCallingIdentity();
9440 try {
9441 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9442 null, subId, workSource);
9443 if (DBG) log("isVoNrEnabled: " + isEnabled);
9444 return isEnabled;
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
9450 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009451 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9452 * network status based on which carrier apps could apply actions accordingly,
9453 * enable/disable default url handler for example.
9454 *
9455 * @param subId the subscription ID that this action applies to.
9456 * @param report control start/stop reporting the default network status.
9457 * {@hide}
9458 */
9459 @Override
9460 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9461 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009462
9463 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9464 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9465 "carrierActionReportDefaultNetworkStatus");
9466
fionaxu8da9cb12017-05-23 15:02:46 -07009467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468
9469 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009470 if (phone == null) {
9471 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9472 return;
9473 }
9474 try {
9475 phone.carrierActionReportDefaultNetworkStatus(report);
9476 } catch (Exception e) {
9477 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009478 } finally {
9479 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009480 }
9481 }
9482
9483 /**
fionaxud9622282017-07-17 17:51:30 -07009484 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9485 * @param subId the subscription ID that this action applies to.
9486 * {@hide}
9487 */
9488 @Override
9489 public void carrierActionResetAll(int subId) {
9490 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009491
9492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9493 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9494
fionaxud9622282017-07-17 17:51:30 -07009495 final Phone phone = getPhone(subId);
9496 if (phone == null) {
9497 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9498 return;
9499 }
9500 try {
9501 phone.carrierActionResetAll();
9502 } catch (Exception e) {
9503 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9504 }
9505 }
9506
9507 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009508 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9509 * bug report is being generated.
9510 */
9511 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009512 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009513 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9514 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009515 writer.println("Permission Denial: can't dump Phone from pid="
9516 + Binder.getCallingPid()
9517 + ", uid=" + Binder.getCallingUid()
9518 + "without permission "
9519 + android.Manifest.permission.DUMP);
9520 return;
9521 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009522 try {
9523 DumpsysHandler.dump(mApp, fd, writer, args);
9524 } catch (Exception e) {
9525 writer.println("Failed to dump phone information: " + e);
9526 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009527 }
Jack Yueb89b242016-06-22 13:27:47 -07009528
Brad Ebingerdac2f002018-04-03 15:17:52 -07009529 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009530 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9531 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9532 @NonNull String[] args) {
9533 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9534 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009535 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009536 }
9537
Jack Yueb89b242016-06-22 13:27:47 -07009538 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009539 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009540 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009541 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009542 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009543 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009544 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009545 */
9546 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009547 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009548 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009549 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9550 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9551 try {
9552 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009553 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009554 } catch (SecurityException se) {
9555 enforceModifyPermission();
9556 }
9557 } else {
9558 enforceModifyPermission();
9559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009560
joonhunshin4ac60942023-11-15 15:23:39 +00009561 enforceTelephonyFeatureWithException(callingPackage,
9562 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9563
Nate Myren116695d2024-02-09 09:36:01 -08009564 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009565 final long identity = Binder.clearCallingIdentity();
9566 try {
Nate Myren116695d2024-02-09 09:36:01 -08009567 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9568 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009569 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009570 callingUid, callingPackage, null, null);
9571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009572 Phone phone = getPhone(subId);
9573 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009574 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9575 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009576 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009577 phone.getDataSettingsManager().setDataEnabled(
9578 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009580 }
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009583 }
9584 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009585
9586 /**
9587 * Get Client request stats
9588 * @return List of Client Request Stats
9589 * @hide
9590 */
9591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009592 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9593 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009595 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009596 return null;
9597 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009598 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009600 final long identity = Binder.clearCallingIdentity();
9601 try {
9602 if (phone != null) {
9603 return phone.getClientRequestStats();
9604 }
9605
9606 return null;
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009610 }
9611
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009612 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009613 PackageManager pm;
9614 if (mFeatureFlags.hsumPackageManager()) {
9615 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9616 .getPackageManager();
9617 } else {
9618 pm = mApp.getPackageManager();
9619 }
9620
9621 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009622 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009623 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9624 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9625 // exception. ROOT_UID seems not to have a valid package name returned by
9626 // PackageManager, so just fake it here to avoid issues when running telephony shell
9627 // commands that plumb through the RIL as root, like so:
9628 // $ adb root
9629 // $ adb shell cmd phone ...
9630 packageName = "root";
9631 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009632 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009633 }
Jack Yueb4124c2017-02-16 15:32:43 -08009634
9635 /**
Grace Chen70990072017-03-24 17:21:30 -07009636 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009637 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009638 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009639 * @param state State of SIM (power down, power up, pass through)
9640 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9641 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9642 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009643 *
9644 **/
9645 @Override
Grace Chen70990072017-03-24 17:21:30 -07009646 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009647 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009648
9649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9650 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9651
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009652 Phone phone = PhoneFactory.getPhone(slotIndex);
9653
vagdeviaf9a5b92018-08-15 16:01:53 -07009654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009659 phone.setSimPowerState(state, null, workSource);
9660 }
9661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 /**
9667 * Set SIM card power state.
9668 *
9669 * @param slotIndex SIM slot id.
9670 * @param state State of SIM (power down, power up, pass through)
9671 * @param callback callback to trigger after success or failure
9672 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9674 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9675 *
9676 **/
9677 @Override
9678 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9679 IIntegerConsumer callback) {
9680 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009681
9682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9683 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9684 "setSimPowerStateForSlotWithCallback");
9685
Jordan Liu109698e2020-11-24 14:50:34 -08009686 Phone phone = PhoneFactory.getPhone(slotIndex);
9687
9688 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9689
9690 final long identity = Binder.clearCallingIdentity();
9691 try {
9692 if (phone != null) {
9693 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9694 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009695 }
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009698 }
9699 }
Shuo Qiandd210312017-04-12 22:11:33 +00009700
Tyler Gunn65d45c22017-06-05 11:22:26 -07009701 private boolean isUssdApiAllowed(int subId) {
9702 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009703 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009704 if (configManager == null) {
9705 return false;
9706 }
9707 PersistableBundle pb = configManager.getConfigForSubId(subId);
9708 if (pb == null) {
9709 return false;
9710 }
9711 return pb.getBoolean(
9712 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9713 }
9714
Shuo Qiandd210312017-04-12 22:11:33 +00009715 /**
Ling Mac28f0212023-03-24 16:07:15 -07009716 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009717 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009718 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009719 */
goneil9c5f4872017-12-05 14:07:56 -08009720 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009721 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009722 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009723
9724 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9725 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009727 final long identity = Binder.clearCallingIdentity();
9728 try {
Ling Mac28f0212023-03-24 16:07:15 -07009729 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009730 } finally {
9731 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009732 }
9733 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009734
9735 /**
9736 * Get the current signal strength information for the given subscription.
9737 * Because this information is not updated when the device is in a low power state
9738 * it should not be relied-upon to be current.
9739 * @param subId Subscription index
9740 * @return the most recent cached signal strength info from the modem
9741 */
9742 @Override
9743 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9745 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 Phone p = getPhone(subId);
9750 if (p == null) {
9751 return null;
9752 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009754 return p.getSignalStrength();
9755 } finally {
9756 Binder.restoreCallingIdentity(identity);
9757 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009758 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009759
Pengquan Meng77b7f132018-08-22 14:49:57 -07009760 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009761 * Get the current modem radio state for the given slot.
9762 * @param slotIndex slot index.
9763 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009764 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009765 * @return the current radio power state from the modem
9766 */
9767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009768 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009769 Phone phone = PhoneFactory.getPhone(slotIndex);
9770 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9772 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009773 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9774 }
9775
joonhunshin4ac60942023-11-15 15:23:39 +00009776 enforceTelephonyFeatureWithException(callingPackage,
9777 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9778
Chen Xuf792fd62018-10-17 17:54:36 +00009779 final long identity = Binder.clearCallingIdentity();
9780 try {
9781 return phone.getRadioPowerState();
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9787 }
9788
9789 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009790 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9791 *
9792 * <p>Requires one of the following permissions:
9793 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009794 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009795 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9796 * privileges.
9797 *
9798 * @param subId subscription id
9799 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9800 * {@code false}.
9801 */
9802 @Override
9803 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009804 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009805 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009806 try {
9807 mApp.enforceCallingOrSelfPermission(
9808 android.Manifest.permission.ACCESS_NETWORK_STATE,
9809 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009810 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009811 mApp.enforceCallingOrSelfPermission(
9812 permission.READ_BASIC_PHONE_STATE, functionName);
9813 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009814 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009815 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009816 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009817 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009818
joonhunshin4ac60942023-11-15 15:23:39 +00009819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9820 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9821
Pengquan Menga1bb6272018-09-06 09:59:22 -07009822 boolean isEnabled = false;
9823 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009824 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009825 Phone phone = getPhone(subId);
9826 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009827 } finally {
9828 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009829 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009830 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009831 }
9832
9833
9834 /**
9835 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9836 *
9837 * <p> Requires permission:
9838 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9839 * privileges.
9840 *
9841 * @param subId subscription id
9842 * @param isEnabled {@code true} means enable, {@code false} means disable.
9843 */
9844 @Override
9845 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9847 mApp, subId, "setDataRoamingEnabled");
9848
joonhunshin4ac60942023-11-15 15:23:39 +00009849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9850 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9851
Pengquan Menga1bb6272018-09-06 09:59:22 -07009852 final long identity = Binder.clearCallingIdentity();
9853 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009854 Phone phone = getPhone(subId);
9855 if (phone != null) {
9856 phone.setDataRoamingEnabled(isEnabled);
9857 }
9858 } finally {
9859 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009860 }
9861 }
9862
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009863 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009864 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009865 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009866 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009867 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009868
joonhunshin4ac60942023-11-15 15:23:39 +00009869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9870 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9871
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009872 boolean isAllowed = true;
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009875 Phone phone = getPhone(subId);
9876 if (phone != null) {
9877 isAllowed = phone.isCspPlmnEnabled();
9878 }
9879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 return isAllowed;
9883 }
9884
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009885 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9886 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009887 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009888 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009890 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9891 if (phone == null) {
9892 return false;
9893 }
9894 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9895 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9896 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009897 }
9898
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009899 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009900 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009901 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009902 mApp.getSystemService(AppOpsManager.class)
9903 .checkPackage(Binder.getCallingUid(), callingPackage);
9904
Jordan Liu1e142fc2019-04-22 15:10:43 -07009905 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009906 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009907 try {
9908 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009909 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009910 } catch (SecurityException e) {
9911 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9912 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009913 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009914 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009915 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009916 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009917 }
joonhunshin4ac60942023-11-15 15:23:39 +00009918
9919 enforceTelephonyFeatureWithException(callingPackage,
9920 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9921
sandeepjsb6c87872021-09-27 15:34:44 +00009922 // checking compatibility, if calling app's target SDK is T and beyond.
9923 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9924 Binder.getCallingUid())) {
9925 isIccIdAccessRestricted = true;
9926 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009927 final long identity = Binder.clearCallingIdentity();
9928 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009929 UiccController uiccController = UiccController.getInstance();
9930 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009931 if (hasReadPermission) {
9932 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009933 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009934
9935 // Remove private info if the caller doesn't have access
9936 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9937 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009938 //setting the value after compatibility check
9939 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009940 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9941 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009942 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009943 if (card == null) {
9944 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009945 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009946 continue;
9947 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009948 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9949 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009950 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009951 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009952 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009953 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9954 for (UiccPortInfo portInfo : portInfos) {
9955 UiccPort port = uiccController.getUiccPortForSlot(
9956 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9957 if (port == null) {
9958 // assume no access if port is null
9959 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9960 continue;
9961 }
9962 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9963 uiccPortInfos.add(portInfo);
9964 } else {
9965 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9966 }
9967 }
9968 filteredInfos.add(new UiccCardInfo(
9969 cardInfo.isEuicc(),
9970 cardInfo.getCardId(),
9971 null,
9972 cardInfo.getPhysicalSlotIndex(),
9973 cardInfo.isRemovable(),
9974 cardInfo.isMultipleEnabledProfilesSupported(),
9975 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009976 }
9977 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009978 } finally {
9979 Binder.restoreCallingIdentity(identity);
9980 }
9981 }
9982
sandeepjsb6c87872021-09-27 15:34:44 +00009983 /**
9984 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9985 * generally private and require carrier privileges to view.
9986 *
9987 * @hide
9988 */
9989 @NonNull
9990 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9991 List<UiccPortInfo> portinfo = new ArrayList<>();
9992 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9993 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9994 }
9995 return new UiccCardInfo(
9996 cardInfo.isEuicc(),
9997 cardInfo.getCardId(),
9998 null,
9999 cardInfo.getPhysicalSlotIndex(),
10000 cardInfo.isRemovable(),
10001 cardInfo.isMultipleEnabledProfilesSupported(),
10002 portinfo
10003 );
10004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010005
sandeepjsb6c87872021-09-27 15:34:44 +000010006 /**
10007 * @hide
10008 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10009 * These values are generally private and require carrier privileges to view.
10010 */
10011 @NonNull
10012 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10013 return new UiccPortInfo(
10014 UiccPortInfo.ICCID_REDACTED,
10015 portInfo.getPortIndex(),
10016 portInfo.getLogicalSlotIndex(),
10017 portInfo.isActive()
10018 );
10019 }
10020 @Override
10021 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010022 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010023 mApp.getSystemService(AppOpsManager.class)
10024 .checkPackage(Binder.getCallingUid(), callingPackage);
10025
sandeepjsb6c87872021-09-27 15:34:44 +000010026 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010027
Aman Guptaf3c90b32022-03-17 04:54:16 +000010028 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10029 // we are reading iccId which is PII data.
10030 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010031
joonhunshin4ac60942023-11-15 15:23:39 +000010032 enforceTelephonyFeatureWithException(callingPackage,
10033 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10034
sandeepjsb6c87872021-09-27 15:34:44 +000010035 // checking compatibility, if calling app's target SDK is T and beyond.
10036 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10037 Binder.getCallingUid())) {
10038 isLogicalSlotAccessRestricted = true;
10039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010040 final long identity = Binder.clearCallingIdentity();
10041 try {
10042 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010043 if (slots == null || slots.length == 0) {
10044 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010045 return null;
10046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010047 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10048 for (int i = 0; i < slots.length; i++) {
10049 UiccSlot slot = slots[i];
10050 if (slot == null) {
10051 continue;
10052 }
10053
Jordan Liu7be7e652019-05-06 18:55:02 +000010054 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010055 UiccCard card = slot.getUiccCard();
10056 if (card != null) {
10057 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010058 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010059 cardId = slot.getEid();
10060 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010061 // If cardId is null, use iccId of default port as cardId.
10062 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010064 }
10065
Jordan Liu857451f2019-05-09 16:35:35 -070010066 if (cardId != null) {
10067 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10068 // if cardId is an EID, it's all digits so this is fine
10069 cardId = IccUtils.stripTrailingFs(cardId);
10070 }
10071
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010072 int cardState = 0;
10073 switch (slot.getCardState()) {
10074 case CARDSTATE_ABSENT:
10075 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10076 break;
10077 case CARDSTATE_PRESENT:
10078 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10079 break;
10080 case CARDSTATE_ERROR:
10081 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10082 break;
10083 case CARDSTATE_RESTRICTED:
10084 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10085 break;
10086 default:
10087 break;
10088
10089 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010090 List<UiccPortInfo> portInfos = new ArrayList<>();
10091 int[] portIndexes = slot.getPortList();
10092 for (int portIdx : portIndexes) {
10093 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010094 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010095 portInfos.add(new UiccPortInfo(iccId, portIdx,
10096 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010098 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010099 slot.isEuicc(),
10100 cardId,
10101 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010102 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010103 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010104 //setting the value after compatibility check
10105 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010106 }
10107 return infos;
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010110 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010111 }
10112
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010113 /* Returns null if doesn't have read permission or carrier privilege access. */
10114 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10115 boolean hasReadPermission) {
10116 String iccId = slot.getIccId(portIndex);
10117 if (hasReadPermission) { // if has read permission
10118 return iccId;
10119 } else {
10120 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10121 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10122 // if no read permission, checking carrier privilege access
10123 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10124 return iccId;
10125 }
10126 }
10127 }
10128 // No read permission or carrier privilege access.
10129 return UiccPortInfo.ICCID_REDACTED;
10130 }
10131
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010132 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010133 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010134 public boolean switchSlots(int[] physicalSlots) {
10135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010136
joonhunshin4ac60942023-11-15 15:23:39 +000010137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10138 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10139
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010140 final long identity = Binder.clearCallingIdentity();
10141 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010142 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10143 for (int i = 0; i < physicalSlots.length; i++) {
10144 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10145 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10146 physicalSlots[i], i));
10147 }
10148 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010149 } finally {
10150 Binder.restoreCallingIdentity(identity);
10151 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010152 }
Jack Yu4c988042018-02-27 15:30:01 -080010153
10154 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010155 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10156 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10157 enforceModifyPermission();
10158
joonhunshin4ac60942023-11-15 15:23:39 +000010159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10160 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10161
sandeepjsb6c87872021-09-27 15:34:44 +000010162 final long identity = Binder.clearCallingIdentity();
10163 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010164 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010171 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010172 enforceTelephonyFeatureWithException(callingPackage,
10173 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10174
Jordan Liu7de49fa2018-12-06 14:48:49 -080010175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 return UiccController.getInstance().getCardIdForDefaultEuicc();
10178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
10182
Pengquan Meng85728fb2018-03-12 16:31:21 -070010183 /**
goneil47ffb6e2018-04-06 15:40:58 -070010184 * A test API to reload the UICC profile.
10185 *
10186 * <p>Requires that the calling app has permission
10187 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10188 * @hide
10189 */
10190 @Override
10191 public void refreshUiccProfile(int subId) {
10192 enforceModifyPermission();
10193
10194 final long identity = Binder.clearCallingIdentity();
10195 try {
10196 Phone phone = getPhone(subId);
10197 if (phone == null) {
10198 return;
10199 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010200 UiccPort uiccPort = phone.getUiccPort();
10201 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010202 return;
10203 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010204 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010205 if (uiccProfile == null) {
10206 return;
10207 }
10208 uiccProfile.refresh();
10209 } finally {
10210 Binder.restoreCallingIdentity(identity);
10211 }
10212 }
10213
10214 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010215 * Returns false if the mobile data is disabled by default, otherwise return true.
10216 */
10217 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010218 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010219 }
10220
10221 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010222 * Returns the default network type for the given {@code subId}, if the default network type is
10223 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10224 */
10225 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010226 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010227 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010228 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10229 return list.get(phoneId);
10230 }
10231 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010232 }
fionaxua13278b2018-03-21 00:08:13 -070010233
10234 @Override
10235 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010236 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 final Phone phone = getPhone(subId);
10242 if (phone == null) {
10243 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10244 return;
10245 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010246 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10247 if (cpt != null) {
10248 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10249 }
10250 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010251 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10252 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010253 if (carrierPrivilegeRules == null) {
10254 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10255 } else {
10256 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010258 } finally {
10259 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010260 }
fionaxua13278b2018-03-21 00:08:13 -070010261 }
10262
10263 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010264 public void setCarrierServicePackageOverride(
10265 int subId, String carrierServicePackage, String callingPackage) {
10266 TelephonyPermissions.enforceShellOnly(
10267 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10268
Benedict Wong66477622023-02-03 23:30:57 +000010269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 final Phone phone = getPhone(subId);
10272 if (phone == null || phone.getSubId() != subId) {
10273 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10274 throw new IllegalArgumentException("No phone for subid");
10275 }
10276 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10277 if (cpt == null) {
10278 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10279 throw new IllegalStateException("No CPT for phone");
10280 }
10281 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
10284 }
10285 }
10286
10287 @Override
fionaxua13278b2018-03-21 00:08:13 -070010288 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010289 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010290
10291 final long identity = Binder.clearCallingIdentity();
10292 try {
10293 final Phone phone = getPhone(subId);
10294 if (phone == null) {
10295 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10296 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10297 }
10298 return phone.getCarrierIdListVersion();
10299 } finally {
10300 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010301 }
fionaxua13278b2018-03-21 00:08:13 -070010302 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010303
10304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010305 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10306 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010308 mApp, subId, callingPackage, callingFeatureId,
10309 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010310 return -1;
10311 }
10312
10313 final long identity = Binder.clearCallingIdentity();
10314 try {
10315 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010320
10321 @Override
10322 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010325 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010326
joonhunshin4ac60942023-11-15 15:23:39 +000010327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10328 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10329
Pengquan Menga1bb6272018-09-06 09:59:22 -070010330 final long identity = Binder.clearCallingIdentity();
10331 try {
10332 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10333 } finally {
10334 Binder.restoreCallingIdentity(identity);
10335 }
10336 }
10337
10338 @Override
10339 public boolean setCdmaRoamingMode(int subId, int mode) {
10340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10341 mApp, subId, "setCdmaRoamingMode");
10342
joonhunshin4ac60942023-11-15 15:23:39 +000010343 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10344 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10345
Pengquan Menga1bb6272018-09-06 09:59:22 -070010346 final long identity = Binder.clearCallingIdentity();
10347 try {
10348 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010355 public int getCdmaSubscriptionMode(int subId) {
10356 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010357 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010358 mApp, subId, "getCdmaSubscriptionMode");
10359
joonhunshin4ac60942023-11-15 15:23:39 +000010360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10361 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10362
Sarah Chinbaab1432020-10-28 13:46:24 -070010363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010372 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10374 mApp, subId, "setCdmaSubscriptionMode");
10375
joonhunshin4ac60942023-11-15 15:23:39 +000010376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10377 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10378
Pengquan Menga1bb6272018-09-06 09:59:22 -070010379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010386
sqianc5eccab2018-10-19 18:46:41 -070010387 @Override
sqian8c685422019-02-22 15:55:18 -080010388 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010389 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010391 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10392 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010393 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10394 }
joonhunshin4ac60942023-11-15 15:23:39 +000010395
10396 enforceTelephonyFeatureWithException(callingPackage,
10397 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10398
sqian11b7a0e2018-12-05 18:48:28 -080010399 final long identity = Binder.clearCallingIdentity();
10400 try {
sqian854d44b2018-12-12 16:48:18 -080010401 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10402 for (Phone phone: PhoneFactory.getPhones()) {
10403 if (phone.getEmergencyNumberTracker() != null
10404 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10405 emergencyNumberListInternal.put(
10406 phone.getSubId(),
10407 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10408 }
sqian11b7a0e2018-12-05 18:48:28 -080010409 }
sqian854d44b2018-12-12 16:48:18 -080010410 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
sqianc5eccab2018-10-19 18:46:41 -070010414 }
10415
10416 @Override
sqian8c685422019-02-22 15:55:18 -080010417 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010418 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010419 if (!exactMatch) {
10420 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010421 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010422 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010423 }
joonhunshin4ac60942023-11-15 15:23:39 +000010424
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010425 if (!mApp.getResources().getBoolean(
10426 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10428 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10429 }
joonhunshin4ac60942023-11-15 15:23:39 +000010430
sqian11b7a0e2018-12-05 18:48:28 -080010431 final long identity = Binder.clearCallingIdentity();
10432 try {
sqian854d44b2018-12-12 16:48:18 -080010433 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010434 //Note: we ignore passed in param exactMatch. We can remove it once
10435 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010436 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010437 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010438 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010439 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010440 }
sqian11b7a0e2018-12-05 18:48:28 -080010441 }
10442 return false;
10443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 }
10447
sqianf4ca7ed2019-01-15 18:32:07 -080010448 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010449 * Start emergency callback mode for GsmCdmaPhone for testing.
10450 */
10451 @Override
10452 public void startEmergencyCallbackMode() {
10453 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10454 "startEmergencyCallbackMode");
10455 enforceModifyPermission();
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 for (Phone phone : PhoneFactory.getPhones()) {
10459 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10460 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10461 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10462 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10463 gsmCdmaPhone.obtainMessage(
10464 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10465 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10466 }
10467 }
10468 } finally {
10469 Binder.restoreCallingIdentity(identity);
10470 }
10471 }
10472
10473 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010474 * Update emergency number list for test mode.
10475 */
10476 @Override
10477 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10479 "updateEmergencyNumberListTestMode");
10480
10481 final long identity = Binder.clearCallingIdentity();
10482 try {
10483 for (Phone phone: PhoneFactory.getPhones()) {
10484 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10485 if (tracker != null) {
10486 tracker.executeEmergencyNumberTestModeCommand(action, num);
10487 }
10488 }
10489 } finally {
10490 Binder.restoreCallingIdentity(identity);
10491 }
10492 }
10493
10494 /**
10495 * Get the full emergency number list for test mode.
10496 */
10497 @Override
10498 public List<String> getEmergencyNumberListTestMode() {
10499 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10500 "getEmergencyNumberListTestMode");
10501
10502 final long identity = Binder.clearCallingIdentity();
10503 try {
10504 Set<String> emergencyNumbers = new HashSet<>();
10505 for (Phone phone: PhoneFactory.getPhones()) {
10506 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10507 if (tracker != null) {
10508 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10509 emergencyNumbers.add(num.getNumber());
10510 }
10511 }
10512 }
10513 return new ArrayList<>(emergencyNumbers);
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
chen xud6b45bd2018-10-30 22:27:10 -070010519 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010520 public int getEmergencyNumberDbVersion(int subId) {
10521 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10522
joonhunshin4ac60942023-11-15 15:23:39 +000010523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10524 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10525
Shuo Qian3b6ee772019-11-13 17:43:31 -080010526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 final Phone phone = getPhone(subId);
10529 if (phone == null) {
10530 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10531 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10532 }
10533 return phone.getEmergencyNumberDbVersion();
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
10538
10539 @Override
10540 public void notifyOtaEmergencyNumberDbInstalled() {
10541 enforceModifyPermission();
10542
joonhunshin4ac60942023-11-15 15:23:39 +000010543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10544 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10545
Shuo Qian3b6ee772019-11-13 17:43:31 -080010546 final long identity = Binder.clearCallingIdentity();
10547 try {
10548 for (Phone phone: PhoneFactory.getPhones()) {
10549 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10550 if (tracker != null) {
10551 tracker.updateOtaEmergencyNumberDatabase();
10552 }
10553 }
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010560 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010561 enforceActiveEmergencySessionPermission();
10562
joonhunshin4ac60942023-11-15 15:23:39 +000010563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10564 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10565
Shuo Qian3b6ee772019-11-13 17:43:31 -080010566 final long identity = Binder.clearCallingIdentity();
10567 try {
10568 for (Phone phone: PhoneFactory.getPhones()) {
10569 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10570 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010571 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10572 }
10573 }
10574 } finally {
10575 Binder.restoreCallingIdentity(identity);
10576 }
10577 }
10578
10579 @Override
10580 public void resetOtaEmergencyNumberDbFilePath() {
10581 enforceActiveEmergencySessionPermission();
10582
joonhunshin4ac60942023-11-15 15:23:39 +000010583 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10584 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10585
Shuo Qianc373f112020-03-05 17:55:34 -080010586 final long identity = Binder.clearCallingIdentity();
10587 try {
10588 for (Phone phone: PhoneFactory.getPhones()) {
10589 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10590 if (tracker != null) {
10591 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010592 }
10593 }
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010600 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10601 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10602 Phone phone = getPhone(subId);
10603 if (phone == null) {
10604 return null;
10605 }
10606 final long identity = Binder.clearCallingIdentity();
10607 try {
10608 UiccProfile profile = UiccController.getInstance()
10609 .getUiccProfileForPhone(phone.getPhoneId());
10610 if (profile != null) {
10611 return profile.getCertsFromCarrierPrivilegeAccessRules();
10612 }
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 return null;
10617 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010618
10619 /**
10620 * Enable or disable a modem stack.
10621 */
10622 @Override
10623 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10624 enforceModifyPermission();
10625
joonhunshin4ac60942023-11-15 15:23:39 +000010626 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10627 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10628
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010629 final long identity = Binder.clearCallingIdentity();
10630 try {
10631 Phone phone = PhoneFactory.getPhone(slotIndex);
10632 if (phone == null) {
10633 return false;
10634 } else {
10635 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10636 }
10637 } finally {
10638 Binder.restoreCallingIdentity(identity);
10639 }
10640 }
Michelecea4cf22018-12-21 15:00:11 -080010641
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010642 /**
10643 * Whether a modem stack is enabled or not.
10644 */
10645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010646 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10647 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010648 Phone phone = PhoneFactory.getPhone(slotIndex);
10649 if (phone == null) return false;
10650
10651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010652 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10653 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010654 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10655 }
10656
joonhunshin4ac60942023-11-15 15:23:39 +000010657 enforceTelephonyFeatureWithException(callingPackage,
10658 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10659
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010660 final long identity = Binder.clearCallingIdentity();
10661 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010662 try {
10663 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10664 } catch (NoSuchElementException ex) {
10665 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10666 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010667 } finally {
10668 Binder.restoreCallingIdentity(identity);
10669 }
10670 }
10671
Michelecea4cf22018-12-21 15:00:11 -080010672 @Override
Michele0ea7d782019-03-19 14:58:42 -070010673 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010674 enforceModifyPermission();
10675
joonhunshin4ac60942023-11-15 15:23:39 +000010676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10677 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10678
Michelecea4cf22018-12-21 15:00:11 -080010679 final long identity = Binder.clearCallingIdentity();
10680 try {
10681 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010682 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010683 .commit();
10684 } finally {
10685 Binder.restoreCallingIdentity(identity);
10686 }
10687 }
10688
10689 @Override
Michele0ea7d782019-03-19 14:58:42 -070010690 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010691 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010693 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10694 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010695 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010696 }
Michelecea4cf22018-12-21 15:00:11 -080010697
joonhunshin4ac60942023-11-15 15:23:39 +000010698 enforceTelephonyFeatureWithException(callingPackage,
10699 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10700
Michelecea4cf22018-12-21 15:00:11 -080010701 final long identity = Binder.clearCallingIdentity();
10702 try {
Michele0ea7d782019-03-19 14:58:42 -070010703 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010704 } finally {
10705 Binder.restoreCallingIdentity(identity);
10706 }
10707 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010708
Michele0ea7d782019-03-19 14:58:42 -070010709 @TelephonyManager.IsMultiSimSupportedResult
10710 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010711 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10712 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10713 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010714 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10715 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010716 }
10717 // Check if the hardware supports multisim functionality. If usage of multisim is not
10718 // supported by the modem, indicate that it is restricted.
10719 PhoneCapability staticCapability =
10720 mPhoneConfigurationManager.getStaticPhoneCapability();
10721 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010722 loge("isMultiSimSupportedInternal: no static configuration available");
10723 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010724 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010725 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010726 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10727 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010728 }
10729 // Check if support of multiple SIMs is restricted by carrier
10730 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010731 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010732 }
10733
Michele0ea7d782019-03-19 14:58:42 -070010734 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010735 }
10736
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010737 /**
10738 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010739 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10740 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10741 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010742 * @param numOfSims number of active sims we want to switch to
10743 */
10744 @Override
10745 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010746 if (numOfSims == 1) {
10747 enforceModifyPermission();
10748 } else {
10749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10750 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10751 }
joonhunshin4ac60942023-11-15 15:23:39 +000010752
10753 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10754 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10755
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010756 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010757
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010758 try {
Michele30b57b22019-03-01 12:01:14 -080010759 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010760 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010761 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10762 return;
10763 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010764 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10765 } finally {
10766 Binder.restoreCallingIdentity(identity);
10767 }
10768 }
10769
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010770 @Override
10771 public boolean isApplicationOnUicc(int subId, int appType) {
10772 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010773
10774 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10775 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10776
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010777 Phone phone = getPhone(subId);
10778 if (phone == null) {
10779 return false;
10780 }
10781 final long identity = Binder.clearCallingIdentity();
10782 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010783 UiccPort uiccPort = phone.getUiccPort();
10784 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010785 return false;
10786 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010787 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010788 if (uiccProfile == null) {
10789 return false;
10790 }
10791 if (TelephonyManager.APPTYPE_SIM <= appType
10792 && appType <= TelephonyManager.APPTYPE_ISIM) {
10793 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10794 }
10795 return false;
10796 } finally {
10797 Binder.restoreCallingIdentity(identity);
10798 }
10799 }
10800
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010801 /**
chen xub4baa772019-04-03 10:23:41 -070010802 * Get whether making changes to modem configurations will trigger reboot.
10803 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010804 */
10805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010806 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10807 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010809 mApp, subId, callingPackage, callingFeatureId,
10810 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010811 return false;
10812 }
joonhunshin4ac60942023-11-15 15:23:39 +000010813
10814 enforceTelephonyFeatureWithException(callingPackage,
10815 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10816 "doesSwitchMultiSimConfigTriggerReboot");
10817
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
Nathan Harold29f5f052019-02-15 13:41:57 -080010826 private void updateModemStateMetrics() {
10827 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10828 // TODO: check the state for each modem if the api is ready.
10829 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10830 }
10831
Pengquan Meng3889a572019-01-23 11:16:29 -080010832 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010833 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010834 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010835 // Verify that the callingPackage belongs to the calling UID
10836 mApp.getSystemService(AppOpsManager.class)
10837 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010838
10839 enforceTelephonyFeatureWithException(callingPackage,
10840 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10841
Pengquan Meng3889a572019-01-23 11:16:29 -080010842 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010843 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010844 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010845 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10846 if (slotInfos != null) {
10847 for (int i = 0; i < slotInfos.length; i++) {
10848 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10849 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10850 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10851 portInfo.getLogicalSlotIndex()));
10852 }
10853 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010854 }
10855 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010856 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010857 } finally {
10858 Binder.restoreCallingIdentity(identity);
10859 }
10860 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010861
10862 /**
10863 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010864 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010865 */
jimsunf9ec1622022-09-13 21:18:43 +080010866 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010867 @Override
10868 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010869 return getHalVersion(HAL_SERVICE_RADIO);
10870 }
10871
10872 /**
10873 * Get the HAL Version of a specific service
10874 */
10875 @Override
10876 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010877 Phone phone = getDefaultPhone();
10878 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010879 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010880 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10881 return hv.major * 100 + hv.minor;
10882 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010883
10884 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010885 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010886 *
10887 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010888 */
10889 @Override
sangyun097dcf72024-01-04 10:35:49 +090010890 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010891 if (mFeatureFlags.hsumPackageManager()) {
10892 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10893 Binder.getCallingUserHandle(), 0).getPackageManager();
10894 if (pm == null) return null;
10895 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10896 return (callingUids == null) ? null : callingUids[0];
10897 }
10898 if (mPackageManager == null) return null;
10899 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10900 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010901 }
10902
10903 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010904 * @return The calling package name or "phone" if the caller is the phone process. This is done
10905 * because multiple Phone has multiple packages in it and the first element in the array is not
10906 * actually always the caller.
10907 * Note: This is for logging purposes only and should not be used for security checks.
10908 */
10909 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010910 PackageManager pm;
10911 if (mFeatureFlags.hsumPackageManager()) {
10912 pm = mApp.getBaseContext().createContextAsUser(
10913 Binder.getCallingUserHandle(), 0).getPackageManager();
10914 } else {
10915 pm = mApp.getPackageManager();
10916 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010917 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10918 if (uidName != null && !uidName.isEmpty()) return uidName;
10919 return getCurrentPackageName();
10920 }
10921
10922 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010923 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10924 * corresponding network requests on a subId.
10925 *
10926 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010927 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010928 * 2) APN is un-metered for this subscription, or
10929 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010930 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010931 *
10932 * @return whether data is allowed for a apn type.
10933 *
10934 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010935 */
10936 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010937 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010938 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10939 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010940
joonhunshin4ac60942023-11-15 15:23:39 +000010941 enforceTelephonyFeatureWithException(callingPackage,
10942 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10943
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010944 // Now that all security checks passes, perform the operation as ourselves.
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 Phone phone = getPhone(subId);
10948 if (phone == null) return false;
10949
Jack Yu27422a52022-03-21 10:38:05 -070010950 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010951 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010952 isMetered = phone.getDataNetworkController().getDataConfigManager()
10953 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10954 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010955 isDataEnabled = (phone.getDataSettingsManager() != null)
10956 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010957 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010964 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010965 enforceReadPrivilegedPermission("isApnMetered");
10966
joonhunshin4ac60942023-11-15 15:23:39 +000010967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10968 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10969
Malcolm Chene5ad5792019-04-18 13:51:02 -070010970 // Now that all security checks passes, perform the operation as ourselves.
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
10973 Phone phone = getPhone(subId);
10974 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010975 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10976 DataUtils.apnTypeToNetworkCapability(apnType),
10977 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010978 } finally {
10979 Binder.restoreCallingIdentity(identity);
10980 }
10981 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010982
10983 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010984 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10985 int subscriptionId, IBooleanConsumer resultCallback) {
10986 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010987
10988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10989 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10990
Hall Liu73f5d362020-01-20 13:42:00 -080010991 long token = Binder.clearCallingIdentity();
10992 try {
10993 Phone phone = getPhone(subscriptionId);
10994 if (phone == null) {
10995 try {
10996 if (resultCallback != null) {
10997 resultCallback.accept(false);
10998 }
10999 } catch (RemoteException e) {
11000 // ignore
11001 }
11002 return;
11003 }
11004 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11005 Pair.create(specifiers, (x) -> {
11006 try {
11007 if (resultCallback != null) {
11008 resultCallback.accept(x);
11009 }
11010 } catch (RemoteException e) {
11011 // ignore
11012 }
11013 });
11014 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11015 } finally {
11016 Binder.restoreCallingIdentity(token);
11017 }
11018 }
11019
11020 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011021 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11022 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011023 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011024 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011025
11026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11027 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11028
Sarah Chin679c08a2020-11-18 13:39:35 -080011029 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11030 final long identity = Binder.clearCallingIdentity();
11031 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011032 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11033 if (result instanceof IllegalStateException) {
11034 throw (IllegalStateException) result;
11035 }
11036 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011037 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11038 return specifiers;
11039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
11043
11044 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011045 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011046 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011047
11048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11049 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11050
Jack Yu8b766fc2022-03-21 09:42:33 -070011051 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011052 }
11053
11054 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011055 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11056 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011057 if (callingPackage == null) {
11058 callingPackage = getCurrentPackageName();
11059 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011060 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11061 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011062 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11063 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011064 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11065 }
11066 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11067 Intent intent = new Intent();
11068 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11069 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11070 // Bring up choose default SMS subscription dialog right now
11071 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11072 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011073 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011074 }
chen xud5ca2d52019-05-28 15:20:57 -070011075
11076 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011077 public void showSwitchToManagedProfileDialog() {
11078 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011079 try {
11080 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11081 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11082 // for work telephony.
11083 Intent intent = new Intent(Intent.ACTION_SENDTO);
11084 intent.setData(Uri.parse("smsto:"));
11085 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011086 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011087 } catch (ActivityNotFoundException e) {
11088 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11089 Intent intent = new Intent();
11090 intent.setClass(mApp, ErrorDialogActivity.class);
11091 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011092 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011093 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011094 }
11095
11096 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011097 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11099 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11100
chen xud5ca2d52019-05-28 15:20:57 -070011101 //TODO investigate if this API should require proper permission check in R b/133791609
11102 final long identity = Binder.clearCallingIdentity();
11103 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011104 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11105 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11106 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11107 return carrierUAProfUrl;
11108 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011109 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11110 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011111 } finally {
11112 Binder.restoreCallingIdentity(identity);
11113 }
11114 }
11115
11116 @Override
11117 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11119 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11120
chen xud5ca2d52019-05-28 15:20:57 -070011121 //TODO investigate if this API should require proper permission check in R b/133791609
11122 final long identity = Binder.clearCallingIdentity();
11123 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011124 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11125 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11126 if (!TextUtils.isEmpty(carrierUserAgent)) {
11127 return carrierUserAgent;
11128 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011129 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11130 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011131 } finally {
11132 Binder.restoreCallingIdentity(identity);
11133 }
11134 }
Jack Yub07d4972019-05-28 16:12:25 -070011135
11136 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011137 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11138 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011139
joonhunshin4ac60942023-11-15 15:23:39 +000011140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11141 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11142
Jack Yub07d4972019-05-28 16:12:25 -070011143 final long identity = Binder.clearCallingIdentity();
11144 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011145 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011146 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011147
Ling Maf188d502022-09-16 15:22:36 -070011148 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011149 } finally {
11150 Binder.restoreCallingIdentity(identity);
11151 }
11152 }
11153
11154 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011155 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011156 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011157 enforceModifyPermission();
11158
joonhunshin4ac60942023-11-15 15:23:39 +000011159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11160 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11161
changbettyd5c246e2019-12-24 15:40:37 +080011162 final long identity = Binder.clearCallingIdentity();
11163 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011164 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011165 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011166
Ling Maf188d502022-09-16 15:22:36 -070011167 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011168 } finally {
11169 Binder.restoreCallingIdentity(identity);
11170 }
11171 }
11172
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011173 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011174 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011175 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11176 * otherwise.
11177 */
11178 @Override
11179 public void setCepEnabled(boolean isCepEnabled) {
11180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11181
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11185 for (Phone phone : PhoneFactory.getPhones()) {
11186 Phone defaultPhone = phone.getImsPhone();
11187 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11188 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11189 ImsPhoneCallTracker imsPhoneCallTracker =
11190 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11191 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11192 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11193 + imsPhone.getMsisdn());
11194 }
11195 }
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
allenwtsu46dcc572020-01-08 18:24:03 +080011200
11201 /**
11202 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11203 *
11204 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11205 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11206 * before being read.
11207 */
11208 @Override
11209 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11210 isCompressed) {
11211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11212 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011213 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11214 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11215 }
joonhunshin4ac60942023-11-15 15:23:39 +000011216
11217 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11218 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11219 Binder.getCallingUserHandle())) {
11220 if (!isImsAvailableOnDevice()) {
11221 // ProvisioningManager can not handle ServiceSpecificException.
11222 // Throw the IllegalStateException and annotate ProvisioningManager.
11223 throw new IllegalStateException("IMS not available on device.");
11224 }
11225 } else {
11226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11227 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11228 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011229 }
11230
11231 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011232 try {
Hui Wang761a6682020-10-31 05:12:53 +000011233 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11234 } finally {
11235 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011236 }
11237 }
zoey chene02881a2019-12-30 16:11:23 +080011238
11239 @Override
11240 public boolean isIccLockEnabled(int subId) {
11241 enforceReadPrivilegedPermission("isIccLockEnabled");
11242
joonhunshin4ac60942023-11-15 15:23:39 +000011243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11244 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11245
zoey chene02881a2019-12-30 16:11:23 +080011246 // Now that all security checks passes, perform the operation as ourselves.
11247 final long identity = Binder.clearCallingIdentity();
11248 try {
11249 Phone phone = getPhone(subId);
11250 if (phone != null && phone.getIccCard() != null) {
11251 return phone.getIccCard().getIccLockEnabled();
11252 } else {
11253 return false;
11254 }
11255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
11259
11260 /**
11261 * Set the ICC pin lock enabled or disabled.
11262 *
11263 * @return an integer representing the status of IccLock enabled or disabled in the following
11264 * three cases:
11265 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11266 * successfully.
11267 * - Positive number and zero for remaining password attempts.
11268 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11269 *
11270 */
11271 @Override
11272 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11273 enforceModifyPermission();
11274
joonhunshin4ac60942023-11-15 15:23:39 +000011275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11276 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11277
zoey chene02881a2019-12-30 16:11:23 +080011278 Phone phone = getPhone(subId);
11279 if (phone == null) {
11280 return 0;
11281 }
11282 // Now that all security checks passes, perform the operation as ourselves.
11283 final long identity = Binder.clearCallingIdentity();
11284 try {
11285 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11286 new Pair<Boolean, String>(enabled, password), phone, null);
11287 return attemptsRemaining;
11288
11289 } catch (Exception e) {
11290 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 return 0;
11295 }
11296
11297 /**
11298 * Change the ICC password used in ICC pin lock.
11299 *
11300 * @return an integer representing the status of IccLock changed in the following three cases:
11301 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11302 * - Positive number and zero for remaining password attempts.
11303 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11304 *
11305 */
11306 @Override
11307 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11308 enforceModifyPermission();
11309
joonhunshin4ac60942023-11-15 15:23:39 +000011310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11311 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11312
zoey chene02881a2019-12-30 16:11:23 +080011313 Phone phone = getPhone(subId);
11314 if (phone == null) {
11315 return 0;
11316 }
11317 // Now that all security checks passes, perform the operation as ourselves.
11318 final long identity = Binder.clearCallingIdentity();
11319 try {
11320 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11321 new Pair<String, String>(oldPassword, newPassword), phone, null);
11322 return attemptsRemaining;
11323
11324 } catch (Exception e) {
11325 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11326 } finally {
11327 Binder.restoreCallingIdentity(identity);
11328 }
11329 return 0;
11330 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011331
11332 /**
11333 * Request for receiving user activity notification
11334 */
11335 @Override
11336 public void requestUserActivityNotification() {
11337 if (!mNotifyUserActivity.get()
11338 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11339 mNotifyUserActivity.set(true);
11340 }
11341 }
11342
11343 /**
11344 * Called when userActivity is signalled in the power manager.
11345 * This is safe to call from any thread, with any window manager locks held or not.
11346 */
11347 @Override
11348 public void userActivity() {
11349 // ***************************************
11350 // * Inherited from PhoneWindowManager *
11351 // ***************************************
11352 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11353 // WITH ITS LOCKS HELD.
11354 //
11355 // This code must be VERY careful about the locks
11356 // it acquires.
11357 // In fact, the current code acquires way too many,
11358 // and probably has lurking deadlocks.
11359
Jack Yu86374492024-09-16 13:05:44 -070011360 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011361 throw new SecurityException("Only the OS may call notifyUserActivity()");
11362 }
11363
11364 if (mNotifyUserActivity.getAndSet(false)) {
11365 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11366 USER_ACTIVITY_NOTIFICATION_DELAY);
11367 }
11368 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011369
11370 @Override
11371 public boolean canConnectTo5GInDsdsMode() {
11372 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11373 }
Jack Yud10cdd42020-09-28 20:28:01 -070011374
11375 @Override
11376 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11377 String callingFeatureId) {
11378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11379 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11380 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11381 }
11382
joonhunshin4ac60942023-11-15 15:23:39 +000011383 enforceTelephonyFeatureWithException(callingPackage,
11384 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11385
Jack Yud10cdd42020-09-28 20:28:01 -070011386 Phone phone = getPhone(subId);
11387 if (phone == null) {
11388 throw new RuntimeException("phone is not available");
11389 }
11390 // Now that all security checks passes, perform the operation as ourselves.
11391 final long identity = Binder.clearCallingIdentity();
11392 try {
11393 return phone.getEquivalentHomePlmns();
11394 } finally {
11395 Binder.restoreCallingIdentity(identity);
11396 }
11397 }
Daniel Bright59e67312020-11-13 11:49:37 -080011398
11399 @Override
11400 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011401 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011402 if (!mApp.getResources().getBoolean(
11403 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11405 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11406 "isRadioInterfaceCapabilitySupported");
11407 }
joonhunshin4ac60942023-11-15 15:23:39 +000011408
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011409 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011410 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011411 if (radioInterfaceCapabilities == null) {
11412 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011413 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011414 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011415 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011416
Hui Wang641e81c2020-10-12 12:14:23 -070011417 @Override
11418 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11419 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011420 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11421 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11422 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11423 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11424 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011425
11426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11427 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11428
Hui Wang641e81c2020-10-12 12:14:23 -070011429 if (DBG) {
11430 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11431 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11432 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11433 }
11434
11435 if (!SubscriptionManager.isValidSubscriptionId(subId)
11436 || appType < TelephonyManager.APPTYPE_UNKNOWN
11437 || appType > TelephonyManager.APPTYPE_ISIM
11438 || nafUrl == null || securityProtocol == null || callback == null) {
11439 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11440 if (callback != null) {
11441 try {
11442 callback.onAuthenticationFailure(
11443 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11444 } catch (RemoteException exception) {
11445 log("Fail to notify onAuthenticationFailure due to " + exception);
11446 }
11447 return;
11448 }
11449 }
11450
11451 final long token = Binder.clearCallingIdentity();
11452 try {
11453 getGbaManager(subId).bootstrapAuthenticationRequest(
11454 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011455 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011456 } finally {
11457 Binder.restoreCallingIdentity(token);
11458 }
11459 }
11460
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011461 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011462 * Attempts to set the radio power state for all phones for thermal reason.
11463 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011464 * requested radio power state will actually be set. See {@link
11465 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11466 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 * @param enable {@code true} if trying to turn radio on.
11468 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11469 * false}.
11470 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011471 private boolean setRadioPowerForThermal(boolean enable) {
11472 boolean isPhoneAvailable = false;
11473 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11474 Phone phone = PhoneFactory.getPhone(i);
11475 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011476 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011477 isPhoneAvailable = true;
11478 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011479 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011480
11481 // return true if successfully informed the phone object about the thermal radio power
11482 // request.
11483 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011484 }
11485
11486 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011487 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011488 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11489 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11490 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11491 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11492 throw new IllegalArgumentException("modem does not support data throttling");
11493 }
11494
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011495 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11496 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011497 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11499 }
11500
Sarah Chinecc78c42022-03-31 21:16:48 -070011501 setDataEnabledForReason(
11502 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011503
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011504 if (isDataThrottlingSupported) {
11505 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011507 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11508 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11509 } else if (thermalMitigationResult
11510 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011511 log("Modem likely does not support data throttling on secondary carrier. Data " +
11512 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11513 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011514 }
11515 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011516 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011517
11518 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 }
11520
Jack Nudelman644b91a2021-03-12 14:09:48 -080011521 private static List<String> getThermalMitigationAllowlist(Context context) {
11522 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11523 for (String pckg : context.getResources()
11524 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11525 sThermalMitigationAllowlistedPackages.add(pckg);
11526 }
11527 }
11528
11529 return sThermalMitigationAllowlistedPackages;
11530 }
11531
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011532 private boolean isAnyPhoneInEmergencyState() {
11533 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11534 if (tm.isInEmergencyCall()) {
11535 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11536 return true;
11537 }
11538 for (Phone phone : PhoneFactory.getPhones()) {
11539 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11540 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011541 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11542 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011543 return true;
11544 }
11545 }
11546
11547 return false;
11548 }
11549
Jack Nudelman644b91a2021-03-12 14:09:48 -080011550 /**
11551 * Used by shell commands to add an authorized package name for thermal mitigation.
11552 * @param packageName name of package to be allowlisted
11553 * @param context
11554 */
11555 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11556 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11557 sThermalMitigationAllowlistedPackages.add(packageName);
11558 }
11559
11560 /**
11561 * Used by shell commands to remove an authorized package name for thermal mitigation.
11562 * @param packageName name of package to remove from allowlist
11563 * @param context
11564 */
11565 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11566 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11567 sThermalMitigationAllowlistedPackages.remove(packageName);
11568 }
11569
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011570 /**
11571 * Thermal mitigation request to control functionalities at modem.
11572 *
11573 * @param subId the id of the subscription.
11574 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011575 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011576 *
11577 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11578 */
11579 @Override
11580 @ThermalMitigationResult
11581 public int sendThermalMitigationRequest(
11582 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011583 ThermalMitigationRequest thermalMitigationRequest,
11584 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011585 enforceModifyPermission();
11586
Jack Nudelman644b91a2021-03-12 14:09:48 -080011587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011588
11589 enforceTelephonyFeatureWithException(callingPackage,
11590 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11591
Jack Nudelman644b91a2021-03-12 14:09:48 -080011592 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11593 .contains(callingPackage)) {
11594 throw new SecurityException("Calling package must be configured in the device config. "
11595 + "calling package: " + callingPackage);
11596 }
11597
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11599 final long identity = Binder.clearCallingIdentity();
11600
11601 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11602 try {
11603 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11604 switch (thermalMitigationAction) {
11605 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11606 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011607 handleDataThrottlingRequest(subId,
11608 thermalMitigationRequest.getDataThrottlingRequest(),
11609 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011610 break;
11611 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11612 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11613 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11614 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11615 }
11616
11617 // Ensure that radio is on. If not able to power on due to phone being
11618 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011619 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011620 thermalMitigationResult =
11621 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11622 break;
11623 }
11624
11625 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011626 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011627 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11628 break;
11629 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11630 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11631 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11632 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11633 }
11634
11635 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11636 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011637 Phone phone = getPhone(subId);
11638 if (phone == null) {
11639 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011640 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011641 break;
11642 }
11643
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011644 TelephonyConnectionService service =
11645 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011646 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011647 Log.e(LOG_TAG, "An emergency call is pending");
11648 thermalMitigationResult =
11649 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11650 break;
11651 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011652 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011653 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011654 break;
11655 }
11656 } else {
11657 thermalMitigationResult =
11658 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11659 break;
11660 }
11661
11662 // Turn radio off. If not able to power off due to phone being unavailable,
11663 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011664 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011665 thermalMitigationResult =
11666 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11667 break;
11668 }
11669 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011670 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011671 break;
11672 default:
11673 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11674 + "not exist. Requested action: " + thermalMitigationAction);
11675 }
11676 } catch (IllegalArgumentException e) {
11677 throw e;
11678 } catch (Exception e) {
11679 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11680 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11681 } finally {
11682 Binder.restoreCallingIdentity(identity);
11683 }
11684
11685 if (DBG) {
11686 log("thermalMitigationRequest returning with thermalMitigationResult: "
11687 + thermalMitigationResult);
11688 }
11689
11690 return thermalMitigationResult;
11691 }
Hui Wang641e81c2020-10-12 12:14:23 -070011692
11693 /**
11694 * Set the GbaService Package Name that Telephony will bind to.
11695 *
11696 * @param subId The sim that the GbaService is associated with.
11697 * @param packageName The name of the package to be replaced with.
11698 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11699 */
11700 @Override
11701 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11702 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011703 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011704 final long identity = Binder.clearCallingIdentity();
11705 try {
Jack Yu02533f12024-10-03 18:44:32 -070011706 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011707 } finally {
11708 Binder.restoreCallingIdentity(identity);
11709 }
11710 }
11711
11712 /**
11713 * Return the package name of the currently bound GbaService.
11714 *
11715 * @param subId The sim that the GbaService is associated with.
11716 * @return the package name of the GbaService configuration, null if GBA is not supported.
11717 */
11718 @Override
11719 public String getBoundGbaService(int subId) {
11720 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11721
11722 final long identity = Binder.clearCallingIdentity();
11723 try {
11724 return getGbaManager(subId).getServicePackage();
11725 } finally {
11726 Binder.restoreCallingIdentity(identity);
11727 }
11728 }
11729
11730 /**
11731 * Set the release time for telephony to unbind GbaService.
11732 *
11733 * @param subId The sim that the GbaService is associated with.
11734 * @param interval The release time to unbind GbaService by millisecond.
11735 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11736 */
11737 @Override
11738 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11739 enforceModifyPermission();
11740
11741 final long identity = Binder.clearCallingIdentity();
11742 try {
11743 return getGbaManager(subId).overrideReleaseTime(interval);
11744 } finally {
11745 Binder.restoreCallingIdentity(identity);
11746 }
11747 }
11748
11749 /**
11750 * Return the release time for telephony to unbind GbaService.
11751 *
11752 * @param subId The sim that the GbaService is associated with.
11753 * @return The release time to unbind GbaService by millisecond.
11754 */
11755 @Override
11756 public int getGbaReleaseTime(int subId) {
11757 enforceReadPrivilegedPermission("getGbaReleaseTime");
11758
11759 final long identity = Binder.clearCallingIdentity();
11760 try {
11761 return getGbaManager(subId).getReleaseTime();
11762 } finally {
11763 Binder.restoreCallingIdentity(identity);
11764 }
11765 }
11766
11767 private GbaManager getGbaManager(int subId) {
11768 GbaManager instance = GbaManager.getInstance(subId);
11769 if (instance == null) {
11770 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11771 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11772 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11773 }
11774 return instance;
11775 }
Hui Wang761a6682020-10-31 05:12:53 +000011776
11777 /**
11778 * indicate whether the device and the carrier can support
11779 * RCS VoLTE single registration.
11780 */
11781 @Override
11782 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011783 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11784 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11785 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11786 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011787
11788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11790 }
11791
11792 final long identity = Binder.clearCallingIdentity();
11793 try {
11794 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11795 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011796 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11797 if (isCapable != null) {
11798 return isCapable;
11799 }
Hui Wang761a6682020-10-31 05:12:53 +000011800 }
Hui Wang67af90e2021-06-04 16:57:15 -070011801 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11802 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011803 } finally {
11804 Binder.restoreCallingIdentity(identity);
11805 }
11806 }
11807
11808 /**
11809 * Register RCS provisioning callback.
11810 */
11811 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011812 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011813 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011814 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011815 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011816 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11817 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011818
11819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11820 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11821 }
joonhunshin4ac60942023-11-15 15:23:39 +000011822 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11823 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11824 Binder.getCallingUserHandle())) {
11825 if (!isImsAvailableOnDevice()) {
11826 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11827 "IMS not available on device.");
11828 }
11829 } else {
11830 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11831 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011832 }
11833
11834 final long identity = Binder.clearCallingIdentity();
11835 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011836 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011837 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011838 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11839 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011840 }
Hui Wang761a6682020-10-31 05:12:53 +000011841 } finally {
11842 Binder.restoreCallingIdentity(identity);
11843 }
11844 }
11845
11846 /**
11847 * Unregister RCS provisioning callback.
11848 */
11849 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011850 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011851 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011852 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011853 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011854 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11855 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011856
11857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11859 }
joonhunshin4ac60942023-11-15 15:23:39 +000011860
11861 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11862 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11863 Binder.getCallingUserHandle())) {
11864 if (!isImsAvailableOnDevice()) {
11865 // operation failed silently
11866 Rlog.w(LOG_TAG, "IMS not available on device.");
11867 return;
11868 }
11869 } else {
11870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11871 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11872 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011873 }
11874
11875 final long identity = Binder.clearCallingIdentity();
11876 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011877 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011878 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011879 } finally {
11880 Binder.restoreCallingIdentity(identity);
11881 }
11882 }
11883
11884 /**
11885 * trigger RCS reconfiguration.
11886 */
11887 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011888 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11889 "triggerRcsReconfiguration",
11890 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011891
11892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11893 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11894 }
joonhunshin4ac60942023-11-15 15:23:39 +000011895 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11896 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11897 Binder.getCallingUserHandle())) {
11898 if (!isImsAvailableOnDevice()) {
11899 // ProvisioningManager can not handle ServiceSpecificException.
11900 // Throw the IllegalStateException and annotate ProvisioningManager.
11901 throw new IllegalStateException("IMS not available on device.");
11902 }
11903 } else {
11904 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11905 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011906 }
11907
11908 final long identity = Binder.clearCallingIdentity();
11909 try {
11910 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11911 } finally {
11912 Binder.restoreCallingIdentity(identity);
11913 }
11914 }
11915
11916 /**
11917 * Provide the client configuration parameters of the RCS application.
11918 */
11919 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011920 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11921 "setRcsClientConfiguration",
11922 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011923
11924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11925 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11926 }
joonhunshin4ac60942023-11-15 15:23:39 +000011927 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11928 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11929 Binder.getCallingUserHandle())) {
11930 if (!isImsAvailableOnDevice()) {
11931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11932 "IMS not available on device.");
11933 }
11934 } else {
11935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11936 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011937 }
11938
11939 final long identity = Binder.clearCallingIdentity();
11940
11941 try {
11942 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11943 if (configBinder == null) {
11944 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011945 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11946 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011947 } else {
11948 configBinder.setRcsClientConfiguration(rcc);
11949 }
joonhunshin3e154242021-09-17 06:33:39 +000011950
11951 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11952 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011953 } catch (RemoteException e) {
11954 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011955 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11956 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011957 } finally {
11958 Binder.restoreCallingIdentity(identity);
11959 }
11960 }
11961
11962 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011963 * Enables or disables the test mode for RCS VoLTE single registration.
11964 */
11965 @Override
11966 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11968 "setRcsSingleRegistrationTestModeEnabled");
11969
11970 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11971 }
11972
11973 /**
11974 * Gets the test mode for RCS VoLTE single registration.
11975 */
11976 @Override
11977 public boolean getRcsSingleRegistrationTestModeEnabled() {
11978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11979 "getRcsSingleRegistrationTestModeEnabled");
11980
11981 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11982 }
11983
11984 /**
Hui Wang761a6682020-10-31 05:12:53 +000011985 * Overrides the config of RCS VoLTE single registration enabled for the device.
11986 */
11987 @Override
11988 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11990 "setDeviceSingleRegistrationEnabledOverride");
11991 enforceModifyPermission();
11992
11993 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11994 : Boolean.parseBoolean(enabledStr);
11995 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011996 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011997 }
11998
11999 /**
Tyler Gunn92479152021-01-20 16:30:10 -080012000 * Sends a device to device communication message. Only usable via shell.
12001 * @param message message to send.
12002 * @param value message value.
12003 */
12004 @Override
12005 public void sendDeviceToDeviceMessage(int message, int value) {
12006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012007 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012008 enforceModifyPermission();
12009
12010 final long identity = Binder.clearCallingIdentity();
12011 try {
12012 TelephonyConnectionService service =
12013 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12014 if (service == null) {
12015 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12016 return;
12017 }
12018 service.sendTestDeviceToDeviceMessage(message, value);
12019 } finally {
12020 Binder.restoreCallingIdentity(identity);
12021 }
12022 }
12023
Tyler Gunnbabbda02021-02-10 11:05:02 -080012024 /**
12025 * Sets the specified device to device transport active.
12026 * @param transport The transport to set active.
12027 */
12028 @Override
12029 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12031 "setActiveDeviceToDeviceTransport");
12032 enforceModifyPermission();
12033
12034 final long identity = Binder.clearCallingIdentity();
12035 try {
12036 TelephonyConnectionService service =
12037 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12038 if (service == null) {
12039 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12040 return;
12041 }
12042 service.setActiveDeviceToDeviceTransport(transport);
12043 } finally {
12044 Binder.restoreCallingIdentity(identity);
12045 }
12046 }
Tyler Gunn92479152021-01-20 16:30:10 -080012047
Tyler Gunnd4339262021-05-03 14:46:49 -070012048 @Override
12049 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12051 "setDeviceToDeviceForceEnabled");
12052
12053 final long identity = Binder.clearCallingIdentity();
12054 try {
12055 Arrays.stream(PhoneFactory.getPhones()).forEach(
12056 p -> {
12057 Phone thePhone = p.getImsPhone();
12058 if (thePhone != null && thePhone instanceof ImsPhone) {
12059 ImsPhone imsPhone = (ImsPhone) thePhone;
12060 CallTracker tracker = imsPhone.getCallTracker();
12061 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12062 ImsPhoneCallTracker imsPhoneCallTracker =
12063 (ImsPhoneCallTracker) tracker;
12064 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12065 }
12066 }
12067 }
12068 );
12069 } finally {
12070 Binder.restoreCallingIdentity(identity);
12071 }
12072 }
12073
Tyler Gunn92479152021-01-20 16:30:10 -080012074 /**
Hui Wang761a6682020-10-31 05:12:53 +000012075 * Gets the config of RCS VoLTE single registration enabled for the device.
12076 */
12077 @Override
12078 public boolean getDeviceSingleRegistrationEnabled() {
12079 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12080 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12081 }
12082
12083 /**
12084 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12085 */
12086 @Override
12087 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12088 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12089 "setCarrierSingleRegistrationEnabledOverride");
12090 enforceModifyPermission();
12091
12092 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12093 : Boolean.parseBoolean(enabledStr);
12094 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12095 subId, enabled);
12096 }
12097
12098 /**
12099 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12100 */
12101 @Override
12102 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12103 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12104 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12105 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012106
12107 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012108 * Overrides the ims feature validation result
12109 */
12110 @Override
12111 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12112 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12113 "setImsFeatureValidationOverride");
12114
12115 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12116 : Boolean.parseBoolean(enabledStr);
12117 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12118 subId, enabled);
12119 }
12120
12121 /**
12122 * Gets the ims feature validation override value
12123 */
12124 @Override
12125 public boolean getImsFeatureValidationOverride(int subId) {
12126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12127 "getImsFeatureValidationOverride");
12128 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12129 }
12130
12131 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012132 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12133 * their mobile plan.
12134 */
12135 @Override
12136 public String getMobileProvisioningUrl() {
12137 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12138 final long identity = Binder.clearCallingIdentity();
12139 try {
12140 return getDefaultPhone().getMobileProvisioningUrl();
12141 } finally {
12142 Binder.restoreCallingIdentity(identity);
12143 }
12144 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012145
James.cf Linbcdf8b32021-01-14 16:44:13 +080012146 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012147 * Get the EAB contact from the EAB database.
12148 */
12149 @Override
12150 public String getContactFromEab(String contact) {
12151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12152 enforceModifyPermission();
12153 final long identity = Binder.clearCallingIdentity();
12154 try {
12155 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12156 } finally {
12157 Binder.restoreCallingIdentity(identity);
12158 }
12159 }
12160
12161 /**
Calvin Pana1434322021-07-01 19:27:01 +080012162 * Get the EAB capability from the EAB database.
12163 */
12164 @Override
12165 public String getCapabilityFromEab(String contact) {
12166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12167 enforceModifyPermission();
12168 final long identity = Binder.clearCallingIdentity();
12169 try {
12170 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12171 } finally {
12172 Binder.restoreCallingIdentity(identity);
12173 }
12174 }
12175
12176 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012177 * Remove the EAB contacts from the EAB database.
12178 */
12179 @Override
12180 public int removeContactFromEab(int subId, String contacts) {
12181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12182 enforceModifyPermission();
12183 final long identity = Binder.clearCallingIdentity();
12184 try {
12185 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12186 } finally {
12187 Binder.restoreCallingIdentity(identity);
12188 }
12189 }
12190
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012191 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012192 public boolean getDeviceUceEnabled() {
12193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12194 final long identity = Binder.clearCallingIdentity();
12195 try {
12196 return mApp.getDeviceUceEnabled();
12197 } finally {
12198 Binder.restoreCallingIdentity(identity);
12199 }
12200 }
12201
12202 @Override
12203 public void setDeviceUceEnabled(boolean isEnabled) {
12204 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12205 final long identity = Binder.clearCallingIdentity();
12206 try {
12207 mApp.setDeviceUceEnabled(isEnabled);
12208 } finally {
12209 Binder.restoreCallingIdentity(identity);
12210 }
12211 }
12212
Brad Ebinger14d467f2021-02-12 06:18:28 +000012213 /**
12214 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12215 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12216 */
12217 // Used for SHELL command only right now.
12218 @Override
12219 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12220 List<String> featureTags) {
12221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12222 "addUceRegistrationOverrideShell");
12223 final long identity = Binder.clearCallingIdentity();
12224 try {
12225 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12226 new ArraySet<>(featureTags));
12227 } catch (ImsException e) {
12228 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12229 } finally {
12230 Binder.restoreCallingIdentity(identity);
12231 }
12232 }
12233
12234 /**
12235 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12236 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12237 */
12238 // Used for SHELL command only right now.
12239 @Override
12240 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12241 List<String> featureTags) {
12242 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12243 "removeUceRegistrationOverrideShell");
12244 final long identity = Binder.clearCallingIdentity();
12245 try {
12246 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12247 new ArraySet<>(featureTags));
12248 } catch (ImsException e) {
12249 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12250 } finally {
12251 Binder.restoreCallingIdentity(identity);
12252 }
12253 }
12254
12255 /**
12256 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12257 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12258 */
12259 // Used for SHELL command only right now.
12260 @Override
12261 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12263 "clearUceRegistrationOverrideShell");
12264 final long identity = Binder.clearCallingIdentity();
12265 try {
12266 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12267 } catch (ImsException e) {
12268 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12269 } finally {
12270 Binder.restoreCallingIdentity(identity);
12271 }
12272 }
12273
12274 /**
12275 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12276 */
12277 // Used for SHELL command only right now.
12278 @Override
12279 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12281 "getLatestRcsContactUceCapabilityShell");
12282 final long identity = Binder.clearCallingIdentity();
12283 try {
12284 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12285 } catch (ImsException e) {
12286 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12287 } finally {
12288 Binder.restoreCallingIdentity(identity);
12289 }
12290 }
12291
12292 /**
12293 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12294 * device does not have an active PUBLISH.
12295 */
12296 // Used for SHELL command only right now.
12297 @Override
12298 public String getLastUcePidfXmlShell(int subId) {
12299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12300 final long identity = Binder.clearCallingIdentity();
12301 try {
12302 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12303 } catch (ImsException e) {
12304 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12305 } finally {
12306 Binder.restoreCallingIdentity(identity);
12307 }
12308 }
12309
James.cf Line8713a42021-04-29 16:04:26 +080012310 /**
12311 * Remove UCE requests cannot be sent to the network status.
12312 */
12313 // Used for SHELL command only right now.
12314 @Override
12315 public boolean removeUceRequestDisallowedStatus(int subId) {
12316 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12317 final long identity = Binder.clearCallingIdentity();
12318 try {
12319 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12320 } catch (ImsException e) {
12321 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12322 } finally {
12323 Binder.restoreCallingIdentity(identity);
12324 }
12325 }
12326
James.cf Lin18bb9002021-05-25 01:37:38 +080012327 /**
12328 * Remove UCE requests cannot be sent to the network status.
12329 */
12330 // Used for SHELL command only.
12331 @Override
12332 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12333 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12334 final long identity = Binder.clearCallingIdentity();
12335 try {
12336 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12337 } catch (ImsException e) {
12338 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12339 } finally {
12340 Binder.restoreCallingIdentity(identity);
12341 }
12342 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012343
James.cf Lin4b784aa2021-01-31 03:25:15 +080012344 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012345 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12346 String callingPackage) {
12347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12348 mApp, subId, "setSignalStrengthUpdateRequest");
12349
joonhunshin4ac60942023-11-15 15:23:39 +000012350 enforceTelephonyFeatureWithException(callingPackage,
12351 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12352
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012353 final int callingUid = Binder.getCallingUid();
12354 // Verify that tha callingPackage belongs to the calling UID
12355 mApp.getSystemService(AppOpsManager.class)
12356 .checkPackage(callingUid, callingPackage);
12357
Rambo Wang3607f502021-02-01 21:51:40 -080012358 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012359
12360 final long identity = Binder.clearCallingIdentity();
12361 try {
12362 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12363 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12364
12365 if (result instanceof IllegalStateException) {
12366 throw (IllegalStateException) result;
12367 }
12368 } finally {
12369 Binder.restoreCallingIdentity(identity);
12370 }
12371 }
12372
12373 @Override
12374 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12375 String callingPackage) {
12376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12377 mApp, subId, "clearSignalStrengthUpdateRequest");
12378
joonhunshin4ac60942023-11-15 15:23:39 +000012379 enforceTelephonyFeatureWithException(callingPackage,
12380 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12381
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012382 final int callingUid = Binder.getCallingUid();
12383 // Verify that tha callingPackage belongs to the calling UID
12384 mApp.getSystemService(AppOpsManager.class)
12385 .checkPackage(callingUid, callingPackage);
12386
12387 final long identity = Binder.clearCallingIdentity();
12388 try {
12389 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12390 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12391
12392 if (result instanceof IllegalStateException) {
12393 throw (IllegalStateException) result;
12394 }
12395 } finally {
12396 Binder.restoreCallingIdentity(identity);
12397 }
12398 }
12399
Rambo Wang3607f502021-02-01 21:51:40 -080012400 private static void validateSignalStrengthUpdateRequest(Context context,
12401 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012402 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012403 // phone/system process do not have further restriction on request
12404 return;
12405 }
12406
12407 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012408 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012409 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012410 context.enforceCallingOrSelfPermission(
12411 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12412 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012413 }
12414
12415 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012416 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012417 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012418 || info.isEnabled()) {
12419 throw new IllegalArgumentException(
12420 "Only system can set hide fields in SignalThresholdInfo");
12421 }
12422
12423 // Thresholds length for each RAN need in range. This has been validated in
12424 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12425 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12426 final int[] thresholds = info.getThresholds();
12427 Objects.requireNonNull(thresholds);
12428 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12429 || thresholds.length
12430 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12431 throw new IllegalArgumentException(
12432 "thresholds length is out of range: " + thresholds.length);
12433 }
12434 }
12435 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012436
12437 /**
12438 * Gets the current phone capability.
12439 *
12440 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12441 * @return the PhoneCapability which describes the data connection capability of modem.
12442 * It's used to evaluate possible phone config change, for example from single
12443 * SIM device to multi-SIM device.
12444 */
12445 @Override
12446 public PhoneCapability getPhoneCapability() {
12447 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012448
12449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12450 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12451
SongFerngWang8236caa2021-01-17 21:51:44 +080012452 final long identity = Binder.clearCallingIdentity();
12453 try {
12454 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12455 } finally {
12456 Binder.restoreCallingIdentity(identity);
12457 }
12458 }
Michele Berionne5e411512020-11-13 02:36:59 +000012459
12460 /**
12461 * Prepare TelephonyManager for an unattended reboot. The reboot is
12462 * required to be done shortly after the API is invoked.
12463 */
12464 @Override
12465 @TelephonyManager.PrepareUnattendedRebootResult
12466 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012468 enforceRebootPermission();
12469
joonhunshin4ac60942023-11-15 15:23:39 +000012470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12471 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12472
Michele Berionne5e411512020-11-13 02:36:59 +000012473 final long identity = Binder.clearCallingIdentity();
12474 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012475 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012476 } finally {
12477 Binder.restoreCallingIdentity(identity);
12478 }
12479 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012480
12481 /**
12482 * Request to get the current slicing configuration including URSP rules and
12483 * NSSAIs (configured, allowed and rejected).
12484 *
12485 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12486 */
12487 @Override
12488 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012489 TelephonyPermissions
12490 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12491 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012492
joonhunshin4ac60942023-11-15 15:23:39 +000012493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12494 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12495 "getSlicingConfig");
12496
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012497 final long identity = Binder.clearCallingIdentity();
12498 try {
12499 Phone phone = getDefaultPhone();
12500 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12501 } finally {
12502 Binder.restoreCallingIdentity(identity);
12503 }
12504 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012505
12506 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012507 * Check whether the given premium capability is available for purchase from the carrier.
12508 *
12509 * @param capability The premium capability to check.
12510 * @param subId The subId to check the premium capability for.
12511 *
12512 * @return Whether the given premium capability is available to purchase.
12513 */
12514 @Override
12515 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12516 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12517 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12518 log("Premium capability "
12519 + TelephonyManager.convertPremiumCapabilityToString(capability)
12520 + " is not available for purchase due to missing permissions.");
12521 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12522 + "permission READ_BASIC_PHONE_STATE.");
12523 }
12524
joonhunshin4ac60942023-11-15 15:23:39 +000012525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12526 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12527
Sarah Chin2ec39f62022-08-31 17:03:26 -070012528 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012529 if (phone == null) {
12530 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12531 return false;
12532 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012533 final long identity = Binder.clearCallingIdentity();
12534 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012535 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012536 .isPremiumCapabilityAvailableForPurchase(capability);
12537 } finally {
12538 Binder.restoreCallingIdentity(identity);
12539 }
12540 }
12541
12542 /**
12543 * Purchase the given premium capability from the carrier.
12544 *
12545 * @param capability The premium capability to purchase.
12546 * @param callback The result of the purchase request.
12547 * @param subId The subId to purchase the premium capability for.
12548 */
12549 @Override
12550 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12551 log("purchasePremiumCapability: capability="
12552 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12553 + getCurrentPackageName());
12554
12555 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12556 mApp, "purchasePremiumCapability")) {
12557 log("purchasePremiumCapability "
12558 + TelephonyManager.convertPremiumCapabilityToString(capability)
12559 + " failed due to missing permissions.");
12560 throw new SecurityException("purchasePremiumCapability requires permission "
12561 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012562 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12563 mApp, "purchasePremiumCapability")) {
12564 log("purchasePremiumCapability "
12565 + TelephonyManager.convertPremiumCapabilityToString(capability)
12566 + " failed due to missing permissions.");
12567 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012568 }
12569
joonhunshin4ac60942023-11-15 15:23:39 +000012570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12571 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12572
Sarah Chin2ec39f62022-08-31 17:03:26 -070012573 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012574 if (phone == null) {
12575 try {
12576 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12577 callback.accept(result);
12578 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12579 } catch (RemoteException e) {
12580 String logStr = "Purchase premium capability "
12581 + TelephonyManager.convertPremiumCapabilityToString(capability)
12582 + " failed due to RemoteException handling null phone: " + e;
12583 if (DBG) log(logStr);
12584 AnomalyReporter.reportAnomaly(
12585 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12586 }
12587 return;
12588 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012589
12590 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012591 try {
Jack Yube3fa442024-09-16 14:39:45 -070012592 if (mFeatureFlags.hsumPackageManager()) {
12593 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12594 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12595 } else {
12596 callingProcess = mApp.getPackageManager().getApplicationInfo(
12597 getCurrentPackageName(), 0).processName;
12598 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012599 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012600 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012601 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012602
12603 boolean isVisible = false;
12604 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12605 if (am != null) {
12606 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12607 if (processes != null) {
12608 for (ActivityManager.RunningAppProcessInfo process : processes) {
12609 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012610 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012611 if (process.processName.equals(callingProcess) && process.importance
12612 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12613 isVisible = true;
12614 break;
12615 }
12616 }
12617 }
12618 }
12619
12620 if (!isVisible) {
12621 try {
12622 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12623 callback.accept(result);
12624 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12625 } catch (RemoteException e) {
12626 String logStr = "Purchase premium capability "
12627 + TelephonyManager.convertPremiumCapabilityToString(capability)
12628 + " failed due to RemoteException handling background application: " + e;
12629 if (DBG) log(logStr);
12630 AnomalyReporter.reportAnomaly(
12631 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12632 }
12633 return;
12634 }
12635
Sarah Chin71b3a852022-09-28 15:54:19 -070012636 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012637 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012638 }
12639
12640 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012641 * Register an IMS connection state callback
12642 */
12643 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012644 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12645 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012646 if (feature == ImsFeature.FEATURE_MMTEL) {
12647 // ImsMmTelManager
12648 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12649 TelephonyPermissions
12650 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12651 mApp, subId, "registerImsStateCallback");
12652 } else if (feature == ImsFeature.FEATURE_RCS) {
12653 // ImsRcsManager or SipDelegateManager
12654 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12655 Binder.getCallingUid(), "registerImsStateCallback",
12656 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12657 Manifest.permission.READ_PRECISE_PHONE_STATE,
12658 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12659 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12660 }
12661
12662 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12664 "IMS not available on device.");
12665 }
12666
12667 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12668 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12669 }
12670
12671 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12672 if (controller == null) {
12673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12674 "IMS not available on device.");
12675 }
12676
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012677 if (callingPackage == null) {
12678 callingPackage = getCurrentPackageName();
12679 }
12680
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012681 final long token = Binder.clearCallingIdentity();
12682 try {
12683 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012684 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012685 } catch (ImsException e) {
12686 throw new ServiceSpecificException(e.getCode());
12687 } finally {
12688 Binder.restoreCallingIdentity(token);
12689 }
12690 }
12691
12692 /**
12693 * Unregister an IMS connection state callback
12694 */
12695 @Override
12696 public void unregisterImsStateCallback(IImsStateCallback cb) {
12697 final long token = Binder.clearCallingIdentity();
12698 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12699 if (controller == null) {
12700 return;
12701 }
12702 try {
12703 controller.unregisterImsStateCallback(cb);
12704 } finally {
12705 Binder.restoreCallingIdentity(token);
12706 }
12707 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012708
12709 /**
12710 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12711 *
12712 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012713 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012714 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012715 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012716 * If there is current registered network this value will be same as the registered cell
12717 * identity. If the device goes out of service the previous cell identity is cached and
12718 * will be returned. If the cache age of the Cell identity is more than 24 hours
12719 * it will be cleared and null will be returned.
12720 *
12721 */
12722 @Override
12723 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12724 String callingFeatureId) {
12725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12726 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12727 LocationAccessPolicy.checkLocationPermission(mApp,
12728 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12729 .setCallingPackage(callingPackage)
12730 .setCallingFeatureId(callingFeatureId)
12731 .setCallingPid(Binder.getCallingPid())
12732 .setCallingUid(Binder.getCallingUid())
12733 .setMethod("getLastKnownCellIdentity")
12734 .setLogAsInfo(true)
12735 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12736 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12737 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12738 .build());
12739
12740 boolean hasFinePermission =
12741 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12742 if (!hasFinePermission
12743 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12744 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012745 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012746 }
12747
12748 final long identity = Binder.clearCallingIdentity();
12749 try {
Ling Mac28f0212023-03-24 16:07:15 -070012750 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012751 if (sst == null) return null;
12752 return sst.getLastKnownCellIdentity();
12753 } finally {
12754 Binder.restoreCallingIdentity(identity);
12755 }
12756 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012757
jimsun3b9ccac2021-10-26 15:01:23 +080012758 /**
12759 * Sets the modem service class Name that Telephony will bind to.
12760 *
12761 * @param serviceName The class name of the modem service.
12762 * @return true if the operation is succeed, otherwise false.
12763 */
12764 public boolean setModemService(String serviceName) {
12765 Log.d(LOG_TAG, "setModemService - " + serviceName);
12766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012768 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12769 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012770 return mPhoneConfigurationManager.setModemService(serviceName);
12771 }
12772
12773 /**
12774 * Return the class name of the currently bounded modem service.
12775 *
12776 * @return the class name of the modem service.
12777 */
12778 public String getModemService() {
12779 String result;
12780 Log.d(LOG_TAG, "getModemService");
12781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12782 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012783 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012784 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12785 "getModemService");
12786 result = mPhoneConfigurationManager.getModemService();
12787 Log.d(LOG_TAG, "result = " + result);
12788 return result;
12789 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012790
Hakjun Choi3ee81112023-12-19 15:40:58 +000012791 /**
12792 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12793 * including carrier config, entitlement server, and config update.
12794 *
12795 * @param subId subId The subscription ID of the carrier.
12796 *
12797 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12798 * be returned.
12799 *
12800 * @throws SecurityException if the caller doesn't have the required permission.
12801 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012802 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12803 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012804 final long identity = Binder.clearCallingIdentity();
12805 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012806 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012807 } finally {
12808 Binder.restoreCallingIdentity(identity);
12809 }
12810 }
12811
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012812 @Override
12813 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12814 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12815 mApp.enforceCallingOrSelfPermission(
12816 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12817 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12818
12819 final long identity = Binder.clearCallingIdentity();
12820 try {
12821 Phone phone = getPhone(subId);
12822 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012823 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12824 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012825 phone.setVoiceServiceStateOverride(hasService);
12826 } finally {
12827 Binder.restoreCallingIdentity(identity);
12828 }
12829 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012830
12831 /**
12832 * set removable eSIM as default eUICC.
12833 *
12834 * @hide
12835 */
12836 @Override
12837 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12838 enforceModifyPermission();
12839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12840
12841 final long identity = Binder.clearCallingIdentity();
12842 try {
12843 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12844 } finally {
12845 Binder.restoreCallingIdentity(identity);
12846 }
12847 }
12848
12849 /**
12850 * Returns whether the removable eSIM is default eUICC or not.
12851 *
12852 * @hide
12853 */
12854 @Override
12855 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12856 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12857 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12858
12859 final long identity = Binder.clearCallingIdentity();
12860 try {
12861 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12862 } finally {
12863 Binder.restoreCallingIdentity(identity);
12864 }
12865 }
12866
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012867 /**
12868 * Get the component name of the default app to direct respond-via-message intent for the
12869 * user associated with this subscription, update the cache if there is no respond-via-message
12870 * application currently configured for this user.
12871 * @return component name of the app and class to direct Respond Via Message intent to, or
12872 * {@code null} if the functionality is not supported.
12873 * @hide
12874 */
12875 @Override
12876 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12877 boolean updateIfNeeded) {
12878 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012879
joonhunshin4ac60942023-11-15 15:23:39 +000012880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12881 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12882 "getDefaultRespondViaMessageApplication");
12883
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012884 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12885
Grant Menkeb0372492024-09-19 18:01:29 -070012886 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12887 UserHandle mainUser = null;
12888 Context userContext = null;
12889 final long identity = Binder.clearCallingIdentity();
12890 try {
12891 mainUser = mUserManager.getMainUser();
12892 userContext = context.createContextAsUser(mainUser, 0);
12893 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12894 } finally {
12895 Binder.restoreCallingIdentity(identity);
12896 }
12897 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12898 updateIfNeeded, mainUser);
12899 } else {
12900 UserHandle userHandle = null;
12901 final long identity = Binder.clearCallingIdentity();
12902 try {
12903 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12904 } finally {
12905 Binder.restoreCallingIdentity(identity);
12906 }
12907 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12908 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012909 }
Grant Menkeb0372492024-09-19 18:01:29 -070012910
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012911 }
Jack Yuf5badd92022-12-08 00:50:53 -080012912
12913 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012914 * Set whether the device is able to connect with null ciphering or integrity
12915 * algorithms. This is a global setting and will apply to all active subscriptions
12916 * and all new subscriptions after this.
12917 *
12918 * @param enabled when true, null cipher and integrity algorithms are allowed.
12919 * @hide
12920 */
12921 @Override
12922 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12923 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12924 enforceModifyPermission();
12925 checkForNullCipherAndIntegritySupport();
12926
12927 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12928 // for listening to these preference changes and applying them immediately.
12929 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12930 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12931 editor.apply();
12932
12933 for (Phone phone: PhoneFactory.getPhones()) {
12934 phone.handleNullCipherEnabledChange();
12935 }
12936 }
12937
12938
12939 /**
12940 * Get whether the device is able to connect with null ciphering or integrity
12941 * algorithms. Note that this retrieves the phone-global preference and not
12942 * the state of the radio.
12943 *
12944 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12945 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12946 * version for this feature.
12947 * @hide
12948 */
12949 @Override
12950 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12951 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12952 enforceReadPermission();
12953 checkForNullCipherAndIntegritySupport();
12954 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12955 }
12956
12957 private void checkForNullCipherAndIntegritySupport() {
12958 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12959 throw new UnsupportedOperationException(
12960 "Null cipher and integrity operations require HAL 2.1 or above");
12961 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012962 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12963 throw new UnsupportedOperationException(
12964 "Null cipher and integrity operations unsupported by modem");
12965 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012966 }
12967
Gil Cukierman06403e12023-11-29 16:33:03 +000012968 private void checkForIdentifierDisclosureNotificationSupport() {
12969 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12970 throw new UnsupportedOperationException(
12971 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12972 + "above");
12973 }
12974 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12975 throw new UnsupportedOperationException(
12976 "Cellular identifier disclosure transparency operations unsupported by modem");
12977 }
12978 }
12979
Michael Groover826b71d2023-12-21 22:08:06 -060012980 private void checkForNullCipherNotificationSupport() {
12981 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12982 throw new UnsupportedOperationException(
12983 "Null cipher notification operations require HAL 2.2 or above");
12984 }
12985 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12986 throw new UnsupportedOperationException(
12987 "Null cipher notification operations unsupported by modem");
12988 }
12989 }
12990
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012991 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012992 * Get the SIM state for the slot index.
12993 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12994 *
12995 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12996 */
12997 @Override
12998 @SimState
12999 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070013000 if (!mApp.getResources().getBoolean(
13001 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13003 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13004 }
joonhunshin4ac60942023-11-15 15:23:39 +000013005
Jack Yuf5badd92022-12-08 00:50:53 -080013006 IccCardConstants.State simState;
13007 if (slotIndex < 0) {
13008 simState = IccCardConstants.State.UNKNOWN;
13009 } else {
13010 Phone phone = null;
13011 try {
13012 phone = PhoneFactory.getPhone(slotIndex);
13013 } catch (IllegalStateException e) {
13014 // ignore
13015 }
13016 if (phone == null) {
13017 simState = IccCardConstants.State.UNKNOWN;
13018 } else {
13019 IccCard icc = phone.getIccCard();
13020 if (icc == null) {
13021 simState = IccCardConstants.State.UNKNOWN;
13022 } else {
13023 simState = icc.getState();
13024 }
13025 }
13026 }
13027 return simState.ordinal();
13028 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013029
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013030 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13031 boolean enableLogcat,
13032 long logcatStartTimestampMillis, boolean enableTelecomDump,
13033 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013034 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013035 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13036 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13037 ecdDataBuilder
13038 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13039 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013040 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013041 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013042 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013043 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13044 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013045 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13046 Executors.newCachedThreadPool(), db,
13047 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013048 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013049 }
13050
13051 /**
13052 * Request telephony to persist state for debugging emergency call failures.
13053 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013054 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013055 * @param enableLogcat whether to collect logcat output
13056 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13057 * @param enableTelecomDump whether to collect telecom dumpsys
13058 * @param enableTelephonyDump whether to collect telephony dumpsys
13059 */
13060 @Override
13061 @RequiresPermission(android.Manifest.permission.DUMP)
13062 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13063 long logcatStartTimestampMillis, boolean enableTelecomDump,
13064 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013065 // Verify that the caller has READ_DROPBOX_DATA permission.
13066 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13067 && Flags.enableReadDropboxPermission()) {
13068 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13069 "persistEmergencyCallDiagnosticData");
13070 } else {
13071 // Otherwise, enforce legacy permission.
13072 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13073 "persistEmergencyCallDiagnosticData");
13074 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013075 final long identity = Binder.clearCallingIdentity();
13076 try {
13077 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13078 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13079
13080 } finally {
13081 Binder.restoreCallingIdentity(identity);
13082 }
13083 }
13084
Hui Wang9b5793a2022-12-05 14:38:06 -060013085 /**
13086 * Get current cell broadcast ranges.
13087 */
13088 @Override
13089 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13090 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13091 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13092 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013093
13094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13095 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13096
Hui Wang9b5793a2022-12-05 14:38:06 -060013097 final long identity = Binder.clearCallingIdentity();
13098 try {
13099 return getPhone(subId).getCellBroadcastIdRanges();
13100 } finally {
13101 Binder.restoreCallingIdentity(identity);
13102 }
13103 }
13104
13105 /**
13106 * Set reception of cell broadcast messages with the list of the given ranges
13107 *
13108 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13109 */
13110 @Override
13111 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13112 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13113 @Nullable IIntegerConsumer callback) {
13114 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13115 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013116
13117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13118 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13119
Hui Wang9b5793a2022-12-05 14:38:06 -060013120 final long identity = Binder.clearCallingIdentity();
13121 try {
13122 Phone phone = getPhoneFromSubId(subId);
13123 if (DBG) {
13124 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13125 }
13126 phone.setCellBroadcastIdRanges(ranges, result -> {
13127 if (callback != null) {
13128 try {
13129 callback.accept(result);
13130 } catch (RemoteException e) {
13131 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13132 }
13133 }
13134 });
13135 } finally {
13136 Binder.restoreCallingIdentity(identity);
13137 }
13138 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013139
13140 /**
13141 * Returns whether the device supports the domain selection service.
13142 *
13143 * @return {@code true} if the device supports the domain selection service.
13144 */
13145 @Override
13146 public boolean isDomainSelectionSupported() {
13147 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13148 "isDomainSelectionSupported");
13149
13150 final long identity = Binder.clearCallingIdentity();
13151 try {
13152 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13153 } finally {
13154 Binder.restoreCallingIdentity(identity);
13155 }
13156 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013157
13158 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013159 * Returns whether the AOSP domain selection service is supported.
13160 *
13161 * @return {@code true} if the AOSP domain selection service is supported,
13162 * {@code false} otherwise.
13163 */
13164 @Override
13165 public boolean isAospDomainSelectionService() {
13166 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13167 "isAospDomainSelectionService");
13168
13169 final long identity = Binder.clearCallingIdentity();
13170 try {
13171 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13172 String dssComponentName = mApp.getResources().getString(
13173 R.string.config_domain_selection_service_component_name);
13174 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13175 TelephonyDomainSelectionService.class.getName());
13176 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13177 + ", aosp=" + componentName.flattenToString());
13178 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13179 }
13180 } finally {
13181 Binder.restoreCallingIdentity(identity);
13182 }
13183 return false;
13184 }
13185
13186 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013187 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13188 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13189 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013190 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013191 * @param enableSatellite {@code true} to enable the satellite modem and
13192 * {@code false} to disable.
13193 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013194 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013195 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013196 *
13197 * @throws SecurityException if the caller doesn't have the required permission.
13198 */
13199 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013200 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013201 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013202 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013203 final long identity = Binder.clearCallingIdentity();
13204 try {
13205 if (enableSatellite) {
13206 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13207 @Override
13208 protected void onReceiveResult(int resultCode, Bundle resultData) {
13209 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13210 + ", resultData=" + resultData);
13211 boolean isAllowed = false;
13212 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13213 callback::accept);
13214 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13215 if (resultData != null
13216 && resultData.containsKey(
13217 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13218 isAllowed = resultData.getBoolean(
13219 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13220 } else {
13221 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13222 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013223 } else {
Hyosun322782b2024-10-24 11:37:59 +000013224 result.accept(resultCode);
13225 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013226 }
Hyosun322782b2024-10-24 11:37:59 +000013227 if (isAllowed) {
13228 mSatelliteController.requestSatelliteEnabled(
13229 enableSatellite, enableDemoMode, isEmergency, callback);
13230 } else {
13231 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13232 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013233 }
Hyosun322782b2024-10-24 11:37:59 +000013234 };
13235 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13236 resultReceiver, true);
13237 } else {
13238 // No need to check if satellite is allowed at current location when disabling
13239 // satellite
13240 mSatelliteController.requestSatelliteEnabled(
13241 enableSatellite, enableDemoMode, isEmergency, callback);
13242 }
13243 } finally {
13244 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013245 }
Sarah Chin503828c2023-02-01 23:54:20 -080013246 }
13247
13248 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013249 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013250 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013251 * @param result The result receiver that returns whether the satellite modem is enabled
13252 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013253 *
13254 * @throws SecurityException if the caller doesn't have the required permission.
13255 */
13256 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013257 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013258 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013259 final long identity = Binder.clearCallingIdentity();
13260 try {
13261 mSatelliteController.requestIsSatelliteEnabled(result);
13262 } finally {
13263 Binder.restoreCallingIdentity(identity);
13264 }
Sarah Chin503828c2023-02-01 23:54:20 -080013265 }
13266
13267 /**
Sarah Chin43457982023-02-15 17:50:38 -080013268 * Request to get whether the satellite service demo mode is enabled.
13269 *
Sarah Chin43457982023-02-15 17:50:38 -080013270 * @param result The result receiver that returns whether the satellite demo mode is enabled
13271 * if the request is successful or an error code if the request failed.
13272 *
13273 * @throws SecurityException if the caller doesn't have the required permission.
13274 */
13275 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013276 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013277 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013278 final long identity = Binder.clearCallingIdentity();
13279 try {
13280 mSatelliteController.requestIsDemoModeEnabled(result);
13281 } finally {
13282 Binder.restoreCallingIdentity(identity);
13283 }
Sarah Chin43457982023-02-15 17:50:38 -080013284 }
13285
13286 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013287 * Request to get whether the satellite service is enabled with emergency mode.
13288 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013289 * @param result The result receiver that returns whether the satellite emergency mode is
13290 * enabled if the request is successful or an error code if the request failed.
13291 *
13292 * @throws SecurityException if the caller doesn't have the required permission.
13293 */
13294 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013295 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013296 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013297 final long identity = Binder.clearCallingIdentity();
13298 try {
13299 mSatelliteController.requestIsEmergencyModeEnabled(result);
13300 } finally {
13301 Binder.restoreCallingIdentity(identity);
13302 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013303 }
13304
13305 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013306 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013307 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013308 * @param result The result receiver that returns whether the satellite service is supported on
13309 * the device if the request is successful or an error code if the request failed.
Hyosun322782b2024-10-24 11:37:59 +000013310 *
13311 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chin503828c2023-02-01 23:54:20 -080013312 */
13313 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013314 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013315 enforceSatelliteCommunicationPermission("requestIsSatelliteSupported");
13316 final long identity = Binder.clearCallingIdentity();
13317 try {
13318 mSatelliteController.requestIsSatelliteSupported(result);
13319 } finally {
13320 Binder.restoreCallingIdentity(identity);
13321 }
Sarah Chin503828c2023-02-01 23:54:20 -080013322 }
13323
13324 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013325 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013326 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013327 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13328 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013329 *
13330 * @throws SecurityException if the caller doesn't have required permission.
13331 */
13332 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013333 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013334 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013335 final long identity = Binder.clearCallingIdentity();
13336 try {
13337 mSatelliteController.requestSatelliteCapabilities(result);
13338 } finally {
13339 Binder.restoreCallingIdentity(identity);
13340 }
Sarah Chin503828c2023-02-01 23:54:20 -080013341 }
13342
13343 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013344 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013345 * This can be called by the pointing UI when the user starts pointing to the satellite.
13346 * Modem should continue to report the pointing input as the device or satellite moves.
13347 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013348 * @param resultCallback The callback to get the result of the request.
13349 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013350 *
13351 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013352 */
13353 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013354 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013355 @NonNull IIntegerConsumer resultCallback,
13356 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13357 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013358 final long identity = Binder.clearCallingIdentity();
13359 try {
13360 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13361 } finally {
13362 Binder.restoreCallingIdentity(identity);
13363 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013364 }
13365
13366 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013367 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013368 * This can be called by the pointing UI when the user stops pointing to the satellite.
13369 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013370 * @param resultCallback The callback to get the result of the request.
13371 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013372 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013373 *
13374 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013375 */
13376 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013377 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013378 @NonNull IIntegerConsumer resultCallback,
13379 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13380 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013381 final long identity = Binder.clearCallingIdentity();
13382 try {
13383 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13384 } finally {
13385 Binder.restoreCallingIdentity(identity);
13386 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013387 }
13388
13389 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013390 * Register the subscription with a satellite provider.
13391 * This is needed to register the subscription if the provider allows dynamic registration.
13392 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013393 * @param token The token to be used as a unique identifier for provisioning with satellite
13394 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013395 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013396 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013397 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013398 * @return The signal transport used by the caller to cancel the provision request,
13399 * or {@code null} if the request failed.
13400 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013401 * @throws SecurityException if the caller doesn't have the required permission.
13402 */
13403 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013404 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013405 @NonNull String token, @NonNull byte[] provisionData,
13406 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013407 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013408 final long identity = Binder.clearCallingIdentity();
13409 try {
13410 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013411 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013412 } finally {
13413 Binder.restoreCallingIdentity(identity);
13414 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013415 }
13416
13417 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013418 * Unregister the device/subscription with the satellite provider.
13419 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013420 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013421 * should report as deprovisioned.
13422 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013423 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013424 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013425 *
13426 * @throws SecurityException if the caller doesn't have the required permission.
13427 */
13428 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013429 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013430 @NonNull String token, @NonNull IIntegerConsumer callback) {
13431 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013432 final long identity = Binder.clearCallingIdentity();
13433 try {
13434 mSatelliteController.deprovisionSatelliteService(token, callback);
13435 } finally {
13436 Binder.restoreCallingIdentity(identity);
13437 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013438 }
13439
13440 /**
Sarah Chin43457982023-02-15 17:50:38 -080013441 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013442 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013443 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013444 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013445 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013446 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013447 * @throws SecurityException if the caller doesn't have the required permission.
13448 */
13449 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013450 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013451 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013452 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013453 final long identity = Binder.clearCallingIdentity();
13454 try {
13455 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13456 } finally {
13457 Binder.restoreCallingIdentity(identity);
13458 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013459 }
13460
13461 /**
Sarah Chin43457982023-02-15 17:50:38 -080013462 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013463 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013464 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013465 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013466 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013467 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013468 * @throws SecurityException if the caller doesn't have the required permission.
13469 */
13470 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013471 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013472 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013473 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013474 final long identity = Binder.clearCallingIdentity();
13475 try {
13476 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13477 } finally {
13478 Binder.restoreCallingIdentity(identity);
13479 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013480 }
13481
13482 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013483 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013484 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013485 * @param result The result receiver that returns whether the device is provisioned with a
13486 * satellite provider if the request is successful or an error code if the
13487 * request failed.
13488 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013489 * @throws SecurityException if the caller doesn't have the required permission.
13490 */
13491 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013492 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013493 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013494 final long identity = Binder.clearCallingIdentity();
13495 try {
13496 mSatelliteController.requestIsSatelliteProvisioned(result);
13497 } finally {
13498 Binder.restoreCallingIdentity(identity);
13499 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013500 }
13501
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013502 /**
Sarah Chin43457982023-02-15 17:50:38 -080013503 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013504 *
Sarah Chin43457982023-02-15 17:50:38 -080013505 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013506 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013507 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013508 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013509 * @throws SecurityException if the caller doesn't have the required permission.
13510 */
13511 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013512 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013513 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013514 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013515 final long identity = Binder.clearCallingIdentity();
13516 try {
13517 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13518 } finally {
13519 Binder.restoreCallingIdentity(identity);
13520 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013521 }
13522
13523 /**
Sarah Chin43457982023-02-15 17:50:38 -080013524 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013525 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013526 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013527 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013528 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013529 *
13530 * @throws SecurityException if the caller doesn't have the required permission.
13531 */
13532 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013533 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013534 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013535 final long identity = Binder.clearCallingIdentity();
13536 try {
13537 mSatelliteController.unregisterForModemStateChanged(callback);
13538 } finally {
13539 Binder.restoreCallingIdentity(identity);
13540 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013541 }
13542
13543 /**
13544 * Register to receive incoming datagrams over satellite.
13545 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013546 * @param callback The callback to handle incoming datagrams over satellite.
13547 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013548 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013549 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013550 * @throws SecurityException if the caller doesn't have the required permission.
13551 */
13552 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013553 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013554 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013555 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013556 final long identity = Binder.clearCallingIdentity();
13557 try {
13558 return mSatelliteController.registerForIncomingDatagram(callback);
13559 } finally {
13560 Binder.restoreCallingIdentity(identity);
13561 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013562 }
13563
13564 /**
13565 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013566 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013567 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013568 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013569 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013570 *
13571 * @throws SecurityException if the caller doesn't have the required permission.
13572 */
13573 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013574 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013575 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013576 final long identity = Binder.clearCallingIdentity();
13577 try {
13578 mSatelliteController.unregisterForIncomingDatagram(callback);
13579 } finally {
13580 Binder.restoreCallingIdentity(identity);
13581 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013582 }
13583
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013584 /**
13585 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013586 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013587 * This method requests modem to check if there are any pending datagrams to be received over
13588 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013589 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013590 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013591 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013592 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013593 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013594 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013595 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013596 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013597 final long identity = Binder.clearCallingIdentity();
13598 try {
13599 mSatelliteController.pollPendingDatagrams(callback);
13600 } finally {
13601 Binder.restoreCallingIdentity(identity);
13602 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013603 }
13604
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013605 /**
13606 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013607 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013608 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13609 * input to this method. Datagram received here will be passed down to modem without any
13610 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013611 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013612 * @param datagramType datagram type indicating whether the datagram is of type
13613 * SOS_SMS or LOCATION_SHARING.
13614 * @param datagram encoded gateway datagram which is encrypted by the caller.
13615 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013616 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13617 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013618 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013619 *
13620 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013621 */
13622 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013623 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013624 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13625 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013626 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013627 final long identity = Binder.clearCallingIdentity();
13628 try {
13629 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13630 callback);
13631 } finally {
13632 Binder.restoreCallingIdentity(identity);
13633 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013634 }
13635
Sarah Chindf715ec2023-02-13 13:46:24 -080013636 /**
13637 * Request to get whether satellite communication is allowed for the current location.
13638 *
13639 * @param subId The subId of the subscription to check whether satellite communication is
13640 * allowed for the current location for.
13641 * @param result The result receiver that returns whether satellite communication is allowed
13642 * for the current location if the request is successful or an error code
13643 * if the request failed.
13644 *
13645 * @throws SecurityException if the caller doesn't have the required permission.
13646 */
13647 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013648 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013649 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013650 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013651 final long identity = Binder.clearCallingIdentity();
13652 try {
13653 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13654 false);
13655 } finally {
13656 Binder.restoreCallingIdentity(identity);
13657 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013658 }
13659
13660 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013661 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013662 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013663 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013664 * be visible if the request is successful or an error code if the request failed.
13665 *
13666 * @throws SecurityException if the caller doesn't have the required permission.
13667 */
13668 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013669 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013670 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013671 final long identity = Binder.clearCallingIdentity();
13672 try {
13673 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13674 } finally {
13675 Binder.restoreCallingIdentity(identity);
13676 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013677 }
13678
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013679 /**
joonhunshin59104152024-09-11 09:55:35 +000013680 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013681 *
joonhunshin59104152024-09-11 09:55:35 +000013682 * @param isAligned {@code true} Device is aligned with the satellite.
13683 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013684 *
13685 * @throws SecurityException if the caller doesn't have required permission.
13686 */
13687 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13688
joonhunshin83da7cd2024-08-22 08:53:35 +000013689 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013690 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13691 final long identity = Binder.clearCallingIdentity();
13692 try {
13693 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13694 } finally {
13695 Binder.restoreCallingIdentity(identity);
13696 }
Hakjun Choiae365972023-04-25 11:00:31 +000013697 }
13698
13699 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013700 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13701 * by modem.
13702 *
13703 * @param subId The subId of the subscription to request for.
13704 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013705 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013706 * operation.
13707 *
13708 * @throws SecurityException if the caller doesn't have required permission.
13709 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013710 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013711 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13712 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013713 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013714 final long identity = Binder.clearCallingIdentity();
13715 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013716 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013717 } finally {
13718 Binder.restoreCallingIdentity(identity);
13719 }
13720 }
13721
13722 /**
13723 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13724 * by modem.
13725 *
13726 * @param subId The subId of the subscription to request for.
13727 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013728 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013729 * operation.
13730 *
13731 * @throws SecurityException if the caller doesn't have required permission.
13732 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013733 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013734 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13735 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013736 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013737 final long identity = Binder.clearCallingIdentity();
13738 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013739 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013740 } finally {
13741 Binder.restoreCallingIdentity(identity);
13742 }
13743 }
13744
13745 /**
13746 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013747 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013748 *
13749 * @param subId The subId of the subscription to request for.
13750 *
13751 * @return Integer array of reasons for disallowing satellite communication.
13752 *
13753 * @throws SecurityException if the caller doesn't have the required permission.
13754 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013755 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013756 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013757 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013758 final long identity = Binder.clearCallingIdentity();
13759 try {
13760 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013761 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013762 return reasonSet.stream().mapToInt(i->i).toArray();
13763 } finally {
13764 Binder.restoreCallingIdentity(identity);
13765 }
13766 }
13767
13768 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013769 * Request to get the signal strength of the satellite connection.
13770 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013771 * @param result Result receiver to get the error code of the request and the current signal
13772 * strength of the satellite connection.
13773 *
13774 * @throws SecurityException if the caller doesn't have required permission.
13775 */
13776 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013777 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013778 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13779 final long identity = Binder.clearCallingIdentity();
13780 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013781 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013782 } finally {
13783 Binder.restoreCallingIdentity(identity);
13784 }
13785 }
13786
13787 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013788 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13789 * is not successful, a {@link ServiceSpecificException} that contains
13790 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013791 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013792 * @param callback The callback to handle the NTN signal strength changed event. If the
13793 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13794 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13795 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13796 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013797 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013798 * @throws SecurityException If the caller doesn't have the required permission.
13799 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013800 */
13801 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013802 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013803 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013804 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13805 final long identity = Binder.clearCallingIdentity();
13806 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013807 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013808 } finally {
13809 Binder.restoreCallingIdentity(identity);
13810 }
13811 }
13812
13813 /**
13814 * Unregisters for NTN signal strength changed from satellite modem.
13815 * If callback was not registered before, the request will be ignored.
13816 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013817 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013818 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013819 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013820 *
13821 * @throws SecurityException if the caller doesn't have the required permission.
13822 */
13823 @Override
13824 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013825 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013826 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13827 final long identity = Binder.clearCallingIdentity();
13828 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013829 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013830 } finally {
13831 Binder.restoreCallingIdentity(identity);
13832 }
13833 }
13834
13835 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013836 * Registers for satellite capabilities change event from the satellite service.
13837 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013838 * @param callback The callback to handle the satellite capabilities changed event.
13839 *
13840 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13841 *
13842 * @throws SecurityException if the caller doesn't have required permission.
13843 */
13844 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013845 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013846 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013847 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013848 final long identity = Binder.clearCallingIdentity();
13849 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013850 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013851 } finally {
13852 Binder.restoreCallingIdentity(identity);
13853 }
13854 }
13855
13856 /**
13857 * Unregisters for satellite capabilities change event from the satellite service.
13858 * If callback was not registered before, the request will be ignored.
13859 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013860 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013861 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013862 *
13863 * @throws SecurityException if the caller doesn't have required permission.
13864 */
13865 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013866 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013867 @NonNull ISatelliteCapabilitiesCallback callback) {
13868 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013869 final long identity = Binder.clearCallingIdentity();
13870 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013871 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013872 } finally {
13873 Binder.restoreCallingIdentity(identity);
13874 }
13875 }
13876
13877 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013878 * Registers for the satellite supported state changed.
13879 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013880 * @param callback The callback to handle the satellite supported state changed event.
13881 *
13882 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13883 *
13884 * @throws SecurityException if the caller doesn't have the required permission.
13885 */
13886 @Override
13887 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013888 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013889 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013890 final long identity = Binder.clearCallingIdentity();
13891 try {
13892 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
13893 } finally {
13894 Binder.restoreCallingIdentity(identity);
13895 }
Hakjun Choif92ac752024-03-18 19:34:29 +000013896 }
13897
13898 /**
13899 * Unregisters for the satellite supported state changed.
13900 * If callback was not registered before, the request will be ignored.
13901 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013902 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013903 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000013904 *
13905 * @throws SecurityException if the caller doesn't have the required permission.
13906 */
13907 @Override
13908 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013909 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013910 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013911 final long identity = Binder.clearCallingIdentity();
13912 try {
13913 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
13914 } finally {
13915 Binder.restoreCallingIdentity(identity);
13916 }
Hakjun Choif92ac752024-03-18 19:34:29 +000013917 }
13918
13919 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013920 * This API can be used by only CTS to update satellite vendor service package name.
13921 *
13922 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013923 * @param provisioned Whether satellite should be provisioned or not.
13924 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013925 * @return {@code true} if the satellite vendor service is set successfully,
13926 * {@code false} otherwise.
13927 */
Hakjun Choic3393242024-06-26 18:02:08 +000013928 public boolean setSatelliteServicePackageName(String servicePackageName,
13929 String provisioned) {
13930 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13931 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013932 TelephonyPermissions.enforceShellOnly(
13933 Binder.getCallingUid(), "setSatelliteServicePackageName");
13934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13935 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13936 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000013937 final long identity = Binder.clearCallingIdentity();
13938 try {
13939 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13940 provisioned);
13941 } finally {
13942 Binder.restoreCallingIdentity(identity);
13943 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013944 }
13945
13946 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013947 * This API can be used by only CTS to update satellite gateway service package name.
13948 *
13949 * @param servicePackageName The package name of the satellite gateway service.
13950 * @return {@code true} if the satellite gateway service is set successfully,
13951 * {@code false} otherwise.
13952 */
13953 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13954 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13955 TelephonyPermissions.enforceShellOnly(
13956 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13958 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13959 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000013960 final long identity = Binder.clearCallingIdentity();
13961 try {
13962 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13963 } finally {
13964 Binder.restoreCallingIdentity(identity);
13965 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013966 }
13967
13968 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013969 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13970 *
13971 * @param packageName The package name of the satellite pointing UI app.
13972 * @param className The class name of the satellite pointing UI app.
13973 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13974 * {@code false} otherwise.
13975 */
13976 public boolean setSatellitePointingUiClassName(
13977 @Nullable String packageName, @Nullable String className) {
13978 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13979 + ", className=" + className);
13980 TelephonyPermissions.enforceShellOnly(
13981 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13983 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000013984 "setSatellitePointingUiClassName");
13985 final long identity = Binder.clearCallingIdentity();
13986 try {
13987 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13988 } finally {
13989 Binder.restoreCallingIdentity(identity);
13990 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070013991 }
13992
13993 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013994 * This API can be used by only CTS to update the timeout duration in milliseconds that
13995 * satellite should stay at listening mode to wait for the next incoming page before disabling
13996 * listening mode.
13997 *
13998 * @param timeoutMillis The timeout duration in millisecond.
13999 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14000 */
14001 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14002 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14003 TelephonyPermissions.enforceShellOnly(
14004 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14006 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14007 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014008 final long identity = Binder.clearCallingIdentity();
14009 try {
14010 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14011 } finally {
14012 Binder.restoreCallingIdentity(identity);
14013 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014014 }
14015
14016 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014017 * This API can be used by only CTS to control ingoring cellular service state event.
14018 *
14019 * @param enabled Whether to enable boolean config.
14020 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14021 */
14022 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014023 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014024 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014025 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14027 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014028 "setSatelliteIgnoreCellularServiceState");
14029 final long identity = Binder.clearCallingIdentity();
14030 try {
14031 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14032 } finally {
14033 Binder.restoreCallingIdentity(identity);
14034 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014035 }
14036
14037 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014038 * This API can be used by only CTS to override the timeout durations used by the
14039 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014040 *
14041 * @param timeoutMillis The timeout duration in millisecond.
14042 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14043 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014044 public boolean setDatagramControllerTimeoutDuration(
14045 boolean reset, int timeoutType, long timeoutMillis) {
14046 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14047 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014048 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014049 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14051 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014052 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014053 final long identity = Binder.clearCallingIdentity();
14054 try {
14055 return mSatelliteController.setDatagramControllerTimeoutDuration(
14056 reset, timeoutType, timeoutMillis);
14057 } finally {
14058 Binder.restoreCallingIdentity(identity);
14059 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014060 }
14061
14062 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014063 * This API can be used by only CTS to override the boolean configs used by the
14064 * DatagramController module.
14065 *
14066 * @param enable Whether to enable or disable boolean config.
14067 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14068 */
14069 public boolean setDatagramControllerBooleanConfig(
14070 boolean reset, int booleanType, boolean enable) {
14071 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14072 + ", reset=" + reset + ", enable=" + enable);
14073 TelephonyPermissions.enforceShellOnly(
14074 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14076 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14077 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014078 final long identity = Binder.clearCallingIdentity();
14079 try {
14080 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14081 enable);
14082 } finally {
14083 Binder.restoreCallingIdentity(identity);
14084 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014085 }
14086
14087
14088 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014089 * This API can be used by only CTS to override the timeout durations used by the
14090 * SatelliteController module.
14091 *
14092 * @param timeoutMillis The timeout duration in millisecond.
14093 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14094 */
14095 public boolean setSatelliteControllerTimeoutDuration(
14096 boolean reset, int timeoutType, long timeoutMillis) {
14097 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14098 + reset + ", timeoutMillis=" + timeoutMillis);
14099 TelephonyPermissions.enforceShellOnly(
14100 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14102 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14103 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014104 final long identity = Binder.clearCallingIdentity();
14105 try {
14106 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14107 reset, timeoutType, timeoutMillis);
14108 } finally {
14109 Binder.restoreCallingIdentity(identity);
14110 }
Hakjun Choiae365972023-04-25 11:00:31 +000014111 }
14112
14113 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014114 * This API can be used in only testing to override connectivity status in monitoring emergency
14115 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14116 *
14117 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14118 * of the following values to enable the override:
14119 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14120 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14121 * To disable the override, use -1 for handoverType.
14122 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14123 * delaySeconds after the emergency call starts.
14124 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14125 */
14126 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14127 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14128 TelephonyPermissions.enforceShellOnly(
14129 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14131 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14132 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014133 final long identity = Binder.clearCallingIdentity();
14134 try {
14135 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14136 handoverType, delaySeconds);
14137 } finally {
14138 Binder.restoreCallingIdentity(identity);
14139 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014140 }
14141
14142 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014143 * This API can be used in only testing to override oem-enabled satellite provision status.
14144 *
14145 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14146 * otherwise.
14147 * @param isProvisioned The overriding provision status.
14148 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14149 */
14150 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14151 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14152 + ", isProvisioned=" + isProvisioned);
14153 TelephonyPermissions.enforceShellOnly(
14154 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14156 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14157 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014158 final long identity = Binder.clearCallingIdentity();
14159 try {
14160 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14161 } finally {
14162 Binder.restoreCallingIdentity(identity);
14163 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014164 }
14165
14166 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014167 * This API should be used by only CTS tests to forcefully set telephony country codes.
14168 *
14169 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14170 */
14171 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14172 Map cachedNetworkCountryCodes, String locationCountryCode,
14173 long locationCountryCodeTimestampNanos) {
14174 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14175 + String.join(", ", currentNetworkCountryCodes)
14176 + ", locationCountryCode=" + locationCountryCode
14177 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14178 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14179 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014182 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14183 final long identity = Binder.clearCallingIdentity();
14184 try {
14185 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14186 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14187 cachedNetworkCountryCodes, locationCountryCode,
14188 locationCountryCodeTimestampNanos);
14189 } finally {
14190 Binder.restoreCallingIdentity(identity);
14191 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014192 }
14193
14194 /**
14195 * This API should be used by only CTS tests to override the overlay configs of satellite
14196 * access controller.
14197 *
14198 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14199 * otherwise.
14200 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14201 */
14202 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14203 String s2CellFile, long locationFreshDurationNanos,
14204 List<String> satelliteCountryCodes) {
14205 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14206 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14207 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14208 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
14209 ? String.join(", ", satelliteCountryCodes) : null));
14210 TelephonyPermissions.enforceShellOnly(
14211 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14213 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14214 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014215 final long identity = Binder.clearCallingIdentity();
14216 try {
14217 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
14218 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
14219 } finally {
14220 Binder.restoreCallingIdentity(identity);
14221 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014222 }
14223
14224 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014225 * This API can be used by only CTS to override the cached value for the device overlay config
14226 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14227 * outgoing satellite datagrams should be sent to modem in demo mode.
14228 *
14229 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14230 * satellite modem or not.
14231 *
14232 * @return {@code true} if the operation is successful, {@code false} otherwise.
14233 */
14234 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14235 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14236 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14237 + "disabled");
14238 return false;
14239 }
14240 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14241 TelephonyPermissions.enforceShellOnly(
14242 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14244 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14245 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014246 final long identity = Binder.clearCallingIdentity();
14247 try {
14248 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14249 shouldSendToModemInDemoMode);
14250 } finally {
14251 Binder.restoreCallingIdentity(identity);
14252 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014253 }
14254
14255 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014256 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14257 *
14258 * @param state a state indicates whether satellite access allowed state should be cached and
14259 * the allowed state.
14260 * @return {@code true} if the setting is successful, {@code false} otherwise.
14261 */
14262 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14263 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14264 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14265 + "oemEnabledSatelliteFlag is disabled");
14266 return false;
14267 }
14268
14269 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14270 + "state=" + state);
14271 TelephonyPermissions.enforceShellOnly(
14272 Binder.getCallingUid(),
14273 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14275 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14276 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014277 final long identity = Binder.clearCallingIdentity();
14278 try {
14279 return mSatelliteAccessController
14280 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14281 } finally {
14282 Binder.restoreCallingIdentity(identity);
14283 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014284 }
14285
14286 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014287 * Sets the service defined in ComponentName to be bound.
14288 *
14289 * This should only be used for testing.
14290 * @return {@code true} if the DomainSelectionService to bind to was set,
14291 * {@code false} otherwise.
14292 */
14293 @Override
14294 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14295 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14296
14297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14298 "setDomainSelectionServiceOverride");
14299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14300 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14301
14302 final long identity = Binder.clearCallingIdentity();
14303 try {
14304 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14305 return DomainSelectionResolver.getInstance()
14306 .setDomainSelectionServiceOverride(componentName);
14307 }
14308 } finally {
14309 Binder.restoreCallingIdentity(identity);
14310 }
14311 return false;
14312 }
14313
14314 /**
14315 * Clears the DomainSelectionService override.
14316 *
14317 * This should only be used for testing.
14318 * @return {@code true} if the DomainSelectionService override was cleared,
14319 * {@code false} otherwise.
14320 */
14321 @Override
14322 public boolean clearDomainSelectionServiceOverride() {
14323 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14324
14325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14326 "clearDomainSelectionServiceOverride");
14327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14328 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14329
14330 final long identity = Binder.clearCallingIdentity();
14331 try {
14332 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14333 return DomainSelectionResolver.getInstance()
14334 .clearDomainSelectionServiceOverride();
14335 }
14336 } finally {
14337 Binder.restoreCallingIdentity(identity);
14338 }
14339 return false;
14340 }
14341
14342 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014343 * Enable or disable notifications sent for cellular identifier disclosure events.
14344 *
14345 * Disclosure events are defined as instances where a device has sent a cellular identifier
14346 * on the Non-access stratum (NAS) before a security context is established. As a result the
14347 * identifier is sent in the clear, which has privacy implications for the user.
14348 *
14349 * @param enable if notifications about disclosure events should be enabled
14350 * @throws SecurityException if the caller does not have the required privileges
14351 * @throws UnsupportedOperationException if the modem does not support this feature.
14352 */
14353 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014354 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014355 enforceModifyPermission();
14356 checkForIdentifierDisclosureNotificationSupport();
14357
14358 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14359 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14360 editor.apply();
14361
14362 // Each phone instance is responsible for updating its respective modem immediately
14363 // after we've made a preference change.
14364 for (Phone phone : PhoneFactory.getPhones()) {
14365 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14366 }
14367 }
14368
14369 /**
14370 * Get whether or not cellular identifier disclosure notifications are enabled.
14371 *
14372 * @throws SecurityException if the caller does not have the required privileges
14373 * @throws UnsupportedOperationException if the modem does not support this feature.
14374 */
14375 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014376 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014377 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14378 checkForIdentifierDisclosureNotificationSupport();
14379 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14380 }
14381
14382 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014383 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14384 * are in use by the cellular modem.
14385 *
14386 * @throws IllegalStateException if the Telephony process is not currently available
14387 * @throws SecurityException if the caller does not have the required privileges
14388 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14389 * and integrity algorithms in use
14390 * @hide
14391 */
14392 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014393 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014394 enforceModifyPermission();
14395 checkForNullCipherNotificationSupport();
14396
14397 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14398 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14399 editor.apply();
14400
14401 // Each phone instance is responsible for updating its respective modem immediately
14402 // after a preference change.
14403 for (Phone phone : PhoneFactory.getPhones()) {
14404 phone.handleNullCipherNotificationPreferenceChanged();
14405 }
14406 }
14407
14408 /**
14409 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14410 * cellular modem.
14411 *
14412 * @throws IllegalStateException if the Telephony process is not currently available
14413 * @throws SecurityException if the caller does not have the required privileges
14414 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14415 * and integrity algorithms in use
14416 * @hide
14417 */
14418 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14419 public boolean isNullCipherNotificationsEnabled() {
14420 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14421 checkForNullCipherNotificationSupport();
14422 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14423 }
14424
14425 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014426 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14427 *
14428 * <p>This method behaves in one of the following ways:
14429 * <ul>
14430 * <li>return true : if the calling package has the appop permission {@link
14431 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14432 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14433 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14434 * Owner device identifier access check, or the calling package has carrier privileges</>
14435 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14436 * </ul>
14437 */
14438 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14439 String callingPackage, @Nullable String callingFeatureId, String message) {
14440 for (Phone phone : PhoneFactory.getPhones()) {
14441 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14442 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14443 return true;
14444 }
14445 }
14446 return false;
14447 }
arunvoddud7401012022-12-15 16:08:12 +000014448
14449 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014450 * @return The subscription manager service instance.
14451 */
14452 public SubscriptionManagerService getSubscriptionManagerService() {
14453 return SubscriptionManagerService.getInstance();
14454 }
14455
14456 /**
arunvoddud7401012022-12-15 16:08:12 +000014457 * Class binds the consumer[callback] and carrierId.
14458 */
14459 private static class CallerCallbackInfo {
14460 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014461 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014462
Steve Statia28b7cb32024-03-11 23:58:50 +000014463 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014464 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014465 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014466 }
14467
14468 public Consumer<Integer> getConsumer() {
14469 return mConsumer;
14470 }
14471
Steve Statia28b7cb32024-03-11 23:58:50 +000014472 public Set<Integer> getCarrierIds() {
14473 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014474 }
14475 }
joonhunshin4ac60942023-11-15 15:23:39 +000014476
14477 /*
14478 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14479 * But the context that is passed in is unused if the phone app is already alive.
14480 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14481 */
14482 @VisibleForTesting
14483 public void setPackageManager(PackageManager packageManager) {
14484 mPackageManager = packageManager;
14485 }
14486
14487 /*
Nate Myren453c3472024-03-13 11:28:11 -070014488 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14489 * But the context that is passed in is unused if the phone app is already alive.
14490 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14491 */
14492 @VisibleForTesting
14493 public void setAppOpsManager(AppOpsManager appOps) {
14494 mAppOps = appOps;
14495 }
14496
14497 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014498 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14499 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14500 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14501 */
14502 @VisibleForTesting
14503 public void setFeatureFlags(FeatureFlags featureFlags) {
14504 mFeatureFlags = featureFlags;
14505 }
14506
14507 /**
14508 * Make sure the device has required telephony feature
14509 *
14510 * @throws UnsupportedOperationException if the device does not have required telephony feature
14511 */
14512 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14513 @NonNull String telephonyFeature, @NonNull String methodName) {
14514 if (callingPackage == null || mPackageManager == null) {
14515 return;
14516 }
14517
14518 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14519 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014520 Binder.getCallingUserHandle())
14521 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14522 // Skip to check associated telephony feature,
14523 // if compatibility change is not enabled for the current process or
14524 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014525 return;
14526 }
14527
14528 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14529 throw new UnsupportedOperationException(
14530 methodName + " is unsupported without " + telephonyFeature);
14531 }
14532 }
youngtaecha5d483d52024-04-29 17:05:45 +000014533
14534 /**
14535 * Registers for the satellite communication allowed state changed.
14536 *
14537 * @param subId The subId of the subscription to register for the satellite communication
14538 * allowed state changed.
14539 * @param callback The callback to handle the satellite communication allowed
14540 * state changed event.
14541 *
14542 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14543 *
14544 * @throws SecurityException if the caller doesn't have the required permission.
14545 */
14546 @Override
14547 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14548 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14549 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014550 final long identity = Binder.clearCallingIdentity();
14551 try {
14552 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14553 subId, callback);
14554 } finally {
14555 Binder.restoreCallingIdentity(identity);
14556 }
youngtaecha5d483d52024-04-29 17:05:45 +000014557 }
14558
14559 /**
14560 * Unregisters for the satellite communication allowed state changed.
14561 * If callback was not registered before, the request will be ignored.
14562 *
14563 * @param subId The subId of the subscription to unregister for the satellite communication
14564 * allowed state changed.
14565 * @param callback The callback that was passed to
14566 * {@link #registerForCommunicationAllowedStateChanged(int,
14567 * ISatelliteCommunicationAllowedStateCallback)}. *
14568 * @throws SecurityException if the caller doesn't have the required permission.
14569 */
14570 @Override
14571 public void unregisterForCommunicationAllowedStateChanged(
14572 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14573 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014574 final long identity = Binder.clearCallingIdentity();
14575 try {
14576 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14577 callback);
14578 } finally {
14579 Binder.restoreCallingIdentity(identity);
14580 }
youngtaecha5d483d52024-04-29 17:05:45 +000014581 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014582
14583 /**
14584 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14585 *
14586 * @param subId The subId of the subscription to the satellite session stats for.
14587 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14588 * if the request is successful or an error code if the request failed.
14589 *
14590 * @throws SecurityException if the caller doesn't have required permission.
14591 */
14592 @Override
14593 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14594 enforceModifyPermission();
14595 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014596 final long identity = Binder.clearCallingIdentity();
14597 try {
14598 mSatelliteController.requestSatelliteSessionStats(subId, result);
14599 } finally {
14600 Binder.restoreCallingIdentity(identity);
14601 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014602 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014603
14604 /**
14605 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14606 *
14607 * @param result The result receiver, which returns the list of prioritized satellite tokens
14608 * to be used for provision if the request is successful or an error code if the request failed.
14609 *
14610 * @throws SecurityException if the caller doesn't have the required permission.
14611 */
14612 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014613 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14614 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014615 final long identity = Binder.clearCallingIdentity();
14616 try {
14617 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14618 } finally {
14619 Binder.restoreCallingIdentity(identity);
14620 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014621 }
14622
14623 /**
14624 * Deliver the list of provisioned satellite subscriber ids.
14625 *
14626 * @param list List of provisioned satellite subscriber ids.
14627 * @param result The result receiver that returns whether deliver success or fail.
14628 *
14629 * @throws SecurityException if the caller doesn't have the required permission.
14630 */
14631 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014632 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014633 @NonNull ResultReceiver result) {
14634 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014635 final long identity = Binder.clearCallingIdentity();
14636 try {
14637 mSatelliteController.provisionSatellite(list, result);
14638 } finally {
14639 Binder.restoreCallingIdentity(identity);
14640 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014641 }
Hyosund6aaf062024-08-23 23:02:10 +000014642
14643 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014644 * Deliver the list of deprovisioned satellite subscriber ids.
14645 *
14646 * @param list List of deprovisioned satellite subscriber ids.
14647 * @param result The result receiver that returns whether deliver success or fail.
14648 *
14649 * @throws SecurityException if the caller doesn't have the required permission.
14650 */
14651 @Override
14652 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14653 @NonNull ResultReceiver result) {
14654 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14655 final long identity = Binder.clearCallingIdentity();
14656 try {
14657 mSatelliteController.deprovisionSatellite(list, result);
14658 } finally {
14659 Binder.restoreCallingIdentity(identity);
14660 }
14661 }
14662
14663 /**
Hyosund6aaf062024-08-23 23:02:10 +000014664 * This API can be used by only CTS to override the cached value for the device overlay config
14665 * value :
14666 * config_satellite_gateway_service_package and
14667 * config_satellite_carrier_roaming_esos_provisioned_class.
14668 * These values are set before sending an intent to broadcast there are any change to list of
14669 * subscriber informations.
14670 *
14671 * @param name the name is one of the following that constitute an intent.
14672 * Component package name, or component class name.
14673 * @return {@code true} if the setting is successful, {@code false} otherwise.
14674 */
14675 @Override
14676 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14677 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14678 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14679 + " carrierRoamingNbIotNtn is disabled");
14680 return false;
14681 }
14682 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14683 TelephonyPermissions.enforceShellOnly(
14684 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14686 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14687 "setSatelliteSubscriberIdListChangedIntentComponent");
14688 final long identity = Binder.clearCallingIdentity();
14689 try {
14690 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14691 } finally {
14692 Binder.restoreCallingIdentity(identity);
14693 }
14694 }
Jack Yu26735292024-09-25 14:33:49 -070014695
14696 /**
14697 * This API can be used by only CTS to override the Euicc UI component.
14698 *
14699 * @param componentName ui component to be launched for testing. {@code null} to reset.
14700 *
14701 * @hide
14702 */
14703 @Override
14704 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14705 enforceModifyPermission();
14706 log("setTestEuiccUiComponent: " + componentName);
14707 mTestEuiccUiComponent = componentName;
14708 }
14709
14710 /**
14711 * This API can be used by only CTS to retrieve the Euicc UI component.
14712 *
14713 * @return Euicc UI component. {@code null} if not available.
14714 * @hide
14715 */
14716 @Override
14717 @Nullable
14718 public ComponentName getTestEuiccUiComponent() {
14719 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14720 return mTestEuiccUiComponent;
14721 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014722
14723 /**
14724 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14725 *
14726 * @param state to update Ntn Eligibility.
14727 * @param resetRequired to reset the overridden flag in satellite controller.
14728 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14729 */
14730 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14731 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014732 final long identity = Binder.clearCallingIdentity();
14733 try {
14734 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14735 resetRequired);
14736 } finally {
14737 Binder.restoreCallingIdentity(identity);
14738 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014739 }
Jack Yufa8ed012023-02-11 15:42:28 -080014740}