blob: 4624884eb09ea0c461e444f369635a35d60b58d4 [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
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800448 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449
Derek Tan97ebb422014-09-05 16:55:38 -0700450 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
451 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800452 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800453 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700454
Michelecea4cf22018-12-21 15:00:11 -0800455 // String to store multi SIM allowed
456 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
457
Derek Tan740e1672017-06-27 14:56:27 -0700458 // The AID of ISD-R.
459 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
460
yinxub1bed742017-04-17 11:45:04 -0700461 private NetworkScanRequestTracker mNetworkScanRequestTracker;
462
David Kelly5e06a7f2018-03-12 14:10:59 +0000463 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
464 private static final int MANUFACTURER_CODE_LENGTH = 8;
465
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800467 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800468
Sarah Chin2ec39f62022-08-31 17:03:26 -0700469 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
470 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
471
Derek Tan89e89d42014-07-08 17:00:10 -0700472 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 * Experiment flag to enable erase modem config on reset network, default value is false
474 */
475 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
476 "reset_network_erase_modem_config_enabled";
477
Rambo Wang0f050d82021-02-12 11:43:36 -0800478 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800479
Gary Jian76280a42022-12-07 16:18:33 +0800480 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
481
arunvoddub1365e62024-07-31 09:42:31 +0000482 private static final int LINE1_NUMBER_MAX_LEN = 50;
483
sandeepjsb6c87872021-09-27 15:34:44 +0000484 /**
485 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
486 * one ICCID active at the same time.
487 * Apps should use below API signatures if targeting SDK is T and beyond.
488 *
489 * @hide
490 */
491 @ChangeId
492 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
493 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800494
Naina Nallurid63128d2019-09-17 14:10:30 -0700495 /**
Chen Xu540470b2021-12-14 17:15:47 -0800496 * Apps targeting on Android T and beyond will get exception whenever icc close channel
497 * operation fails.
498 */
499 @ChangeId
500 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
501 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
502
503 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 * A request object to use for transmitting data to an ICC.
505 */
506 private static final class IccAPDUArgument {
507 public int channel, cla, command, p1, p2, p3;
508 public String data;
509
510 public IccAPDUArgument(int channel, int cla, int command,
511 int p1, int p2, int p3, String data) {
512 this.channel = channel;
513 this.cla = cla;
514 this.command = command;
515 this.p1 = p1;
516 this.p2 = p2;
517 this.p3 = p3;
518 this.data = data;
519 }
520 }
521
522 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700523 * A request object to use for transmitting data to an ICC.
524 */
525 private static final class ManualNetworkSelectionArgument {
526 public OperatorInfo operatorInfo;
527 public boolean persistSelection;
528
529 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
530 this.operatorInfo = operatorInfo;
531 this.persistSelection = persistSelection;
532 }
533 }
534
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 private static final class PurchasePremiumCapabilityArgument {
536 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700537 public @NonNull IIntegerConsumer callback;
538
539 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800540 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700542 this.callback = callback;
543 }
544 }
545
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700546 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
548 * request after sending. The main thread will notify the request when it is complete.
549 */
550 private static final class MainThreadRequest {
551 /** The argument to use for the request */
552 public Object argument;
553 /** The result of the request that is run on the main thread */
554 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800555 // The subscriber id that this request applies to. Defaults to
556 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
557 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558
Nathan Harold92bed182018-10-12 18:16:49 -0700559 // In cases where subId is unavailable, the caller needs to specify the phone.
560 public Phone phone;
561
vagdeviaf9a5b92018-08-15 16:01:53 -0700562 public WorkSource workSource;
563
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 public MainThreadRequest(Object argument) {
565 this.argument = argument;
566 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800567
Nathan Harold92bed182018-10-12 18:16:49 -0700568 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
569 this.argument = argument;
570 if (phone != null) {
571 this.phone = phone;
572 }
573 this.workSource = workSource;
574 }
575
vagdeviaf9a5b92018-08-15 16:01:53 -0700576 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800577 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800578 if (subId != null) {
579 this.subId = subId;
580 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700581 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 }
584
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800585 private static final class IncomingThirdPartyCallArgs {
586 public final ComponentName component;
587 public final String callId;
588 public final String callerDisplayName;
589
590 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
591 String callerDisplayName) {
592 this.component = component;
593 this.callId = callId;
594 this.callerDisplayName = callerDisplayName;
595 }
596 }
597
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598 /**
599 * A handler that processes messages on the main thread in the phone process. Since many
600 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
601 * inbound binder threads to the main thread in the phone process. The Binder thread
602 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
603 * on, which will be notified when the operation completes and will contain the result of the
604 * request.
605 *
606 * <p>If a MainThreadRequest object is provided in the msg.obj field,
607 * note that request.result must be set to something non-null for the calling thread to
608 * unblock.
609 */
610 private final class MainThreadHandler extends Handler {
611 @Override
612 public void handleMessage(Message msg) {
613 MainThreadRequest request;
614 Message onCompleted;
615 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000616 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800618 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619
620 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 case CMD_HANDLE_USSD_REQUEST: {
622 request = (MainThreadRequest) msg.obj;
623 final Phone phone = getPhoneFromRequest(request);
624 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800625 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700627
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 if (!isUssdApiAllowed(request.subId)) {
629 // Carrier does not support use of this API, return failure.
630 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
631 UssdResponse response = new UssdResponse(ussdRequest, null);
632 Bundle returnData = new Bundle();
633 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
634 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700635
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 request.result = true;
637 notifyRequester(request);
638 return;
639 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700640
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 try {
642 request.result = phone != null
643 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
644 } catch (CallStateException cse) {
645 request.result = false;
646 }
647 // Wake up the requesting thread
648 notifyRequester(request);
649 break;
pkanwar32d516d2016-10-14 19:37:38 -0700650 }
651
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700654 final Phone phone = getPhoneFromRequest(request);
655 request.result = phone != null ?
656 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
657 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000666 uiccPort = getUiccPortFromRequest(request);
667 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800669 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800673 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000674 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800675 iccArgument.channel, iccArgument.cla, iccArgument.command,
676 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
677 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 ar = (AsyncResult) msg.obj;
683 request = (MainThreadRequest) ar.userObj;
684 if (ar.exception == null && ar.result != null) {
685 request.result = ar.result;
686 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 if (ar.result == null) {
689 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800690 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800692 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 } else {
694 loge("iccTransmitApduLogicalChannel: Unknown exception");
695 }
696 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700697 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 break;
699
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
701 request = (MainThreadRequest) msg.obj;
702 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000703 uiccPort = getUiccPortFromRequest(request);
704 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 } else {
709 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800710 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800712 iccArgument.cla, iccArgument.command, iccArgument.p1,
713 iccArgument.p2,
714 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 }
716 break;
717
718 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
719 ar = (AsyncResult) msg.obj;
720 request = (MainThreadRequest) ar.userObj;
721 if (ar.exception == null && ar.result != null) {
722 request.result = ar.result;
723 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800724 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 if (ar.result == null) {
726 loge("iccTransmitApduBasicChannel: Empty response");
727 } else if (ar.exception instanceof CommandException) {
728 loge("iccTransmitApduBasicChannel: CommandException: " +
729 ar.exception);
730 } else {
731 loge("iccTransmitApduBasicChannel: Unknown exception");
732 }
733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 break;
736
737 case CMD_EXCHANGE_SIM_IO:
738 request = (MainThreadRequest) msg.obj;
739 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000740 uiccPort = getUiccPortFromRequest(request);
741 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800743 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700745 } else {
746 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
747 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000748 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700749 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
750 iccArgument.data, onCompleted);
751 }
752 break;
753
754 case EVENT_EXCHANGE_SIM_IO_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result;
759 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800760 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 break;
764
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 case CMD_SEND_ENVELOPE:
766 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000767 uiccPort = getUiccPortFromRequest(request);
768 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800770 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 } else {
773 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800774 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 break;
777
778 case EVENT_SEND_ENVELOPE_DONE:
779 ar = (AsyncResult) msg.obj;
780 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700781 if (ar.exception == null && ar.result != null) {
782 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800783 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800784 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700785 if (ar.result == null) {
786 loge("sendEnvelopeWithStatus: Empty response");
787 } else if (ar.exception instanceof CommandException) {
788 loge("sendEnvelopeWithStatus: CommandException: " +
789 ar.exception);
790 } else {
791 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
792 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800793 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700794 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800795 break;
796
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 case CMD_OPEN_CHANNEL:
798 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000799 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800800 IccLogicalChannelRequest openChannelRequest =
801 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000802 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800804 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800805 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700806 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700807 } else {
808 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800809 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
810 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 break;
813
814 case EVENT_OPEN_CHANNEL_DONE:
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700818 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700819 int[] result = (int[]) ar.result;
820 int channelId = result[0];
821 byte[] selectResponse = null;
822 if (result.length > 1) {
823 selectResponse = new byte[result.length - 1];
824 for (int i = 1; i < result.length; ++i) {
825 selectResponse[i - 1] = (byte) result[i];
826 }
827 }
828 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800829 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800830
831 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700832 if (uiccPort == null) {
833 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
834 } else {
835 IccLogicalChannelRequest channelRequest =
836 (IccLogicalChannelRequest) request.argument;
837 channelRequest.channel = channelId;
838 uiccPort.onLogicalChannelOpened(channelRequest);
839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700840 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 if (ar.result == null) {
842 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700844 if (ar.exception != null) {
845 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
846 }
847
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700848 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700849 if (ar.exception instanceof CommandException) {
850 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800851 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700852 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700854 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700855 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700856 }
857 }
858 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800859 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700861 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700862 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 break;
864
865 case CMD_CLOSE_CHANNEL:
866 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000867 uiccPort = getUiccPortFromRequest(request);
868 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700869 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800870 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800871 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800872 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700873 } else {
874 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000875 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700876 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 break;
878
879 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null) {
883 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800884 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700885 if (uiccPort == null) {
886 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
887 } else {
888 final int channelId = (Integer) request.argument;
889 uiccPort.onLogicalChannelClosed(channelId);
890 }
Chen Xu540470b2021-12-14 17:15:47 -0800891 } else {
892 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800893 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800894 if (ar.exception instanceof CommandException) {
895 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
896 CommandException.Error error =
897 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800898 if (error == CommandException.Error.INVALID_ARGUMENTS) {
899 // should only throw exceptions from the binder threads.
900 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800901 "iccCloseLogicalChannel: invalid argument ");
902 }
903 } else {
904 loge("iccCloseLogicalChannel: Unknown exception");
905 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800906 request.result = (exception != null) ? exception :
907 new IllegalStateException(
908 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800909 }
910 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
913 case CMD_NV_READ_ITEM:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
917 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800918 break;
919
920 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700921 ar = (AsyncResult) msg.obj;
922 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800923 if (ar.exception == null && ar.result != null) {
924 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800926 request.result = "";
927 if (ar.result == null) {
928 loge("nvReadItem: Empty response");
929 } else if (ar.exception instanceof CommandException) {
930 loge("nvReadItem: CommandException: " +
931 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800933 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700934 }
935 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700936 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700937 break;
938
Jake Hambye994d462014-02-03 13:10:13 -0800939 case CMD_NV_WRITE_ITEM:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
942 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800943 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700944 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
947 case EVENT_NV_WRITE_ITEM_DONE:
948 handleNullReturnEvent(msg, "nvWriteItem");
949 break;
950
951 case CMD_NV_WRITE_CDMA_PRL:
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800954 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800955 break;
956
957 case EVENT_NV_WRITE_CDMA_PRL_DONE:
958 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
959 break;
960
chen xu6dac5ab2018-10-26 17:39:23 -0700961 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800962 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700963 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800964 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800965 break;
966
chen xu6dac5ab2018-10-26 17:39:23 -0700967 case EVENT_RESET_MODEM_CONFIG_DONE:
968 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800969 break;
970
Sooraj Sasindran37444802020-08-11 10:40:43 -0700971 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
974 request);
975 Phone phone = getPhoneFromRequest(request);
976 if (phone != null) {
977 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
978 } else {
979 loge("isNRDualConnectivityEnabled: No phone object");
980 request.result = false;
981 notifyRequester(request);
982 }
983 break;
984 }
985
986 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 if (ar.exception == null && ar.result != null) {
990 request.result = ar.result;
991 } else {
992 // request.result must be set to something non-null
993 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700994 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700995 request.result = ar.result;
996 } else {
997 request.result = false;
998 }
999 if (ar.result == null) {
1000 loge("isNRDualConnectivityEnabled: Empty response");
1001 } else if (ar.exception instanceof CommandException) {
1002 loge("isNRDualConnectivityEnabled: CommandException: "
1003 + ar.exception);
1004 } else {
1005 loge("isNRDualConnectivityEnabled: Unknown exception");
1006 }
1007 }
1008 notifyRequester(request);
1009 break;
1010
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001011 case CMD_IS_VONR_ENABLED: {
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1014 request);
1015 Phone phone = getPhoneFromRequest(request);
1016 if (phone != null) {
1017 phone.isVoNrEnabled(onCompleted, request.workSource);
1018 } else {
1019 loge("isVoNrEnabled: No phone object");
1020 request.result = false;
1021 notifyRequester(request);
1022 }
1023 break;
1024 }
1025
1026 case EVENT_IS_VONR_ENABLED_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception == null && ar.result != null) {
1030 request.result = ar.result;
1031 } else {
1032 // request.result must be set to something non-null
1033 // for the calling thread to unblock
1034 if (ar.result != null) {
1035 request.result = ar.result;
1036 } else {
1037 request.result = false;
1038 }
1039 if (ar.result == null) {
1040 loge("isVoNrEnabled: Empty response");
1041 } else if (ar.exception instanceof CommandException) {
1042 loge("isVoNrEnabled: CommandException: "
1043 + ar.exception);
1044 } else {
1045 loge("isVoNrEnabled: Unknown exception");
1046 }
1047 }
1048 notifyRequester(request);
1049 break;
1050
Sooraj Sasindran37444802020-08-11 10:40:43 -07001051 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1054 Phone phone = getPhoneFromRequest(request);
1055 if (phone != null) {
1056 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1057 request.workSource);
1058 } else {
1059 loge("enableNrDualConnectivity: No phone object");
1060 request.result =
1061 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1062 notifyRequester(request);
1063 }
1064 break;
1065 }
1066
1067 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
1070 if (ar.exception == null) {
1071 request.result =
1072 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1073 } else {
1074 request.result =
1075 TelephonyManager
1076 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1077 if (ar.exception instanceof CommandException) {
1078 CommandException.Error error =
1079 ((CommandException) (ar.exception)).getCommandError();
1080 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1081 request.result =
1082 TelephonyManager
1083 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001084 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1085 request.result =
1086 TelephonyManager
1087 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001088 }
1089 loge("enableNrDualConnectivity" + ": CommandException: "
1090 + ar.exception);
1091 } else {
1092 loge("enableNrDualConnectivity" + ": Unknown exception");
1093 }
1094 }
1095 notifyRequester(request);
1096 break;
1097 }
1098
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001099 case CMD_ENABLE_VONR: {
1100 request = (MainThreadRequest) msg.obj;
1101 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1102 Phone phone = getPhoneFromRequest(request);
1103 if (phone != null) {
1104 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1105 request.workSource);
1106 } else {
1107 loge("setVoNrEnabled: No phone object");
1108 request.result =
1109 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1110 notifyRequester(request);
1111 }
1112 break;
1113 }
1114
1115 case EVENT_ENABLE_VONR_DONE: {
1116 ar = (AsyncResult) msg.obj;
1117 request = (MainThreadRequest) ar.userObj;
1118 if (ar.exception == null) {
1119 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1120 } else {
1121 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1126 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1128 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1129 } else {
1130 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1131 }
1132 loge("setVoNrEnabled" + ": CommandException: "
1133 + ar.exception);
1134 } else {
1135 loge("setVoNrEnabled" + ": Unknown exception");
1136 }
1137 }
1138 notifyRequester(request);
1139 break;
1140 }
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1145 request);
1146 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 break;
1148
SongFerngWang3ef3e072020-12-21 16:41:52 +08001149 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 if (ar.exception == null && ar.result != null) {
1153 request.result = ar.result; // Integer
1154 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301155 // request.result must be set to something non-null
1156 // for the calling thread to unblock
1157 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001161 loge("getAllowedNetworkTypesBitmask: CommandException: "
1162 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001165 }
1166 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 break;
1169
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001172 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1173 request);
1174 Pair<Integer, Long> reasonWithNetworkTypes =
1175 (Pair<Integer, Long>) request.argument;
1176 getPhoneFromRequest(request).setAllowedNetworkTypes(
1177 reasonWithNetworkTypes.first,
1178 reasonWithNetworkTypes.second,
1179 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001180 break;
1181
SongFerngWang3ef3e072020-12-21 16:41:52 +08001182 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1183 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001184 break;
1185
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001186 case CMD_SET_VOICEMAIL_NUMBER:
1187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1189 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001190 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1191 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001192 break;
1193
1194 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1195 handleNullReturnEvent(msg, "setVoicemailNumber");
1196 break;
1197
Stuart Scott54788802015-03-30 13:18:01 -07001198 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1199 request = (MainThreadRequest) msg.obj;
1200 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1201 request);
1202 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1203 break;
1204
1205 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1206 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1207 break;
1208
Shishir Agrawal302c8692015-06-19 13:49:39 -07001209 case CMD_PERFORM_NETWORK_SCAN:
1210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1212 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1213 break;
1214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001218 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1219 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1220 request.argument;
1221 int callForwardingReason = args.first;
1222 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 break;
Hall Liu27d24262020-09-18 19:04:59 -07001224 }
1225 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001226 ar = (AsyncResult) msg.obj;
1227 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001228 TelephonyManager.CallForwardingInfoCallback callback =
1229 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1230 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001232 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001233 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1234 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1235 // Service Class is a bit mask per 3gpp 27.007. Search for
1236 // any service for voice call.
1237 if ((callForwardInfo.serviceClass
1238 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001239 callForwardingInfo = new CallForwardingInfo(
1240 callForwardInfo.status
1241 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001242 callForwardInfo.reason,
1243 callForwardInfo.number,
1244 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
1246 }
1247 }
1248 // Didn't find a call forward info for voice call.
1249 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001250 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1251 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 }
Hall Liu27d24262020-09-18 19:04:59 -07001253 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001254 } else {
1255 if (ar.result == null) {
1256 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1257 }
1258 if (ar.exception != null) {
1259 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1260 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 int errorCode = TelephonyManager
1262 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 if (ar.exception instanceof CommandException) {
1264 CommandException.Error error =
1265 ((CommandException) (ar.exception)).getCommandError();
1266 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001267 errorCode = TelephonyManager
1268 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001269 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager
1271 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 }
1273 }
Hall Liu27d24262020-09-18 19:04:59 -07001274 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276 break;
Hall Liu27d24262020-09-18 19:04:59 -07001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278
Hall Liu27d24262020-09-18 19:04:59 -07001279 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001280 request = (MainThreadRequest) msg.obj;
1281 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001282 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001284 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1285 request.argument).first;
1286 request.phone.setCallForwardingOption(
1287 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001288 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001289 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001290 callForwardingInfoToSet.getReason(),
1291 callForwardingInfoToSet.getNumber(),
1292 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001299 Consumer<Integer> callback =
1300 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1301 request.argument).second;
1302 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 int errorCode = TelephonyManager.CallForwardingInfoCallback
1305 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001306 if (ar.exception instanceof CommandException) {
1307 CommandException.Error error =
1308 ((CommandException) (ar.exception)).getCommandError();
1309 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001310 errorCode = TelephonyManager.CallForwardingInfoCallback
1311 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001312 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001313 errorCode = TelephonyManager.CallForwardingInfoCallback
1314 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
1316 }
1317 callback.accept(errorCode);
1318 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001319 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321 break;
Hall Liu27d24262020-09-18 19:04:59 -07001322 }
Shuo Qian4a594052020-01-23 11:59:30 -08001323
Hall Liu27d24262020-09-18 19:04:59 -07001324 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1327 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1328 break;
Hall Liu27d24262020-09-18 19:04:59 -07001329 }
Shuo Qian4a594052020-01-23 11:59:30 -08001330
Hall Liu27d24262020-09-18 19:04:59 -07001331 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001334 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001335 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001337 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001338 // Service Class is a bit mask per 3gpp 27.007.
1339 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001340 if (callForwardResults.length > 1
1341 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001342 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001343 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001344 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1345 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001348 }
1349 } else {
1350 if (ar.result == null) {
1351 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1352 }
1353 if (ar.exception != null) {
1354 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1355 }
1356 if (ar.exception instanceof CommandException) {
1357 CommandException.Error error =
1358 ((CommandException) (ar.exception)).getCommandError();
1359 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001361 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001362 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1363 callWaitingStatus =
1364 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001365 }
1366 }
1367 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001368 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001369 break;
Hall Liu27d24262020-09-18 19:04:59 -07001370 }
Shuo Qian4a594052020-01-23 11:59:30 -08001371
Hall Liu27d24262020-09-18 19:04:59 -07001372 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001375 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1376 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001377 break;
Hall Liu27d24262020-09-18 19:04:59 -07001378 }
Shuo Qian4a594052020-01-23 11:59:30 -08001379
Hall Liu27d24262020-09-18 19:04:59 -07001380 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001383 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1384 Consumer<Integer> callback =
1385 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1386 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001387 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001388 if (ar.exception instanceof CommandException) {
1389 CommandException.Error error =
1390 ((CommandException) (ar.exception)).getCommandError();
1391 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001393 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1394 callback.accept(
1395 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001396 } else {
1397 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1398 }
1399 } else {
1400 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1401 }
1402 } else {
1403 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1404 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001405 }
Shuo Qian4a594052020-01-23 11:59:30 -08001406 break;
Hall Liu27d24262020-09-18 19:04:59 -07001407 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001408 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 CellNetworkScanResult cellScanResult;
1412 if (ar.exception == null && ar.result != null) {
1413 cellScanResult = new CellNetworkScanResult(
1414 CellNetworkScanResult.STATUS_SUCCESS,
1415 (List<OperatorInfo>) ar.result);
1416 } else {
1417 if (ar.result == null) {
1418 loge("getCellNetworkScanResults: Empty response");
1419 }
1420 if (ar.exception != null) {
1421 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1422 }
1423 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1424 if (ar.exception instanceof CommandException) {
1425 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001426 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001427 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1428 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1429 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1430 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1431 }
1432 }
1433 cellScanResult = new CellNetworkScanResult(errorCode, null);
1434 }
1435 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001437 break;
1438
1439 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1440 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001441 ManualNetworkSelectionArgument selArg =
1442 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001443 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1444 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001445 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1446 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001447 break;
1448
1449 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null) {
1453 request.result = true;
1454 } else {
1455 request.result = false;
1456 loge("setNetworkSelectionModeManual " + ar.exception);
1457 }
1458 notifyRequester(request);
1459 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001460 break;
1461
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 case CMD_GET_MODEM_ACTIVITY_INFO:
1463 request = (MainThreadRequest) msg.obj;
1464 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001465 if (defaultPhone != null) {
1466 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 } else {
1468 ResultReceiver result = (ResultReceiver) request.argument;
1469 Bundle bundle = new Bundle();
1470 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001471 new ModemActivityInfo(0, 0, 0,
1472 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001474 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 break;
1476
Hall Liud0f208c2020-10-14 16:54:44 -07001477 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001480 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001481 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001482 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001483 if (mLastModemActivityInfo == null) {
1484 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1485 mLastModemActivitySpecificInfo[0] =
1486 new ActivityStatsTechSpecificInfo(
1487 0,
1488 0,
1489 new int[ModemActivityInfo.getNumTxPowerLevels()],
1490 0);
1491 mLastModemActivityInfo =
1492 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1493 }
1494
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001496 // Update the last modem activity info and the result of the request.
1497 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1498 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001499 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001500 } else {
1501 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001502 }
Kai Shi917fdc62022-11-28 14:01:02 -08001503 // This is needed to decouple ret from mLastModemActivityInfo
1504 // We don't want to return mLastModemActivityInfo which is updated
1505 // inside mergeModemActivityInfo()
1506 ret = new ModemActivityInfo(
1507 mLastModemActivityInfo.getTimestampMillis(),
1508 mLastModemActivityInfo.getSleepTimeMillis(),
1509 mLastModemActivityInfo.getIdleTimeMillis(),
1510 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001511
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512 } else {
1513 if (ar.result == null) {
1514 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001515 error = TelephonyManager.ModemActivityInfoException
1516 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001518 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001519 error = TelephonyManager.ModemActivityInfoException
1520 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001521 } else {
1522 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001523 error = TelephonyManager.ModemActivityInfoException
1524 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001525 }
1526 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001527 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001528 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001529 bundle.putParcelable(
1530 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001531 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001532 } else {
1533 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1534 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001535 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001536 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001537 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001538 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001539
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001540 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001542 CarrierRestrictionRules argument =
1543 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001545 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001547 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001548
1549 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001555 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1556 if (ar.exception instanceof CommandException) {
1557 loge("setAllowedCarriers: CommandException: " + ar.exception);
1558 CommandException.Error error =
1559 ((CommandException) (ar.exception)).getCommandError();
1560 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1561 request.result =
1562 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1563 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001564 } else {
1565 loge("setAllowedCarriers: Unknown exception");
1566 }
1567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001569 break;
1570
1571 case CMD_GET_ALLOWED_CARRIERS:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001574 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001575 break;
1576
1577 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception == null && ar.result != null) {
1581 request.result = ar.result;
1582 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001583 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001584 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001585 if (ar.result == null) {
1586 loge("getAllowedCarriers: Empty response");
1587 } else if (ar.exception instanceof CommandException) {
1588 loge("getAllowedCarriers: CommandException: " +
1589 ar.exception);
1590 } else {
1591 loge("getAllowedCarriers: Unknown exception");
1592 }
1593 }
arunvoddud7401012022-12-15 16:08:12 +00001594 if (request.argument != null) {
1595 // This is for the implementation of carrierRestrictionStatus.
1596 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1597 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001598 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001599 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1600 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1601 CarrierRestrictionRules carrierRestrictionRules =
1602 (CarrierRestrictionRules) ar.result;
1603 int carrierId = -1;
1604 try {
1605 CarrierIdentifier carrierIdentifier =
1606 carrierRestrictionRules.getAllowedCarriers().get(0);
1607 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1608 carrierIdentifier);
1609 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1610 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1611 }
1612 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001613 int restrictedStatus =
1614 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1615 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1616 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001617 lockStatus = TelephonyManager
1618 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001619 }
1620 } else {
1621 Rlog.e(LOG_TAG,
1622 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1623 }
1624 callback.accept(lockStatus);
1625 } else {
1626 // This is for the implementation of getAllowedCarriers.
1627 notifyRequester(request);
1628 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001629 break;
1630
Nathan Haroldb3014052017-01-25 15:57:32 -08001631 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception == null && ar.result != null) {
1635 request.result = ar.result;
1636 } else {
1637 request.result = new IllegalArgumentException(
1638 "Failed to retrieve Forbidden Plmns");
1639 if (ar.result == null) {
1640 loge("getForbiddenPlmns: Empty response");
1641 } else {
1642 loge("getForbiddenPlmns: Unknown exception");
1643 }
1644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001645 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001646 break;
1647
1648 case CMD_GET_FORBIDDEN_PLMNS:
1649 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001650 uiccPort = getUiccPortFromRequest(request);
1651 if (uiccPort == null) {
1652 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001653 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001654 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657 }
1658 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001659 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001660 if (uiccApp == null) {
1661 loge("getForbiddenPlmns() no app with specified type -- "
1662 + appType);
1663 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001664 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001665 break;
1666 } else {
1667 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1668 + " specified type -- " + appType);
1669 }
1670 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1671 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001672 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001673 break;
1674
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001675 case CMD_SWITCH_SLOTS:
1676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001677 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001679 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 break;
1681
1682 case EVENT_SWITCH_SLOTS_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001686 notifyRequester(request);
1687 break;
1688 case CMD_GET_NETWORK_SELECTION_MODE:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1691 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1692 break;
1693
1694 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1695 ar = (AsyncResult) msg.obj;
1696 request = (MainThreadRequest) ar.userObj;
1697 if (ar.exception != null) {
1698 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1699 } else {
1700 int mode = ((int[]) ar.result)[0];
1701 if (mode == 0) {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1703 } else {
1704 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1705 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001706 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001707 notifyRequester(request);
1708 break;
1709 case CMD_GET_CDMA_ROAMING_MODE:
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1712 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1713 break;
1714 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 if (ar.exception != null) {
1718 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1719 } else {
1720 request.result = ((int[]) ar.result)[0];
1721 }
1722 notifyRequester(request);
1723 break;
1724 case CMD_SET_CDMA_ROAMING_MODE:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1727 int mode = (int) request.argument;
1728 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1729 break;
1730 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 request.result = ar.exception == null;
1734 notifyRequester(request);
1735 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001736 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1737 request = (MainThreadRequest) msg.obj;
1738 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1739 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1740 break;
1741 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 if (ar.exception != null) {
1745 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1746 } else {
1747 request.result = ((int[]) ar.result)[0];
1748 }
1749 notifyRequester(request);
1750 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001751 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1752 request = (MainThreadRequest) msg.obj;
1753 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1754 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001755 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1756 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001757 break;
1758 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 request.result = ar.exception == null;
1762 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001763 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 case CMD_GET_ALL_CELL_INFO:
1765 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001767 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 case EVENT_GET_ALL_CELL_INFO_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001772 // If a timeout occurs, the response will be null
1773 request.result = (ar.exception == null && ar.result != null)
1774 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001775 synchronized (request) {
1776 request.notifyAll();
1777 }
1778 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 case CMD_REQUEST_CELL_INFO_UPDATE:
1780 request = (MainThreadRequest) msg.obj;
1781 request.phone.requestCellInfoUpdate(request.workSource,
1782 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1783 break;
1784 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1788 try {
1789 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001790 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001791 cb.onError(
1792 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1793 ar.exception.getClass().getName(),
1794 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001795 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001797 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001798 } else {
1799 // use the result as returned
1800 cb.onCellInfo((List<CellInfo>) ar.result);
1801 }
1802 } catch (RemoteException re) {
1803 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1804 }
1805 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001807 request = (MainThreadRequest) msg.obj;
1808 WorkSource ws = (WorkSource) request.argument;
1809 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001810 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001812 }
1813 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 if (ar.exception == null) {
1817 request.result = ar.result;
1818 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001819 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001821 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001822 }
1823
1824 synchronized (request) {
1825 request.notifyAll();
1826 }
1827 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001828 }
chen xu6dac5ab2018-10-26 17:39:23 -07001829 case CMD_MODEM_REBOOT:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001832 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001833 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001834 case EVENT_CMD_MODEM_REBOOT_DONE:
1835 handleNullReturnEvent(msg, "rebootModem");
1836 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001837 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001838 request = (MainThreadRequest) msg.obj;
1839 boolean enable = (boolean) request.argument;
1840 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001841 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001842 PhoneConfigurationManager.getInstance()
1843 .enablePhone(request.phone, enable, onCompleted);
1844 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001845 }
Michele Berionne5e411512020-11-13 02:36:59 +00001846 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001847 ar = (AsyncResult) msg.obj;
1848 request = (MainThreadRequest) ar.userObj;
1849 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001851 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001852 if ((boolean) request.result) {
1853 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1854 updateModemStateMetrics();
1855 } else {
1856 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1857 + ar.exception);
1858 }
1859 notifyRequester(request);
1860 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001861 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001862 case CMD_GET_MODEM_STATUS:
1863 request = (MainThreadRequest) msg.obj;
1864 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1865 PhoneConfigurationManager.getInstance()
1866 .getPhoneStatusFromModem(request.phone, onCompleted);
1867 break;
1868 case EVENT_GET_MODEM_STATUS_DONE:
1869 ar = (AsyncResult) msg.obj;
1870 request = (MainThreadRequest) ar.userObj;
1871 int id = request.phone.getPhoneId();
1872 if (ar.exception == null && ar.result != null) {
1873 request.result = ar.result;
1874 //update the cache as modem status has changed
1875 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1876 (boolean) request.result);
1877 } else {
1878 // Return true if modem status cannot be retrieved. For most cases,
1879 // modem status is on. And for older version modems, GET_MODEM_STATUS
1880 // and disable modem are not supported. Modem is always on.
1881 // TODO: this should be fixed in R to support a third
1882 // status UNKNOWN b/131631629
1883 request.result = true;
1884 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1885 + ar.exception);
1886 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001887 notifyRequester(request);
1888 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001889 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1892 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1893 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1894 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1895 break;
1896 }
1897 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1898 ar = (AsyncResult) msg.obj;
1899 request = (MainThreadRequest) ar.userObj;
1900 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1901 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1902 args.second.accept(ar.exception == null);
1903 notifyRequester(request);
1904 break;
1905 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001906 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1907 request = (MainThreadRequest) msg.obj;
1908 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1909 Phone phone = getPhoneFromRequest(request);
1910 if (phone != null) {
1911 phone.getSystemSelectionChannels(onCompleted);
1912 } else {
1913 loge("getSystemSelectionChannels: No phone object");
1914 request.result = new ArrayList<RadioAccessSpecifier>();
1915 notifyRequester(request);
1916 }
1917 break;
1918 }
1919 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null && ar.result != null) {
1923 request.result = ar.result;
1924 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001925 request.result = new IllegalStateException(
1926 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001927 if (ar.result == null) {
1928 loge("getSystemSelectionChannels: Empty response");
1929 } else {
1930 loge("getSystemSelectionChannels: Unknown exception");
1931 }
1932 }
1933 notifyRequester(request);
1934 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001935 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1936 ar = (AsyncResult) msg.obj;
1937 request = (MainThreadRequest) ar.userObj;
1938 if (ar.exception == null && ar.result != null) {
1939 request.result = ar.result;
1940 } else {
1941 request.result = -1;
1942 loge("Failed to set Forbidden Plmns");
1943 if (ar.result == null) {
1944 loge("setForbidenPlmns: Empty response");
1945 } else if (ar.exception != null) {
1946 loge("setForbiddenPlmns: Exception: " + ar.exception);
1947 request.result = -1;
1948 } else {
1949 loge("setForbiddenPlmns: Unknown exception");
1950 }
1951 }
1952 notifyRequester(request);
1953 break;
1954 case CMD_SET_FORBIDDEN_PLMNS:
1955 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001956 uiccPort = getUiccPortFromRequest(request);
1957 if (uiccPort == null) {
1958 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001959 request.result = -1;
1960 notifyRequester(request);
1961 break;
1962 }
1963 Pair<Integer, List<String>> setFplmnsArgs =
1964 (Pair<Integer, List<String>>) request.argument;
1965 appType = setFplmnsArgs.first;
1966 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001967 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001968 if (uiccApp == null) {
1969 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1970 request.result = -1;
1971 loge("Failed to get UICC App");
1972 notifyRequester(request);
1973 } else {
1974 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1975 ((SIMRecords) uiccApp.getIccRecords())
1976 .setForbiddenPlmns(onCompleted, fplmns);
1977 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001978 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001979 case CMD_ERASE_MODEM_CONFIG:
1980 request = (MainThreadRequest) msg.obj;
1981 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1982 defaultPhone.eraseModemConfig(onCompleted);
1983 break;
1984 case EVENT_ERASE_MODEM_CONFIG_DONE:
1985 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001986 break;
zoey chene02881a2019-12-30 16:11:23 +08001987
Kai Shif70f46f2021-03-03 13:59:46 -08001988 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1989 request = (MainThreadRequest) msg.obj;
1990 request.result = defaultPhone.eraseDataInSharedPreferences();
1991 notifyRequester(request);
1992 break;
1993
zoey chene02881a2019-12-30 16:11:23 +08001994 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1995 request = (MainThreadRequest) msg.obj;
1996 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1997 Pair<String, String> changed = (Pair<String, String>) request.argument;
1998 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1999 changed.first, changed.second, onCompleted);
2000 break;
2001 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2002 ar = (AsyncResult) msg.obj;
2003 request = (MainThreadRequest) ar.userObj;
2004 if (ar.exception == null) {
2005 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002006 // If the operation is successful, update the PIN storage
2007 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2008 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002009 UiccController.getInstance().getPinStorage()
2010 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002011 } else {
2012 request.result = msg.arg1;
2013 }
2014 notifyRequester(request);
2015 break;
2016
Michele Berionne5e411512020-11-13 02:36:59 +00002017 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002018 request = (MainThreadRequest) msg.obj;
2019 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2020 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2021 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2022 enabled.first, enabled.second, onCompleted);
2023 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002024 }
zoey chene02881a2019-12-30 16:11:23 +08002025 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2026 ar = (AsyncResult) msg.obj;
2027 request = (MainThreadRequest) ar.userObj;
2028 if (ar.exception == null) {
2029 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002030 // If the operation is successful, update the PIN storage
2031 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2032 int phoneId = getPhoneFromRequest(request).getPhoneId();
2033 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002034 UiccController.getInstance().getPinStorage()
2035 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002036 } else {
2037 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2038 }
zoey chene02881a2019-12-30 16:11:23 +08002039 } else {
2040 request.result = msg.arg1;
2041 }
Michele Berionne5e411512020-11-13 02:36:59 +00002042
2043
zoey chene02881a2019-12-30 16:11:23 +08002044 notifyRequester(request);
2045 break;
2046
Peter Wangdafb9ac2020-01-15 14:13:38 -08002047 case MSG_NOTIFY_USER_ACTIVITY:
2048 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002049 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002050 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2051 getDefaultPhone().getContext().sendBroadcastAsUser(
2052 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2053 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002054
2055 case CMD_SET_DATA_THROTTLING: {
2056 request = (MainThreadRequest) msg.obj;
2057 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2058 DataThrottlingRequest dataThrottlingRequest =
2059 (DataThrottlingRequest) request.argument;
2060 Phone phone = getPhoneFromRequest(request);
2061 if (phone != null) {
2062 phone.setDataThrottling(onCompleted,
2063 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2064 dataThrottlingRequest.getCompletionDurationMillis());
2065 } else {
2066 loge("setDataThrottling: No phone object");
2067 request.result =
2068 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2069 notifyRequester(request);
2070 }
2071
2072 break;
2073 }
2074 case EVENT_SET_DATA_THROTTLING_DONE:
2075 ar = (AsyncResult) msg.obj;
2076 request = (MainThreadRequest) ar.userObj;
2077
2078 if (ar.exception == null) {
2079 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2080 } else if (ar.exception instanceof CommandException) {
2081 loge("setDataThrottling: CommandException: " + ar.exception);
2082 CommandException.Error error =
2083 ((CommandException) (ar.exception)).getCommandError();
2084
2085 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2086 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002087 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002088 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2089 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002090 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2091 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002092 } else {
2093 request.result =
2094 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2095 }
2096 } else {
2097 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2098 }
2099 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2100 notifyRequester(request);
2101 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002102
2103 case CMD_SET_SIM_POWER: {
2104 request = (MainThreadRequest) msg.obj;
2105 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2106 request = (MainThreadRequest) msg.obj;
2107 int stateToSet =
2108 ((Pair<Integer, IIntegerConsumer>)
2109 request.argument).first;
2110 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2111 break;
2112 }
2113 case EVENT_SET_SIM_POWER_DONE: {
2114 ar = (AsyncResult) msg.obj;
2115 request = (MainThreadRequest) ar.userObj;
2116 IIntegerConsumer callback =
2117 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2118 if (ar.exception != null) {
2119 loge("setSimPower exception: " + ar.exception);
2120 int errorCode = TelephonyManager.CallForwardingInfoCallback
2121 .RESULT_ERROR_UNKNOWN;
2122 if (ar.exception instanceof CommandException) {
2123 CommandException.Error error =
2124 ((CommandException) (ar.exception)).getCommandError();
2125 if (error == CommandException.Error.SIM_ERR) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2127 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2129 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2131 } else {
2132 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2133 }
2134 }
2135 try {
2136 callback.accept(errorCode);
2137 } catch (RemoteException e) {
2138 // Ignore if the remote process is no longer available to call back.
2139 Log.w(LOG_TAG, "setSimPower: callback not available.");
2140 }
2141 } else {
2142 try {
2143 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2144 } catch (RemoteException e) {
2145 // Ignore if the remote process is no longer available to call back.
2146 Log.w(LOG_TAG, "setSimPower: callback not available.");
2147 }
2148 }
2149 break;
2150 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002151 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2152 request = (MainThreadRequest) msg.obj;
2153
2154 final Phone phone = getPhoneFromRequest(request);
2155 if (phone == null || phone.getServiceStateTracker() == null) {
2156 request.result = new IllegalStateException("Phone or SST is null");
2157 notifyRequester(request);
2158 break;
2159 }
2160
2161 Pair<Integer, SignalStrengthUpdateRequest> pair =
2162 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2163 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2164 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002165 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002166 request.subId, pair.first /*callingUid*/,
2167 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002168 break;
2169 }
2170 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2171 ar = (AsyncResult) msg.obj;
2172 request = (MainThreadRequest) ar.userObj;
2173 // request.result will be the exception of ar if present, true otherwise.
2174 // Be cautious not to leave result null which will wait() forever
2175 request.result = ar.exception != null ? ar.exception : true;
2176 notifyRequester(request);
2177 break;
2178 }
2179 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2180 request = (MainThreadRequest) msg.obj;
2181
2182 Phone phone = getPhoneFromRequest(request);
2183 if (phone == null || phone.getServiceStateTracker() == null) {
2184 request.result = new IllegalStateException("Phone or SST is null");
2185 notifyRequester(request);
2186 break;
2187 }
2188
2189 Pair<Integer, SignalStrengthUpdateRequest> pair =
2190 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2191 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2192 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002193 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002194 request.subId, pair.first /*callingUid*/,
2195 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002196 break;
2197 }
2198 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2199 ar = (AsyncResult) msg.obj;
2200 request = (MainThreadRequest) ar.userObj;
2201 request.result = ar.exception != null ? ar.exception : true;
2202 notifyRequester(request);
2203 break;
2204 }
Jordan Liu109698e2020-11-24 14:50:34 -08002205
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002206 case CMD_GET_SLICING_CONFIG: {
2207 request = (MainThreadRequest) msg.obj;
2208 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2209 request.phone.getSlicingConfig(onCompleted);
2210 break;
2211 }
2212 case EVENT_GET_SLICING_CONFIG_DONE: {
2213 ar = (AsyncResult) msg.obj;
2214 request = (MainThreadRequest) ar.userObj;
2215 ResultReceiver result = (ResultReceiver) request.argument;
2216
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 Bundle bundle = new Bundle();
2219 int resultCode = 0;
2220 if (ar.exception != null) {
2221 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2222 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002223 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002224 } else if (ar.result == null) {
2225 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002226 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002227 } else {
2228 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002229 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2230 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002231 }
2232
2233 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002234 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002235 }
2236 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2237 result.send(resultCode, bundle);
2238 notifyRequester(request);
2239 break;
2240 }
2241
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 request = (MainThreadRequest) msg.obj;
2244 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 PurchasePremiumCapabilityArgument arg =
2246 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002247 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2248 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 ar = (AsyncResult) msg.obj;
2254 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 PurchasePremiumCapabilityArgument arg =
2256 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 try {
2258 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002260 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002261 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002262 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263 + TelephonyManager.convertPurchaseResultToString(result));
2264 } catch (RemoteException e) {
2265 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002266 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002267 + " failed: " + e;
2268 if (DBG) log(logStr);
2269 AnomalyReporter.reportAnomaly(
2270 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2271 }
2272 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002273 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002274
Michele Berionne5e411512020-11-13 02:36:59 +00002275 case CMD_PREPARE_UNATTENDED_REBOOT:
2276 request = (MainThreadRequest) msg.obj;
2277 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002278 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002279 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002280 notifyRequester(request);
2281 break;
2282
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 default:
2284 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2285 break;
2286 }
2287 }
Jake Hambye994d462014-02-03 13:10:13 -08002288
Pengquan Menga1bb6272018-09-06 09:59:22 -07002289 private void notifyRequester(MainThreadRequest request) {
2290 synchronized (request) {
2291 request.notifyAll();
2292 }
2293 }
2294
Jake Hambye994d462014-02-03 13:10:13 -08002295 private void handleNullReturnEvent(Message msg, String command) {
2296 AsyncResult ar = (AsyncResult) msg.obj;
2297 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2298 if (ar.exception == null) {
2299 request.result = true;
2300 } else {
2301 request.result = false;
2302 if (ar.exception instanceof CommandException) {
2303 loge(command + ": CommandException: " + ar.exception);
2304 } else {
2305 loge(command + ": Unknown exception");
2306 }
2307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002308 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
2311
2312 /**
2313 * Posts the specified command to be executed on the main thread,
2314 * waits for the request to complete, and returns the result.
2315 * @see #sendRequestAsync
2316 */
2317 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002318 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2319 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002320 }
2321
2322 /**
2323 * Posts the specified command to be executed on the main thread,
2324 * waits for the request to complete, and returns the result.
2325 * @see #sendRequestAsync
2326 */
2327 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2328 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
2331
2332 /**
2333 * Posts the specified command to be executed on the main thread,
2334 * waits for the request to complete, and returns the result.
2335 * @see #sendRequestAsync
2336 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002337 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002338 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2339 }
2340
2341 /**
2342 * Posts the specified command to be executed on the main thread,
2343 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2344 * if not timeout or null otherwise.
2345 * @see #sendRequestAsync
2346 */
2347 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2348 long timeoutInMs) {
2349 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002350 }
2351
2352 /**
2353 * Posts the specified command to be executed on the main thread,
2354 * waits for the request to complete, and returns the result.
2355 * @see #sendRequestAsync
2356 */
Nathan Harold92bed182018-10-12 18:16:49 -07002357 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002359 }
2360
2361 /**
2362 * Posts the specified command to be executed on the main thread,
2363 * waits for the request to complete, and returns the result.
2364 * @see #sendRequestAsync
2365 */
2366 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002367 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2368 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002369 }
2370
2371 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002372 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2373 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2374 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002375 * @see #sendRequestAsync
2376 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002377 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2378 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2380 throw new RuntimeException("This method will deadlock if called from the main thread.");
2381 }
2382
Nathan Harold92bed182018-10-12 18:16:49 -07002383 MainThreadRequest request = null;
2384 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2385 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2386 } else if (phone != null) {
2387 request = new MainThreadRequest(argument, phone, workSource);
2388 } else {
2389 request = new MainThreadRequest(argument, subId, workSource);
2390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 Message msg = mMainThreadHandler.obtainMessage(command, request);
2393 msg.sendToTarget();
2394
Rambo Wang0f050d82021-02-12 11:43:36 -08002395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002397 if (timeoutInMs >= 0) {
2398 // Wait for at least timeoutInMs before returning null request result
2399 long now = SystemClock.elapsedRealtime();
2400 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002401 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002402 try {
2403 request.wait(deadline - now);
2404 } catch (InterruptedException e) {
2405 // Do nothing, go back and check if request is completed or timeout
2406 } finally {
2407 now = SystemClock.elapsedRealtime();
2408 }
2409 }
2410 } else {
2411 // Wait for the request to complete
2412 while (request.result == null) {
2413 try {
2414 request.wait();
2415 } catch (InterruptedException e) {
2416 // Do nothing, go back and wait until the request is complete
2417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419 }
2420 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002421 if (request.result == null) {
2422 Log.wtf(LOG_TAG,
2423 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 return request.result;
2426 }
2427
2428 /**
2429 * Asynchronous ("fire and forget") version of sendRequest():
2430 * Posts the specified command to be executed on the main thread, and
2431 * returns immediately.
2432 * @see #sendRequest
2433 */
2434 private void sendRequestAsync(int command) {
2435 mMainThreadHandler.sendEmptyMessage(command);
2436 }
2437
2438 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002440 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002441 */
2442 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002443 sendRequestAsync(command, argument, null, null);
2444 }
2445
2446 /**
2447 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2448 * @see {@link #sendRequest(int,Object)}
2449 */
2450 private void sendRequestAsync(
2451 int command, Object argument, Phone phone, WorkSource workSource) {
2452 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002453 Message msg = mMainThreadHandler.obtainMessage(command, request);
2454 msg.sendToTarget();
2455 }
2456
2457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 * Initialize the singleton PhoneInterfaceManager instance.
2459 * This is only done once, at startup, from PhoneApp.onCreate().
2460 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002461 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 synchronized (PhoneInterfaceManager.class) {
2463 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 } else {
2466 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2467 }
2468 return sInstance;
2469 }
2470 }
2471
2472 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002473 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002475 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002476 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002478 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002479 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002480 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2482 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002483 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002484 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002485 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002486 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002487 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002488 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002489 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2490 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002491 mVendorApiLevel = SystemProperties.getInt(
2492 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2493
Tyler Gunn64144d92022-03-17 14:16:41 -07002494 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 publish();
arunvoddud7401012022-12-15 16:08:12 +00002496 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002497
2498 // Create the SatelliteEntitlementController singleton, for using the get the
2499 // entitlementStatus for satellite service.
2500 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002503 @VisibleForTesting
2504 public SharedPreferences getSharedPreferences() {
2505 return mTelephonySharedPreferences;
2506 }
2507
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002508 /**
2509 * Get the default phone for this device.
2510 */
2511 @VisibleForTesting
2512 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002513 Phone thePhone = getPhone(getDefaultSubscription());
2514 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2515 }
2516
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 private void publish() {
2518 if (DBG) log("publish: " + this);
2519
Peter Wangc035ce42020-01-08 21:00:22 -08002520 TelephonyFrameworkInitializer
2521 .getTelephonyServiceManager()
2522 .getTelephonyServiceRegisterer()
2523 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
Stuart Scott584921c2015-01-15 17:10:34 -08002526 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002527 if (request.phone != null) {
2528 return request.phone;
2529 } else {
2530 return getPhoneFromSubId(request.subId);
2531 }
2532 }
2533
2534 private Phone getPhoneFromSubId(int subId) {
2535 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2536 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002537 }
2538
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002539 /**
2540 * Get phone object associated with a subscription.
2541 * Return default phone if phone object associated with subscription is null
2542 * @param subId - subscriptionId
2543 * @return phone object associated with a subscription or default phone if null.
2544 */
Ling Mac28f0212023-03-24 16:07:15 -07002545 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002546 Phone phone = getPhoneFromSubId(subId);
2547 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002548 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002549 phone = getDefaultPhone();
2550 }
2551 return phone;
2552 }
2553
Rambo Wange53e07d2022-05-10 13:01:13 -07002554 @Nullable
2555 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002556 Phone phone = getPhoneFromRequest(request);
2557 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002558 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002559 }
2560
Ling Mac28f0212023-03-24 16:07:15 -07002561 /**
2562 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2563 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2564 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2565 * @return The Phone associated the sub Id
2566 */
2567 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002568 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570
Kai Shif70f46f2021-03-03 13:59:46 -08002571 private void sendEraseModemConfig(@NonNull Phone phone) {
2572 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2573 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2574 }
2575
2576 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2577 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2578 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002579 }
2580
Peter Wang44b186e2020-01-13 23:33:09 -08002581 private boolean isImsAvailableOnDevice() {
2582 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2583 if (pm == null) {
2584 // For some reason package manger is not available.. This will fail internally anyway,
2585 // so do not throw error and allow.
2586 return true;
2587 }
2588 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2589 }
2590
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002592 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2593 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2594
Wink Savilleadd7cc52014-09-08 14:23:09 -07002595 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
Wink Savilleb564aae2014-10-23 10:18:09 -07002598 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 if (DBG) log("dial: " + number);
2600 // No permission check needed here: This is just a wrapper around the
2601 // ACTION_DIAL intent, which is available to any app since it puts up
2602 // the UI before it does anything.
2603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 String url = createTelUrl(number);
2607 if (url == null) {
2608 return;
2609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 // PENDING: should we just silently fail if phone is offhook or ringing?
2612 PhoneConstants.State state = mCM.getState(subId);
2613 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2614 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2615 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002616 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 }
2621 }
2622
2623 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002624 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002625 }
2626
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 if (DBG) log("call: " + number);
2629
2630 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002631 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 // from the context of the phone app.
2633 enforceCallPermission();
2634
Jordan Liu1617b712019-07-10 15:06:26 -07002635 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 != AppOpsManager.MODE_ALLOWED) {
2637 return;
2638 }
2639
joonhunshin4ac60942023-11-15 15:23:39 +00002640 enforceTelephonyFeatureWithException(callingPackage,
2641 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 String url = createTelUrl(number);
2646 if (url == null) {
2647 return;
2648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 boolean isValid = false;
2651 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2652 if (slist != null) {
2653 for (SubscriptionInfo subInfoRecord : slist) {
2654 if (subInfoRecord.getSubscriptionId() == subId) {
2655 isValid = true;
2656 break;
2657 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002658 }
Wink Saville08874612014-08-31 19:19:58 -07002659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 if (!isValid) {
2661 return;
2662 }
Wink Saville08874612014-08-31 19:19:58 -07002663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2665 intent.putExtra(SUBSCRIPTION_KEY, subId);
2666 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002667 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
Wink Savilleb564aae2014-10-23 10:18:09 -07002673 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002674 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002675 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2676 }
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002680 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2681 }
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
joonhunshin4ac60942023-11-15 15:23:39 +00002686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2687 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2688 "supplyPinReportResultForSubscriber");
2689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 final long identity = Binder.clearCallingIdentity();
2691 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002692 Phone phone = getPhone(subId);
2693 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 checkSimPin.start();
2695 return checkSimPin.unlockSim(null, pin);
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
2698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
Wink Savilleb564aae2014-10-23 10:18:09 -07002701 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
joonhunshin4ac60942023-11-15 15:23:39 +00002704 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2705 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002709 Phone phone = getPhone(subId);
2710 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711 checkSimPuk.start();
2712 return checkSimPuk.unlockSim(puk, pin);
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
2718 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002719 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 * a synchronous one.
2721 */
2722 private static class UnlockSim extends Thread {
2723
2724 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002725 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726
2727 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002728 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2729 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730
2731 // For replies from SimCard interface
2732 private Handler mHandler;
2733
2734 // For async handler to identify request type
2735 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002736 private static final int SUPPLY_PIN_DELAYED = 101;
2737 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2738 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2739 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740
Michele Berionne5e411512020-11-13 02:36:59 +00002741 UnlockSim(int phoneId, IccCard simCard) {
2742 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 mSimCard = simCard;
2744 }
2745
2746 @Override
2747 public void run() {
2748 Looper.prepare();
2749 synchronized (UnlockSim.this) {
2750 mHandler = new Handler() {
2751 @Override
2752 public void handleMessage(Message msg) {
2753 AsyncResult ar = (AsyncResult) msg.obj;
2754 switch (msg.what) {
2755 case SUPPLY_PIN_COMPLETE:
2756 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2757 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002758 mRetryCount = msg.arg1;
2759 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002760 CommandException.Error error = null;
2761 if (ar.exception instanceof CommandException) {
2762 error = ((CommandException) (ar.exception))
2763 .getCommandError();
2764 }
2765 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002766 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002767 } else if (error == CommandException.Error.ABORTED) {
2768 /* When UiccCardApp dispose, handle message and return
2769 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002770 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002771 } else {
2772 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2773 }
2774 } else {
2775 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002778 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 UnlockSim.this.notifyAll();
2780 }
2781 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002782 case SUPPLY_PIN_DELAYED:
2783 if(!mDone) {
2784 String logStr = "Delay in receiving SIM PIN response ";
2785 if (DBG) log(logStr);
2786 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2787 }
2788 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790 }
2791 };
2792 UnlockSim.this.notifyAll();
2793 }
2794 Looper.loop();
2795 }
2796
2797 /*
2798 * Use PIN or PUK to unlock SIM card
2799 *
2800 * If PUK is null, unlock SIM card with PIN
2801 *
2802 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302803 *
2804 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2805 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 */
Wink Saville9de0f752013-10-22 19:04:03 -07002807 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808
2809 while (mHandler == null) {
2810 try {
2811 wait();
2812 } catch (InterruptedException e) {
2813 Thread.currentThread().interrupt();
2814 }
2815 }
2816 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2817
2818 if (puk == null) {
2819 mSimCard.supplyPin(pin, callback);
2820 } else {
2821 mSimCard.supplyPuk(puk, pin, callback);
2822 }
2823
2824 while (!mDone) {
2825 try {
2826 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002827 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2828 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 wait();
2830 } catch (InterruptedException e) {
2831 // Restore the interrupted status
2832 Thread.currentThread().interrupt();
2833 }
2834 }
2835 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002836 int[] resultArray = new int[2];
2837 resultArray[0] = mResult;
2838 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002839
2840 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002841 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002842 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302843 // This instance is no longer reused, so quit its thread's looper.
2844 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002845
Wink Saville9de0f752013-10-22 19:04:03 -07002846 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848 }
2849
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002850 /**
2851 * This method has been removed due to privacy and stability concerns.
2852 */
2853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002855 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2856 return;
Wink Saville36469e72014-06-11 15:17:00 -07002857 }
2858
Nathan Harold1f889d82020-06-04 17:05:26 -07002859 @Override
2860 public void updateServiceLocationWithPackageName(String callingPackage) {
2861 mApp.getSystemService(AppOpsManager.class)
2862 .checkPackage(Binder.getCallingUid(), callingPackage);
2863
Nathan Haroldf096d982020-11-18 17:18:06 -08002864 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002865 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2866 // Callers targeting S have no business invoking this method.
2867 return;
2868 }
2869
2870 LocationAccessPolicy.LocationPermissionResult locationResult =
2871 LocationAccessPolicy.checkLocationPermission(mApp,
2872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2873 .setCallingPackage(callingPackage)
2874 .setCallingFeatureId(null)
2875 .setCallingPid(Binder.getCallingPid())
2876 .setCallingUid(Binder.getCallingUid())
2877 .setMethod("updateServiceLocation")
2878 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2879 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2880 .build());
2881 // Apps that lack location permission have no business calling this method;
2882 // however, because no permission was declared in the public API, denials must
2883 // all be "soft".
2884 switch (locationResult) {
2885 case DENIED_HARD: /* fall through */
2886 case DENIED_SOFT:
2887 return;
2888 }
2889
2890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
Ling Mac28f0212023-03-24 16:07:15 -07002893 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002899 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002900 @Override
2901 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002902 return isRadioOnWithFeature(callingPackage, null);
2903 }
2904
2905
2906 @Override
2907 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2908 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2909 callingFeatureId);
2910 }
2911
2912 @Deprecated
2913 @Override
2914 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2915 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002919 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002922 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002923 return false;
2924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925
joonhunshin4ac60942023-11-15 15:23:39 +00002926 enforceTelephonyFeatureWithException(callingPackage,
2927 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 return isRadioOnForSubscriber(subId);
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002935 }
2936
2937 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
2941 if (phone != null) {
2942 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2943 } else {
2944 return false;
2945 }
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
2951 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002952 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
Wink Saville36469e72014-06-11 15:17:00 -07002954
Wink Savilleb564aae2014-10-23 10:18:09 -07002955 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
joonhunshin4ac60942023-11-15 15:23:39 +00002958 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2959 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = getPhone(subId);
2964 if (phone != null) {
2965 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2966 }
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 }
Wink Saville36469e72014-06-11 15:17:00 -07002970 }
2971
2972 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002973 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002974 }
2975
Wink Savilleb564aae2014-10-23 10:18:09 -07002976 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002977 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 final Phone phone = getPhone(subId);
2982 if (phone == null) {
2983 return false;
2984 }
2985 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2986 toggleRadioOnOffForSubscriber(subId);
2987 }
2988 return true;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
Wink Saville36469e72014-06-11 15:17:00 -07002993
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002994 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002995 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002996
Tomasz Wasilczykef763582024-09-17 13:50:32 -07002997 if (!mApp.getResources().getBoolean(
2998 com.android.internal.R.bool.config_force_phone_globals_creation)) {
2999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3000 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3001 }
joonhunshin4ac60942023-11-15 15:23:39 +00003002
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003003 /*
3004 * If any of the Radios are available, it will need to be
3005 * shutdown. So return true if any Radio is available.
3006 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3010 Phone phone = PhoneFactory.getPhone(i);
3011 if (phone != null && phone.isRadioAvailable()) return true;
3012 }
3013 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3014 return false;
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003017 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003018 }
3019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003021 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 enforceModifyPermission();
3023
joonhunshin4ac60942023-11-15 15:23:39 +00003024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3025 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3030 logv("Shutting down Phone " + i);
3031 shutdownRadioUsingPhoneId(i);
3032 }
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003035 }
3036 }
3037
3038 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003039 Phone phone = PhoneFactory.getPhone(phoneId);
3040 if (phone != null && phone.isRadioAvailable()) {
3041 phone.shutdownRadio();
3042 }
3043 }
3044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003046 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
Ling Ma83dc5ea2023-01-12 15:06:04 -08003048 if (!turnOn) {
3049 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3050 }
3051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3055 if (defaultPhone != null) {
3056 defaultPhone.setRadioPower(turnOn);
3057 return true;
3058 } else {
3059 loge("There's no default phone.");
3060 return false;
3061 }
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003064 }
Wink Saville36469e72014-06-11 15:17:00 -07003065 }
3066
Wink Savilleb564aae2014-10-23 10:18:09 -07003067 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069
Ling Ma83dc5ea2023-01-12 15:06:04 -08003070 if (!turnOn) {
3071 log("setRadioPowerForSubscriber off: subId=" + subId
3072 + ",callingPackage=" + getCurrentPackageName());
3073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 final Phone phone = getPhone(subId);
3077 if (phone != null) {
3078 phone.setRadioPower(turnOn);
3079 return true;
3080 } else {
3081 return false;
3082 }
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 }
3087
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003088 /**
3089 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3090 * no reason to power it off. When any of the voters want to power it off, it will be turned
3091 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3092 * powering it off, and these radio off votes will be cleared.
3093 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3094 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3095 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3096 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3097 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3098 * check its vote.
3099 *
3100 * @param subId The subscription ID.
3101 * @param reason The reason for powering off radio.
3102 * @return true on success and false on failure.
3103 */
3104 public boolean requestRadioPowerOffForReason(int subId,
3105 @TelephonyManager.RadioPowerReason int reason) {
3106 enforceModifyPermission();
3107
joonhunshin4ac60942023-11-15 15:23:39 +00003108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3109 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3110
Ling Ma83dc5ea2023-01-12 15:06:04 -08003111 log("requestRadioPowerOffForReason: subId=" + subId
3112 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003113 final long identity = Binder.clearCallingIdentity();
3114 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003115 boolean result = false;
3116 for (Phone phone : PhoneFactory.getPhones()) {
3117 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003118 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003120 if (!result) {
3121 loge("requestRadioPowerOffForReason: no phone exists");
3122 }
3123 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
3127 }
3128
3129 /**
3130 * Remove the vote on powering off the radio for a reason, as requested by
3131 * {@link requestRadioPowerOffForReason}.
3132 *
3133 * @param subId The subscription ID.
3134 * @param reason The reason for powering off radio.
3135 * @return true on success and false on failure.
3136 */
3137 public boolean clearRadioPowerOffForReason(int subId,
3138 @TelephonyManager.RadioPowerReason int reason) {
3139 enforceModifyPermission();
3140
joonhunshin4ac60942023-11-15 15:23:39 +00003141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3142 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3143
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003144 final long identity = Binder.clearCallingIdentity();
3145 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003146 boolean result = false;
3147 for (Phone phone : PhoneFactory.getPhones()) {
3148 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003149 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003150 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003151 if (!result) {
3152 loge("clearRadioPowerOffForReason: no phone exists");
3153 }
3154 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
3158 }
3159
3160 /**
3161 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3162 *
3163 * @param subId The subscription ID.
3164 * @param callingPackage The package making the call.
3165 * @param callingFeatureId The feature in the package.
3166 * @return List of reasons for powering off radio.
3167 */
3168 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3169 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3170
joonhunshin4ac60942023-11-15 15:23:39 +00003171 enforceTelephonyFeatureWithException(callingPackage,
3172 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3173
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003174 final long identity = Binder.clearCallingIdentity();
3175 List result = new ArrayList();
3176 try {
3177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3178 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3179 return result;
3180 }
3181
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003182 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003183 if (phone != null) {
3184 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003185 } else {
3186 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003187 }
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 return result;
3192 }
3193
Wink Saville36469e72014-06-11 15:17:00 -07003194 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003196 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
joonhunshin4ac60942023-11-15 15:23:39 +00003199 enforceTelephonyFeatureWithException(callingPackage,
3200 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 final long identity = Binder.clearCallingIdentity();
3203 try {
Jack Yu285100e2022-12-02 22:48:35 -08003204 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003206 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003207 phone.getDataSettingsManager().setDataEnabled(
3208 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 return true;
3210 } else {
3211 return false;
3212 }
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217
Wink Saville36469e72014-06-11 15:17:00 -07003218 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003220 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222
joonhunshin4ac60942023-11-15 15:23:39 +00003223 enforceTelephonyFeatureWithException(callingPackage,
3224 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
Jack Yu285100e2022-12-02 22:48:35 -08003228 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003230 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003231 phone.getDataSettingsManager().setDataEnabled(
3232 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 return true;
3234 } else {
3235 return false;
3236 }
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 }
3241
Sanket Padawe356d7632015-06-22 14:03:32 -07003242 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003243 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003244 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3245 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 final Phone phone = getPhone(subId);
3250 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003251 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 } else {
3253 return false;
3254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 }
3259
3260 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003261 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003262 }
3263
pkanwarae03a6b2016-11-06 20:37:09 -08003264 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 enforceCallPermission();
3266
joonhunshin4ac60942023-11-15 15:23:39 +00003267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3268 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3273 return;
3274 }
3275 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3276 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
pkanwar32d516d2016-10-14 19:37:38 -07003280 };
3281
Wink Savilleb564aae2014-10-23 10:18:09 -07003282 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
joonhunshin4ac60942023-11-15 15:23:39 +00003285 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3286 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3291 return false;
3292 }
3293 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3294 } finally {
3295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 }
3298
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003299 /**
3300 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3301 * tag on getCallState Binder call.
3302 */
3303 @Deprecated
3304 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003305 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003306 if (CompatChanges.isChangeEnabled(
3307 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3308 Binder.getCallingUid())) {
3309 // Do not allow this API to be called on API version 31+, it should only be
3310 // called on old apps using this Binder call directly.
3311 throw new SecurityException("This method can only be used for applications "
3312 + "targeting API version 30 or less.");
3313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
Ling Mac28f0212023-03-24 16:07:15 -07003316 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3317 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
3324 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3325 if (CompatChanges.isChangeEnabled(
3326 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3327 Binder.getCallingUid())) {
3328 // Check READ_PHONE_STATE for API version 31+
3329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3330 featureId, "getCallStateForSubscription")) {
3331 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3332 + "targeting API level 31+.");
3333 }
3334 }
joonhunshin4ac60942023-11-15 15:23:39 +00003335
3336 enforceTelephonyFeatureWithException(callingPackage,
3337 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3338
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3343 PhoneConstantConversions.convertCallState(phone.getState());
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 }
3348
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003350 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003351 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003352 }
3353
3354 @Override
3355 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003356 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3357 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 final long identity = Binder.clearCallingIdentity();
3360 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003361 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003363 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 } else {
3365 return PhoneConstantConversions.convertDataState(
3366 PhoneConstants.DataState.DISCONNECTED);
3367 }
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003371 }
3372
Sanket Padawe356d7632015-06-22 14:03:32 -07003373 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003374 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003375 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003376 }
3377
3378 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003379 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3381 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 final long identity = Binder.clearCallingIdentity();
3384 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003385 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003387 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388 } else {
3389 return TelephonyManager.DATA_ACTIVITY_NONE;
3390 }
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 }
3395
3396 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003397 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003398 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003399 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003400
3401 LocationAccessPolicy.LocationPermissionResult locationResult =
3402 LocationAccessPolicy.checkLocationPermission(mApp,
3403 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3404 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003405 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003406 .setCallingPid(Binder.getCallingPid())
3407 .setCallingUid(Binder.getCallingUid())
3408 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003409 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003410 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3411 .build());
3412 switch (locationResult) {
3413 case DENIED_HARD:
3414 throw new SecurityException("Not allowed to access cell location");
3415 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003416 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3417 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003418 }
3419
joonhunshin4ac60942023-11-15 15:23:39 +00003420 enforceTelephonyFeatureWithException(callingPackage,
3421 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3422
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003423 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003427 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003428 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
Svetoslav64fad262015-04-14 14:35:21 -07003432 }
3433
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003435 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003436 if (!mApp.getResources().getBoolean(
3437 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3438 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3439 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3440 }
joonhunshin4ac60942023-11-15 15:23:39 +00003441
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003442 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3443 // registered cell info, so return a NULL country instead.
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003446 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3447 // Get default phone in this case.
3448 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3449 }
Jack Yu285100e2022-12-02 22:48:35 -08003450 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003452 if (phone == null) return "";
3453 ServiceStateTracker sst = phone.getServiceStateTracker();
3454 if (sst == null) return "";
3455 LocaleTracker lt = sst.getLocaleTracker();
3456 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003457 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003461 }
3462
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003463 /**
3464 * This method was removed due to potential issues caused by performing partial
3465 * updates of service state, and lack of a credible use case.
3466 *
3467 * This has the ability to break the telephony implementation by disabling notification of
3468 * changes in device connectivity. DO NOT USE THIS!
3469 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003470 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 public void enableLocationUpdates() {
3472 mApp.enforceCallingOrSelfPermission(
3473 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 }
3475
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003476 /**
3477 * This method was removed due to potential issues caused by performing partial
3478 * updates of service state, and lack of a credible use case.
3479 *
3480 * This has the ability to break the telephony implementation by disabling notification of
3481 * changes in device connectivity. DO NOT USE THIS!
3482 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 @Override
3484 public void disableLocationUpdates() {
3485 mApp.enforceCallingOrSelfPermission(
3486 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 }
3488
3489 @Override
3490 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003491 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3492 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003493 try {
3494 mApp.getSystemService(AppOpsManager.class)
3495 .checkPackage(Binder.getCallingUid(), callingPackage);
3496 } catch (SecurityException e) {
3497 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3498 throw e;
3499 }
3500
Nathan Haroldf096d982020-11-18 17:18:06 -08003501 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003502 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3503 throw new SecurityException(
3504 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3505 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003506
Jordan Liu1617b712019-07-10 15:06:26 -07003507 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3509 return null;
3510 }
Svetoslav64fad262015-04-14 14:35:21 -07003511
joonhunshin4ac60942023-11-15 15:23:39 +00003512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3513 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3514
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003515 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003517 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003518 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519
Nathan Haroldf180aac2018-06-01 18:43:55 -07003520 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3521 for (CellInfo ci : info) {
3522 if (ci instanceof CellInfoGsm) {
3523 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3524 } else if (ci instanceof CellInfoWcdma) {
3525 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003528 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 }
3530
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003531 private List<CellInfo> getCachedCellInfo() {
3532 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3533 for (Phone phone : PhoneFactory.getPhones()) {
3534 List<CellInfo> info = phone.getAllCellInfo();
3535 if (info != null) cellInfos.addAll(info);
3536 }
3537 return cellInfos;
3538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539
3540 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003541 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003542 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003543 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003544
3545 LocationAccessPolicy.LocationPermissionResult locationResult =
3546 LocationAccessPolicy.checkLocationPermission(mApp,
3547 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3548 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003549 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003550 .setCallingPid(Binder.getCallingPid())
3551 .setCallingUid(Binder.getCallingUid())
3552 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003553 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003554 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3555 .build());
3556 switch (locationResult) {
3557 case DENIED_HARD:
3558 throw new SecurityException("Not allowed to access cell info");
3559 case DENIED_SOFT:
3560 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003561 }
3562
Nathan Haroldf096d982020-11-18 17:18:06 -08003563 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003564 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3565 return getCachedCellInfo();
3566 }
3567
joonhunshin4ac60942023-11-15 15:23:39 +00003568 enforceTelephonyFeatureWithException(callingPackage,
3569 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3570
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003571 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003572 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3576 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003577 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003578 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 if (info != null) cellInfos.addAll(info);
3580 }
3581 return cellInfos;
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003584 }
3585 }
3586
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003587 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003588 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3589 String callingFeatureId) {
3590 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3591 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003592 }
3593
3594 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003595 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3596 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003597 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003598 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003599 }
3600
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003601 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3602 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003604 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003605
3606 LocationAccessPolicy.LocationPermissionResult locationResult =
3607 LocationAccessPolicy.checkLocationPermission(mApp,
3608 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3609 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003610 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003611 .setCallingPid(Binder.getCallingPid())
3612 .setCallingUid(Binder.getCallingUid())
3613 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003614 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3615 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003616 .build());
3617 switch (locationResult) {
3618 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003619 if (TelephonyPermissions
3620 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003621 // Safetynet logging for b/154934934
3622 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3623 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003624 throw new SecurityException("Not allowed to access cell info");
3625 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003626 if (TelephonyPermissions
3627 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003628 // Safetynet logging for b/154934934
3629 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3630 }
Nathan Harold5320c422019-05-09 10:26:08 -07003631 try {
3632 cb.onCellInfo(new ArrayList<CellInfo>());
3633 } catch (RemoteException re) {
3634 // Drop without consequences
3635 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003636 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003637 }
3638
joonhunshin4ac60942023-11-15 15:23:39 +00003639 enforceTelephonyFeatureWithException(callingPackage,
3640 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003641
3642 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003643 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3644
3645 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3646 }
3647
3648 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003649 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003650 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003651 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652
3653 final long identity = Binder.clearCallingIdentity();
3654 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003655 Phone phone = getPhone(subId);
3656 if (phone == null) {
3657 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3658 } else {
3659 phone.setCellInfoListRate(rateInMillis, workSource);
3660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003664 }
3665
Shishir Agrawala9f32182016-04-12 12:00:16 -07003666 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003667 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003668 Phone phone = PhoneFactory.getPhone(slotIndex);
3669 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 return null;
3671 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003672 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003673 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003674 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003675 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003676 return null;
3677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678
joonhunshin4ac60942023-11-15 15:23:39 +00003679 enforceTelephonyFeatureWithException(callingPackage,
3680 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682 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
3698 enforceTelephonyFeatureWithException(callingPackage,
3699 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3700
arunvoddud5c6ce02022-12-11 06:03:12 +00003701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 for (Phone phone : PhoneFactory.getPhones()) {
3704 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3705 return phone.getImei();
3706 }
3707 }
3708 throw new UnsupportedOperationException("Operation not supported");
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
3712 }
3713
3714 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003715 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003716 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3717 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3718
David Kelly5e06a7f2018-03-12 14:10:59 +00003719 Phone phone = PhoneFactory.getPhone(slotIndex);
3720 String tac = null;
3721 if (phone != null) {
3722 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003723 try {
3724 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3725 } catch (IndexOutOfBoundsException e) {
3726 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3727 return null;
3728 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003729 }
3730 return tac;
3731 }
3732
3733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003734 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003735 try {
3736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3737 } catch (SecurityException se) {
3738 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3739 throw new SecurityException("Package " + callingPackage + " does not belong to "
3740 + Binder.getCallingUid());
3741 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 Phone phone = PhoneFactory.getPhone(slotIndex);
3743 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003744 return null;
3745 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746
Jeff Davidson913390f2018-02-23 17:11:49 -08003747 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003748 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003749 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003750 return null;
3751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752
joonhunshin4ac60942023-11-15 15:23:39 +00003753 enforceTelephonyFeatureWithException(callingPackage,
3754 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 return phone.getMeid();
3759 } finally {
3760 Binder.restoreCallingIdentity(identity);
3761 }
Jack Yu2af8d712017-03-15 17:14:14 -07003762 }
3763
3764 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003765 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003766 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3767 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3768
David Kelly5e06a7f2018-03-12 14:10:59 +00003769 Phone phone = PhoneFactory.getPhone(slotIndex);
3770 String manufacturerCode = null;
3771 if (phone != null) {
3772 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003773 try {
3774 manufacturerCode =
3775 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3776 } catch (IndexOutOfBoundsException e) {
3777 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3778 return null;
3779 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003780 }
3781 return manufacturerCode;
3782 }
3783
3784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003785 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3786 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 Phone phone = PhoneFactory.getPhone(slotIndex);
3788 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 return null;
3790 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003791 int subId = phone.getSubId();
3792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003793 mApp, subId, callingPackage, callingFeatureId,
3794 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003795 return null;
3796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
joonhunshin4ac60942023-11-15 15:23:39 +00003798 enforceTelephonyFeatureWithException(callingPackage,
3799 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 return phone.getDeviceSvn();
3804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003807 }
3808
fionaxu43304da2017-11-27 22:51:16 -08003809 @Override
3810 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003811 if (!mApp.getResources().getBoolean(
3812 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3813 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3814 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3815 }
joonhunshin4ac60942023-11-15 15:23:39 +00003816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 final Phone phone = getPhone(subId);
3820 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
3823 }
fionaxu43304da2017-11-27 22:51:16 -08003824 }
3825
3826 @Override
3827 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3829 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = getPhone(subId);
3834 return phone == null ? null : phone.getCarrierName();
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
3837 }
fionaxu43304da2017-11-27 22:51:16 -08003838 }
3839
calvinpanffe225e2018-11-01 19:43:06 +08003840 @Override
chen xu0026ca62019-03-06 15:28:50 -08003841 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003842 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3843 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3844
chen xu25637222018-11-04 17:17:00 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 final Phone phone = getPhone(subId);
3848 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003849 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
3853 }
3854
3855 @Override
chen xu0026ca62019-03-06 15:28:50 -08003856 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003857 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3858 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3859 "getSubscriptionSpecificCarrierName");
3860
chen xu25637222018-11-04 17:17:00 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003864 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003865 } finally {
3866 Binder.restoreCallingIdentity(identity);
3867 }
3868 }
3869
chen xu651eec72018-11-11 19:03:44 -08003870 @Override
chen xu864e11c2018-12-06 22:10:03 -08003871 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3872 if (!isSubscriptionMccMnc) {
3873 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3874 }
chen xu651eec72018-11-11 19:03:44 -08003875 final Phone phone = PhoneFactory.getPhone(slotIndex);
3876 if (phone == null) {
3877 return TelephonyManager.UNKNOWN_CARRIER_ID;
3878 }
joonhunshin4ac60942023-11-15 15:23:39 +00003879
3880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3881 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3882
chen xu651eec72018-11-11 19:03:44 -08003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
3889 }
3890
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 //
3892 // Internal helper methods.
3893 //
3894
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003895 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003896 * Make sure the caller is the calling package itself
3897 *
3898 * @throws SecurityException if the caller is not the calling package
3899 */
3900 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3901 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003902 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3903 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003904 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003905 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003906 } catch (PackageManager.NameNotFoundException e) {
3907 // packageUid is -1
3908 }
3909 if (packageUid != callingUid) {
3910 throw new SecurityException(message + ": Package " + callingPackage
3911 + " does not belong to " + callingUid);
3912 }
3913 }
3914
3915 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003916 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3917 *
3918 * @throws SecurityException if the caller does not have the required permission
3919 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003920 @VisibleForTesting
3921 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003922 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3923 }
3924
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003925 /**
arunvoddud7401012022-12-15 16:08:12 +00003926 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003927 *
3928 * @throws SecurityException if the caller does not have the required permission
3929 */
3930 @VisibleForTesting
3931 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003932 enforceReadPermission(null);
3933 }
3934
3935 /**
3936 * Make sure the caller has the READ_PHONE_STATE permissions.
3937 *
3938 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3939 */
3940 @VisibleForTesting
3941 public void enforceReadPermission(String msg) {
3942 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003943 }
3944
Shuo Qian3b6ee772019-11-13 17:43:31 -08003945 private void enforceActiveEmergencySessionPermission() {
3946 mApp.enforceCallingOrSelfPermission(
3947 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3948 }
3949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003950 /**
3951 * Make sure the caller has the CALL_PHONE permission.
3952 *
3953 * @throws SecurityException if the caller does not have the required permission
3954 */
3955 private void enforceCallPermission() {
3956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3957 }
3958
paulhu5a773602019-08-23 19:17:33 +08003959 private void enforceSettingsPermission() {
3960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003961 }
3962
Michele Berionne5e411512020-11-13 02:36:59 +00003963 private void enforceRebootPermission() {
3964 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3965 }
3966
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003967 /**
3968 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3969 * @param message - log message to print.
3970 * @throws SecurityException if the caller does not have the required permission
3971 */
3972 private void enforceSatelliteCommunicationPermission(String message) {
3973 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3974 }
3975
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003976 /**
3977 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3978 * @param message - log message to print.
3979 * @throws SecurityException if the caller does not have the required permission
3980 */
3981 private void enforcePackageUsageStatsPermission(String message) {
3982 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3983 }
3984
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003985 private String createTelUrl(String number) {
3986 if (TextUtils.isEmpty(number)) {
3987 return null;
3988 }
3989
Jake Hambye994d462014-02-03 13:10:13 -08003990 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003991 }
3992
Ihab Awadf9e92732013-12-05 18:02:52 -08003993 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003994 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003995 }
3996
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003997 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003998 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003999 }
4000
Ihab Awadf9e92732013-12-05 18:02:52 -08004001 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004002 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004003 }
4004
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004005 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004006 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004007 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004008 }
4009
Sanket Padawe356d7632015-06-22 14:03:32 -07004010 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004011 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004012 if (!mApp.getResources().getBoolean(
4013 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4015 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4016 }
joonhunshin4ac60942023-11-15 15:23:39 +00004017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 final Phone phone = PhoneFactory.getPhone(slotIndex);
4021 if (phone == null) {
4022 return PhoneConstants.PHONE_TYPE_NONE;
4023 } else {
4024 return phone.getPhoneType();
4025 }
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004029 }
4030
4031 /**
4032 * Returns the CDMA ERI icon index to display
4033 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004035 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4036 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4037 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004038 }
4039
Sanket Padawe356d7632015-06-22 14:03:32 -07004040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004041 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4042 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004044 mApp, subId, callingPackage, callingFeatureId,
4045 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004046 return -1;
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
joonhunshin4ac60942023-11-15 15:23:39 +00004049 enforceTelephonyFeatureWithException(callingPackage,
4050 PackageManager.FEATURE_TELEPHONY_CDMA,
4051 "getCdmaEriIconIndexForSubscriber");
4052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 final Phone phone = getPhone(subId);
4056 if (phone != null) {
4057 return phone.getCdmaEriIconIndex();
4058 } else {
4059 return -1;
4060 }
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004064 }
4065
4066 /**
4067 * Returns the CDMA ERI icon mode,
4068 * 0 - ON
4069 * 1 - FLASHING
4070 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004072 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4073 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4074 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004075 }
4076
Sanket Padawe356d7632015-06-22 14:03:32 -07004077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4079 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004081 mApp, subId, callingPackage, callingFeatureId,
4082 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004083 return -1;
4084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 final Phone phone = getPhone(subId);
4089 if (phone != null) {
4090 return phone.getCdmaEriIconMode();
4091 } else {
4092 return -1;
4093 }
4094 } finally {
4095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004097 }
4098
4099 /**
4100 * Returns the CDMA ERI text,
4101 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004103 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4104 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4105 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004106 }
4107
Sanket Padawe356d7632015-06-22 14:03:32 -07004108 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004109 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4110 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004112 mApp, subId, callingPackage, callingFeatureId,
4113 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004114 return null;
4115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 final Phone phone = getPhone(subId);
4120 if (phone != null) {
4121 return phone.getCdmaEriText();
4122 } else {
4123 return null;
4124 }
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004128 }
4129
4130 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004131 * Returns the CDMA MDN.
4132 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004133 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004134 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137
joonhunshin4ac60942023-11-15 15:23:39 +00004138 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4139 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004144 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 return phone.getLine1Number();
4146 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004147 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 return null;
4149 }
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004152 }
4153 }
4154
4155 /**
4156 * Returns the CDMA MIN.
4157 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004158 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004159 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4161 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162
joonhunshin4ac60942023-11-15 15:23:39 +00004163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4164 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 final Phone phone = getPhone(subId);
4169 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4170 return phone.getCdmaMin();
4171 } else {
4172 return null;
4173 }
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004176 }
4177 }
4178
Hall Liud892bec2018-11-30 14:51:45 -08004179 @Override
4180 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4181 INumberVerificationCallback callback, String callingPackage) {
4182 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4183 != PERMISSION_GRANTED) {
4184 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4185 }
4186 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4187
4188 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4189 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004190 throw new SecurityException("Calling package must be configured in the device config: "
4191 + "calling package: " + callingPackage
4192 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004193 }
4194
joonhunshin4ac60942023-11-15 15:23:39 +00004195 enforceTelephonyFeatureWithException(callingPackage,
4196 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4197
Hall Liud892bec2018-11-30 14:51:45 -08004198 if (range == null) {
4199 throw new NullPointerException("Range must be non-null");
4200 }
4201
4202 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004203 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004204
4205 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4206 }
4207
Junda Liuca05d5d2014-08-14 22:36:34 -07004208 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004209 * Returns true if CDMA provisioning needs to run.
4210 */
4211 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4213 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004221 }
4222
4223 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004224 * Sets the voice mail number of a given subId.
4225 */
4226 @Override
4227 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004228 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4229 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230
joonhunshin4ac60942023-11-15 15:23:39 +00004231 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4232 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4237 new Pair<String, String>(alphaTag, number), new Integer(subId));
4238 return success;
4239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004242 }
4243
Ta-wei Yen87c49842016-05-13 21:19:52 -07004244 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004245 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4246 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004247 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4248 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004249 if (!TextUtils.equals(callingPackage, systemDialer)) {
4250 throw new SecurityException("caller must be system dialer");
4251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252
joonhunshin4ac60942023-11-15 15:23:39 +00004253 enforceTelephonyFeatureWithException(callingPackage,
4254 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4259 if (phoneAccountHandle == null) {
4260 return null;
4261 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004262 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004265 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004266 }
4267
4268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4270 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004273 mApp, subId, callingPackage, callingFeatureId,
4274 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004275 return null;
4276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277
joonhunshin4ac60942023-11-15 15:23:39 +00004278 enforceTelephonyFeatureWithException(callingPackage,
4279 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4280
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004281 final long identity = Binder.clearCallingIdentity();
4282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004287 }
4288
4289 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004290 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4291 VisualVoicemailSmsFilterSettings settings) {
4292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004293 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004294 enforceTelephonyFeatureWithException(callingPackage,
4295 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004299 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004303 }
4304
4305 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004306 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004308 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004309 enforceTelephonyFeatureWithException(callingPackage,
4310 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004315 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004319 }
4320
4321 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004322 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4323 String callingPackage, int subId) {
4324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004329 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004333 }
4334
4335 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004336 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338
4339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004342 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004346 }
4347
4348 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004349 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4350 String callingAttributionTag, int subId, String number, int port, String text,
4351 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004352 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004353 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004354 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004355
4356 enforceTelephonyFeatureWithException(callingPackage,
4357 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4358
Amit Mahajandccb3f12019-05-13 13:48:32 -07004359 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004360 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4361 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4362 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004363 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004364
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004365 /**
fionaxu0152e512016-11-14 13:36:14 -08004366 * Sets the voice activation state of a given subId.
4367 */
4368 @Override
4369 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
joonhunshin4ac60942023-11-15 15:23:39 +00004373 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4374 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 final Phone phone = getPhone(subId);
4379 if (phone != null) {
4380 phone.setVoiceActivationState(activationState);
4381 } else {
4382 loge("setVoiceActivationState fails with invalid subId: " + subId);
4383 }
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004386 }
4387 }
4388
4389 /**
4390 * Sets the data activation state of a given subId.
4391 */
4392 @Override
4393 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4395 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396
joonhunshin4ac60942023-11-15 15:23:39 +00004397 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4398 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 final Phone phone = getPhone(subId);
4403 if (phone != null) {
4404 phone.setDataActivationState(activationState);
4405 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004406 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 }
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004410 }
4411 }
4412
4413 /**
4414 * Returns the voice activation state of a given subId.
4415 */
4416 @Override
4417 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419
joonhunshin4ac60942023-11-15 15:23:39 +00004420 enforceTelephonyFeatureWithException(callingPackage,
4421 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4422
fionaxu0152e512016-11-14 13:36:14 -08004423 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 if (phone != null) {
4427 return phone.getVoiceActivationState();
4428 } else {
4429 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4430 }
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004433 }
4434 }
4435
4436 /**
4437 * Returns the data activation state of a given subId.
4438 */
4439 @Override
4440 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442
joonhunshin4ac60942023-11-15 15:23:39 +00004443 enforceTelephonyFeatureWithException(callingPackage,
4444 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4445
fionaxu0152e512016-11-14 13:36:14 -08004446 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
4449 if (phone != null) {
4450 return phone.getDataActivationState();
4451 } else {
4452 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4453 }
4454 } finally {
4455 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004456 }
4457 }
4458
4459 /**
Wink Saville36469e72014-06-11 15:17:00 -07004460 * Returns the unread count of voicemails for a subId
4461 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004463 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4464 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 mApp, subId, callingPackage, callingFeatureId,
4467 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004468 return 0;
4469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 final Phone phone = getPhone(subId);
4473 if (phone != null) {
4474 return phone.getVoiceMessageCount();
4475 } else {
4476 return 0;
4477 }
4478 } finally {
4479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004481 }
4482
4483 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004484 * returns true, if the device is in a state where both voice and data
4485 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004486 */
4487 @Override
4488 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4490 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
Ling Mac28f0212023-03-24 16:07:15 -07004494 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004498 }
4499
4500 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004501 * Send the dialer code if called from the current default dialer or the caller has
4502 * carrier privilege.
4503 * @param inputCode The dialer code to send
4504 */
4505 @Override
4506 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004507 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004509 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4510 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004511 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004513 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515
joonhunshin4ac60942023-11-15 15:23:39 +00004516 enforceTelephonyFeatureWithException(callingPackage,
4517 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004521 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
fionaxu235cc5e2017-03-06 22:25:57 -08004525 }
4526
Pengquan Menga1bb6272018-09-06 09:59:22 -07004527 @Override
4528 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004529 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004530 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4531 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004532
4533 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4534 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4535
shilufc958392020-01-20 11:36:01 -08004536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 if (!isActiveSubscription(subId)) {
4539 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4540 }
4541 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004545 }
4546
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004548 public boolean isInEmergencySmsMode() {
4549 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004550
4551 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4552 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4553
Brad Ebingerb2b65522019-03-15 13:48:47 -07004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 for (Phone phone : PhoneFactory.getPhones()) {
4557 if (phone.isInEmergencySmsMode()) {
4558 return true;
4559 }
4560 }
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 return false;
4565 }
4566
shilu366312e2019-12-17 09:28:10 -08004567 /**
4568 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param c The callback that will be used to send the result.
4571 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004572 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004573 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4574 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004576 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004577
4578 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4579 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4580 "IMS not available on device.");
4581 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 final long token = Binder.clearCallingIdentity();
4583 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004584 int slotId = getSlotIndexOrException(subId);
4585 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004586
4587 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4588 if (controller != null) {
4589 ImsManager imsManager = controller.getImsManager(subId);
4590 if (imsManager != null) {
4591 imsManager.addRegistrationCallbackForSubscription(c, subId);
4592 } else {
4593 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4594 }
4595 } else {
4596 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4597 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004600 } finally {
4601 Binder.restoreCallingIdentity(token);
4602 }
4603 }
4604
shilu366312e2019-12-17 09:28:10 -08004605 /**
4606 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4607 * @param subId The subscription to use to check the configuration.
4608 * @param c The callback that will be used to send the result.
4609 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004611 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004612 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004613 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004614 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4615 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4616 }
Meng Wangafbc5852019-09-19 17:37:13 -07004617 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004618
Meng Wangafbc5852019-09-19 17:37:13 -07004619 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004620 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4621 if (controller != null) {
4622 ImsManager imsManager = controller.getImsManager(subId);
4623 if (imsManager != null) {
4624 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4625 } else {
4626 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4627 + "is inactive, ignoring unregister.");
4628 // If the ImsManager is not valid, just return, since the callback
4629 // will already have been removed internally.
4630 }
4631 }
Meng Wangafbc5852019-09-19 17:37:13 -07004632 } finally {
4633 Binder.restoreCallingIdentity(token);
4634 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 }
4636
Brad Ebingera34a6c22019-10-22 17:36:18 -07004637 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004638 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4639 * @param subId The subscription to use to check the configuration.
4640 * @param c The callback that will be used to send the result.
4641 */
4642 @Override
4643 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4644 throws RemoteException {
4645 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4646 mApp, subId, "registerImsEmergencyRegistrationCallback");
4647
4648 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4650 "IMS not available on device.");
4651 }
4652 final long token = Binder.clearCallingIdentity();
4653 try {
4654 int slotId = getSlotIndexOrException(subId);
4655 verifyImsMmTelConfiguredOrThrow(slotId);
4656
4657 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4658 if (controller != null) {
4659 ImsManager imsManager = controller.getImsManager(subId);
4660 if (imsManager != null) {
4661 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4662 } else {
4663 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4664 }
4665 } else {
4666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4667 }
4668 } catch (ImsException e) {
4669 throw new ServiceSpecificException(e.getCode());
4670 } finally {
4671 Binder.restoreCallingIdentity(token);
4672 }
4673 }
4674
4675 /**
4676 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4677 * @param subId The subscription to use to check the configuration.
4678 * @param c The callback that will be used to send the result.
4679 */
4680 @Override
4681 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4682 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4683 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4685 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4686 }
4687 final long token = Binder.clearCallingIdentity();
4688
4689 try {
4690 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4691 if (controller != null) {
4692 ImsManager imsManager = controller.getImsManager(subId);
4693 if (imsManager != null) {
4694 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4695 } else {
4696 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4697 + "is inactive, ignoring unregister.");
4698 // If the ImsManager is not valid, just return, since the callback
4699 // will already have been removed internally.
4700 }
4701 }
4702 } finally {
4703 Binder.restoreCallingIdentity(token);
4704 }
4705 }
4706
4707 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004708 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4709 */
4710 @Override
4711 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4712 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4713 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4715 "IMS not available on device.");
4716 }
4717 final long token = Binder.clearCallingIdentity();
4718 try {
4719 Phone phone = getPhone(subId);
4720 if (phone == null) {
4721 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4722 + subId + "'");
4723 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4724 }
4725 phone.getImsRegistrationState(regState -> {
4726 try {
4727 consumer.accept((regState == null)
4728 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4729 } catch (RemoteException e) {
4730 // Ignore if the remote process is no longer available to call back.
4731 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4732 }
4733 });
4734 } finally {
4735 Binder.restoreCallingIdentity(token);
4736 }
4737 }
4738
4739 /**
4740 * Get the transport type for the IMS service registration state.
4741 */
4742 @Override
4743 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004744 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004745 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004746 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4747 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4748 "IMS not available on device.");
4749 }
4750 final long token = Binder.clearCallingIdentity();
4751 try {
4752 Phone phone = getPhone(subId);
4753 if (phone == null) {
4754 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4755 + subId + "'");
4756 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4757 }
4758 phone.getImsRegistrationTech(regTech -> {
4759 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4760 int regTechConverted = (regTech == null)
4761 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4762 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4763 regTechConverted);
4764 try {
4765 consumer.accept(regTechConverted);
4766 } catch (RemoteException e) {
4767 // Ignore if the remote process is no longer available to call back.
4768 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4769 }
4770 });
4771 } finally {
4772 Binder.restoreCallingIdentity(token);
4773 }
4774 }
4775
shilu366312e2019-12-17 09:28:10 -08004776 /**
4777 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4778 * @param subId The subscription to use to check the configuration.
4779 * @param c The callback that will be used to send the result.
4780 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004782 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4783 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004784 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004785 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004786 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4788 "IMS not available on device.");
4789 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004790 final long token = Binder.clearCallingIdentity();
4791 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004792 int slotId = getSlotIndexOrException(subId);
4793 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004794
4795 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4796 if (controller != null) {
4797 ImsManager imsManager = controller.getImsManager(subId);
4798 if (imsManager != null) {
4799 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4800 } else {
4801 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4802 }
4803 } else {
4804 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4805 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004806 } catch (ImsException e) {
4807 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004808 } finally {
4809 Binder.restoreCallingIdentity(token);
4810 }
4811 }
4812
shilu366312e2019-12-17 09:28:10 -08004813 /**
4814 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4815 * @param subId The subscription to use to check the configuration.
4816 * @param c The callback that will be used to send the result.
4817 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004818 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004819 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004820 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004821 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4824 }
Meng Wangafbc5852019-09-19 17:37:13 -07004825
4826 final long token = Binder.clearCallingIdentity();
4827 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004828 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4829 if (controller != null) {
4830 ImsManager imsManager = controller.getImsManager(subId);
4831 if (imsManager != null) {
4832 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4833 } else {
4834 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4835 + " is inactive, ignoring unregister.");
4836 // If the ImsManager is not valid, just return, since the callback
4837 // will already have been removed internally.
4838 }
4839 }
Meng Wangafbc5852019-09-19 17:37:13 -07004840 } finally {
4841 Binder.restoreCallingIdentity(token);
4842 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004843 }
4844
4845 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004846 public boolean isCapable(int subId, int capability, int regTech) {
4847 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004848
4849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4850 FEATURE_TELEPHONY_IMS, "isCapable");
4851
Brad Ebinger35c841c2018-10-01 10:40:55 -07004852 final long token = Binder.clearCallingIdentity();
4853 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004854 int slotId = getSlotIndexOrException(subId);
4855 verifyImsMmTelConfiguredOrThrow(slotId);
4856 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4857 } catch (com.android.ims.ImsException e) {
4858 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4859 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004860 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004861 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4862 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004863 } finally {
4864 Binder.restoreCallingIdentity(token);
4865 }
4866 }
4867
4868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004869 public boolean isAvailable(int subId, int capability, int regTech) {
4870 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004871
4872 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4873 FEATURE_TELEPHONY_IMS, "isAvailable");
4874
Brad Ebinger35c841c2018-10-01 10:40:55 -07004875 final long token = Binder.clearCallingIdentity();
4876 try {
4877 Phone phone = getPhone(subId);
4878 if (phone == null) return false;
4879 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004880 } catch (com.android.ims.ImsException e) {
4881 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4882 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 } finally {
4884 Binder.restoreCallingIdentity(token);
4885 }
4886 }
4887
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004888 /**
4889 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4890 * subscription.
4891 * @param subId The subscription to use to check the configuration.
4892 * @param callback The callback that will be used to send the result.
4893 * @param capability The MmTelFeature capability that will be used to send the result.
4894 * @param transportType The transport type of the MmTelFeature capability.
4895 */
4896 @Override
4897 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4898 int transportType) {
4899 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004900 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4901 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4902 "IMS not available on device.");
4903 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004904 final long token = Binder.clearCallingIdentity();
4905 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004906 int slotId = getSlotIndex(subId);
4907 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4908 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4909 + subId + "'");
4910 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4911 }
4912 verifyImsMmTelConfiguredOrThrow(slotId);
4913 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4914 transportType, aBoolean -> {
4915 try {
4916 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4917 } catch (RemoteException e) {
4918 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4919 + "running. Ignore");
4920 }
4921 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004922 } catch (ImsException e) {
4923 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004924 } finally {
4925 Binder.restoreCallingIdentity(token);
4926 }
4927 }
4928
shilu366312e2019-12-17 09:28:10 -08004929 /**
4930 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4931 * @param subId The subscription to use to check the configuration.
4932 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004933 @Override
4934 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004935 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004936 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004937
joonhunshin4ac60942023-11-15 15:23:39 +00004938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4939 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4940
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 final long token = Binder.clearCallingIdentity();
4942 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004943 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004944 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004945 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 } catch (ImsException e) {
4947 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 } finally {
4949 Binder.restoreCallingIdentity(token);
4950 }
4951 }
4952
4953 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004954 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004956 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004957
4958 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4959 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4960
Brad Ebinger35c841c2018-10-01 10:40:55 -07004961 final long identity = Binder.clearCallingIdentity();
4962 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004964 // This setting doesn't require an active ImsService connection, so do not verify. The
4965 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004966 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004967 } catch (ImsException e) {
4968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
4972 }
4973
shilu366312e2019-12-17 09:28:10 -08004974 /**
4975 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4976 * @param subId The subscription to use to check the configuration.
4977 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004979 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004981 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004982
4983 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4984 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4985
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 final long identity = Binder.clearCallingIdentity();
4987 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004989 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004990 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004991 } catch (ImsException e) {
4992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
4996 }
4997
4998 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004999 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005001 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005002
5003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5004 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5005
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 final long identity = Binder.clearCallingIdentity();
5007 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005008 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005009 // This setting doesn't require an active ImsService connection, so do not verify. The
5010 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005011 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005012 } catch (ImsException e) {
5013 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
5017 }
5018
shilu366312e2019-12-17 09:28:10 -08005019 /**
5020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5021 * @param subId The subscription to use to check the configuration.
5022 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005023 @Override
5024 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005025 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005026 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005027
5028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5029 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5030
Brad Ebinger35c841c2018-10-01 10:40:55 -07005031 final long identity = Binder.clearCallingIdentity();
5032 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005033 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005034 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005035 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005036 } catch (ImsException e) {
5037 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
5041 }
5042
5043 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005044 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005046 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005047
5048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5049 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5050
Brad Ebinger35c841c2018-10-01 10:40:55 -07005051 final long identity = Binder.clearCallingIdentity();
5052 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005053 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005054 // This setting doesn't require an active ImsService connection, so do not verify. The
5055 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005056 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005057 } catch (ImsException e) {
5058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
5062 }
5063
shilu366312e2019-12-17 09:28:10 -08005064 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005065 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5066 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5067 * @param subId The subscription to use to check the configuration.
5068 */
5069 @Override
5070 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005071 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005072 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005073
5074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5075 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5076
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005079 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005080 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005081 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005082 } catch (ImsException e) {
5083 throw new ServiceSpecificException(e.getCode());
5084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
5087 }
5088
5089 /**
5090 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5091 * Requires MODIFY_PHONE_STATE permission.
5092 * @param subId The subscription to use to check the configuration.
5093 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5094 * false otherwise
5095 */
5096 @Override
5097 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5099 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005100
5101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5102 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5103
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005106 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005107 // This setting doesn't require an active ImsService connection, so do not verify. The
5108 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005110 } catch (ImsException e) {
5111 throw new ServiceSpecificException(e.getCode());
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
5115 }
5116
5117 /**
shilu366312e2019-12-17 09:28:10 -08005118 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5119 * @param subId The subscription to use to check the configuration.
5120 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005122
Brad Ebinger35c841c2018-10-01 10:40:55 -07005123 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005124 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005125 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005126
5127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5128 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5129
Brad Ebinger35c841c2018-10-01 10:40:55 -07005130 final long identity = Binder.clearCallingIdentity();
5131 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005132 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005133 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005134 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005135 } catch (ImsException e) {
5136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005137 } finally {
5138 Binder.restoreCallingIdentity(identity);
5139 }
5140 }
5141
5142 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005143 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005145 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005146
5147 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5148 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5149
Brad Ebinger35c841c2018-10-01 10:40:55 -07005150 final long identity = Binder.clearCallingIdentity();
5151 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005152 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005153 // This setting doesn't require an active ImsService connection, so do not verify. The
5154 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005155 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005156 } catch (ImsException e) {
5157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
5161 }
5162
5163 @Override
5164 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5166 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005167
5168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5169 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5170
Brad Ebinger35c841c2018-10-01 10:40:55 -07005171 final long identity = Binder.clearCallingIdentity();
5172 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005174 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005175 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005176 } catch (ImsException e) {
5177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
5181 }
5182
shilu366312e2019-12-17 09:28:10 -08005183 /**
5184 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5185 * @param subId The subscription to use to check the configuration.
5186 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005187 @Override
5188 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005189 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005190 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005191
5192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5193 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5194
Brad Ebinger35c841c2018-10-01 10:40:55 -07005195 final long identity = Binder.clearCallingIdentity();
5196 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005197 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005198 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005199 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005200 } catch (ImsException e) {
5201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
5205 }
5206
5207 @Override
5208 public void setVoWiFiModeSetting(int subId, int mode) {
5209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5210 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005211
5212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5213 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5214
Brad Ebinger35c841c2018-10-01 10:40:55 -07005215 final long identity = Binder.clearCallingIdentity();
5216 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005217 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005218 // This setting doesn't require an active ImsService connection, so do not verify. The
5219 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005221 } catch (ImsException e) {
5222 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
5226 }
5227
5228 @Override
5229 public int getVoWiFiRoamingModeSetting(int subId) {
5230 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005231
5232 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5233 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5234
Brad Ebinger35c841c2018-10-01 10:40:55 -07005235 final long identity = Binder.clearCallingIdentity();
5236 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005237 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005238 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005239 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005240 } catch (ImsException e) {
5241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
5245 }
5246
5247 @Override
5248 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5250 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005251
5252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5253 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5254
Brad Ebinger35c841c2018-10-01 10:40:55 -07005255 final long identity = Binder.clearCallingIdentity();
5256 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005257 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005258 // This setting doesn't require an active ImsService connection, so do not verify. The
5259 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005260 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005261 } catch (ImsException e) {
5262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
5266 }
5267
5268 @Override
5269 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5271 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005272
5273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5274 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5275
Brad Ebinger35c841c2018-10-01 10:40:55 -07005276 final long identity = Binder.clearCallingIdentity();
5277 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005278 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005279 // This setting doesn't require an active ImsService connection, so do not verify. The
5280 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005281 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005282 } catch (ImsException e) {
5283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
5287 }
5288
shilu366312e2019-12-17 09:28:10 -08005289 /**
5290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5291 * @param subId The subscription to use to check the configuration.
5292 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005293 @Override
5294 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005295 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005296 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005297
5298 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5299 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5300
Brad Ebinger35c841c2018-10-01 10:40:55 -07005301 final long identity = Binder.clearCallingIdentity();
5302 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005303 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005304 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005305 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005306 } catch (ImsException e) {
5307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
5311 }
5312
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005313 @Override
5314 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5315 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005316
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005317 final long identity = Binder.clearCallingIdentity();
5318 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005319 if (!isImsAvailableOnDevice()) {
5320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5321 "IMS not available on device.");
5322 }
5323 int slotId = getSlotIndexOrException(subId);
5324 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005325
5326 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5327 if (controller != null) {
5328 ImsManager imsManager = controller.getImsManager(subId);
5329 if (imsManager != null) {
5330 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5331 } else {
5332 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5333 }
5334 } else {
5335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5336 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005337 } catch (ImsException e) {
5338 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 @Override
5345 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5346 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005347
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005348 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005349 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5350 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5351 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005352 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005353 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5354 if (controller != null) {
5355 ImsManager imsManager = controller.getImsManager(subId);
5356 if (imsManager != null) {
5357 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5358 } else {
5359 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5360 + " is inactive, ignoring unregister.");
5361 // If the ImsManager is not valid, just return, since the callback will already
5362 // have been removed internally.
5363 }
5364 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005365 } finally {
5366 Binder.restoreCallingIdentity(identity);
5367 }
5368 }
5369
joonhunshincffb7fc2021-11-28 07:32:01 +00005370 @Override
5371 public void registerFeatureProvisioningChangedCallback(int subId,
5372 IFeatureProvisioningCallback callback) {
5373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5374 mApp, subId, "registerFeatureProvisioningChangedCallback");
5375
5376 final long identity = Binder.clearCallingIdentity();
5377 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5378 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5379 }
5380
joonhunshin91bc1952022-04-29 08:47:15 +00005381 try {
5382 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5383 if (controller == null) {
5384 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5385 "Device does not support IMS");
5386 }
5387 controller.addFeatureProvisioningChangedCallback(subId, callback);
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005391 }
5392
5393 @Override
5394 public void unregisterFeatureProvisioningChangedCallback(int subId,
5395 IFeatureProvisioningCallback callback) {
5396 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5397 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5398
5399 final long identity = Binder.clearCallingIdentity();
5400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5401 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5402 }
5403
joonhunshin91bc1952022-04-29 08:47:15 +00005404 try {
5405 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5406 if (controller == null) {
5407 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5408 return;
5409 }
5410 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005414 }
allenwtsu99c623b2020-01-03 18:24:23 +08005415
5416 private void checkModifyPhoneStatePermission(int subId, String message) {
5417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5418 message);
5419 }
5420
allenwtsu99c623b2020-01-03 18:24:23 +08005421 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005422 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005423 boolean isProvisioned) {
5424 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5425
joonhunshin4ac60942023-11-15 15:23:39 +00005426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5427 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5428
allenwtsu99c623b2020-01-03 18:24:23 +08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005431 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5432 if (controller == null) {
5433 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5434 return;
5435 }
5436 controller.setRcsProvisioningStatusForCapability(
5437 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
allenwtsu99c623b2020-01-03 18:24:23 +08005441 }
5442
5443
5444 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005445 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5446 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5447 mApp, subId, "getRcsProvisioningStatusForCapability");
5448
joonhunshin4ac60942023-11-15 15:23:39 +00005449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5450 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5451
allenwtsu99c623b2020-01-03 18:24:23 +08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005454 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5455 if (controller == null) {
5456 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5457
5458 // device does not support IMS, this method will return true always.
5459 return true;
5460 }
5461 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
5465 }
5466
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005467 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005468 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5469 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005470 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005471
joonhunshin4ac60942023-11-15 15:23:39 +00005472 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5473 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5474
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005475 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005478 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5479 if (controller == null) {
5480 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5481 return;
5482 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005483 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005484 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
5488 }
5489
5490 @Override
5491 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5493 mApp, subId, "getProvisioningStatusForCapability");
5494
joonhunshin4ac60942023-11-15 15:23:39 +00005495 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5496 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5497
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005498 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005499 final long identity = Binder.clearCallingIdentity();
5500 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005501 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5502 if (controller == null) {
5503 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005504
joonhunshin91bc1952022-04-29 08:47:15 +00005505 // device does not support IMS, this method will return true always.
5506 return true;
5507 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005508 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5509 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
5513 }
5514
5515 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005516 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5517 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5518 mApp, subId, "isProvisioningRequiredForCapability");
5519
joonhunshin4ac60942023-11-15 15:23:39 +00005520 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5521 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5522
joonhunshincffb7fc2021-11-28 07:32:01 +00005523 final long identity = Binder.clearCallingIdentity();
5524 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005525 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5526 if (controller == null) {
5527 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5528
5529 // device does not support IMS, this method will return false
5530 return false;
5531 }
5532 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005536 }
5537
5538 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005539 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5540 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5541 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005542
joonhunshin4ac60942023-11-15 15:23:39 +00005543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5544 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5545
joonhunshincffb7fc2021-11-28 07:32:01 +00005546 final long identity = Binder.clearCallingIdentity();
5547 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005548 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5549 if (controller == null) {
5550 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5551
5552 // device does not support IMS, this method will return false
5553 return false;
5554 }
5555 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005559 }
5560
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005561 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005562 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5564 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5565 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005566 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5567 mApp, subId, "getImsProvisioningInt");
5568
joonhunshin4ac60942023-11-15 15:23:39 +00005569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5570 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5571
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005572 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005576 int slotId = getSlotIndex(subId);
5577 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5578 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5579 + subId + "' for key:" + key);
5580 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5581 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005582
joonhunshin91bc1952022-04-29 08:47:15 +00005583 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5584 if (controller == null) {
5585 loge("getImsProvisioningInt: Device does not support IMS");
5586
5587 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5588 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5589 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005590 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5591 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005592 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5593 return retVal;
5594 }
5595
calvinpanb5a34062021-02-08 19:59:36 +08005596 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005597 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005598 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5599 + subId + "' for key:" + key);
5600 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
5604 }
5605
5606 @Override
5607 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5609 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5610 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005611 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5612 mApp, subId, "getImsProvisioningString");
5613
joonhunshin4ac60942023-11-15 15:23:39 +00005614 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5615 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5616
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005620 int slotId = getSlotIndex(subId);
5621 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5622 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5623 + subId + "' for key:" + key);
5624 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5625 }
calvinpanb5a34062021-02-08 19:59:36 +08005626 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005627 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005628 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5629 + subId + "' for key:" + key);
5630 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
5634 }
5635
5636 @Override
5637 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5639 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5640 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5642 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005643
joonhunshin4ac60942023-11-15 15:23:39 +00005644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5645 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5646
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005647 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 int slotId = getSlotIndex(subId);
5652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5653 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5654 + subId + "' for key:" + key);
5655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5656 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005657
joonhunshin91bc1952022-04-29 08:47:15 +00005658 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5659 if (controller == null) {
5660 loge("setImsProvisioningInt: Device does not support IMS");
5661
5662 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5663 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5664 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005665 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5666 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005667 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5668 return retVal;
5669 }
5670
calvinpanb5a34062021-02-08 19:59:36 +08005671 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5672 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005673 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005674 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005675 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
5679 }
5680
5681 @Override
5682 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5684 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5685 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5687 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005688
5689 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5690 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5691
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005695 int slotId = getSlotIndex(subId);
5696 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5697 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5698 + subId + "' for key:" + key);
5699 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5700 }
calvinpanb5a34062021-02-08 19:59:36 +08005701 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5702 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005703 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005704 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005705 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
5709 }
5710
Brad Ebinger919631e2021-06-02 17:46:35 -07005711 /**
5712 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5713 * for the given slot ID or no ImsResolver instance has been created.
5714 * @param slotId The slot ID that the IMS service is created for.
5715 * @throws ImsException If there is no ImsService configured for this slot.
5716 */
5717 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5718 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5719 ImsFeature.FEATURE_MMTEL)) {
5720 throw new ImsException("This subscription does not support MMTEL over IMS",
5721 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5722 }
5723 }
5724
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005725 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005726 int slotId = SubscriptionManager.getSlotIndex(subId);
5727 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005728 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5729 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005730 }
5731 return slotId;
5732 }
5733
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005734 private int getSlotIndex(int subId) {
5735 int slotId = SubscriptionManager.getSlotIndex(subId);
5736 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5737 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5738 }
5739 return slotId;
5740 }
5741
Wink Saville36469e72014-06-11 15:17:00 -07005742 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005743 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005744 */
5745 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005746 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5747 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005748 try {
5749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5750 } catch (SecurityException se) {
5751 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5752 throw new SecurityException("Package " + callingPackage + " does not belong to "
5753 + Binder.getCallingUid());
5754 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005755 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005756 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005758 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005759 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005760 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005761 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5763 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005764
joonhunshin4ac60942023-11-15 15:23:39 +00005765 enforceTelephonyFeatureWithException(callingPackage,
5766 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 final Phone phone = getPhone(subId);
5771 if (phone != null) {
5772 return phone.getServiceState().getDataNetworkType();
5773 } else {
5774 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5775 }
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005779 }
5780
5781 /**
5782 * Returns the data network type
5783 */
5784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005785 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005786 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005787 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005788 }
5789
5790 /**
5791 * Returns the data network type for a subId
5792 */
5793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005794 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5795 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005796 String functionName = "getDataNetworkTypeForSubscriber";
5797 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5798 mApp, functionName)) {
5799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5800 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5802 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005803 }
5804
joonhunshin4ac60942023-11-15 15:23:39 +00005805 enforceTelephonyFeatureWithException(callingPackage,
5806 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 final Phone phone = getPhone(subId);
5811 if (phone != null) {
5812 return phone.getServiceState().getDataNetworkType();
5813 } else {
5814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5815 }
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005819 }
5820
5821 /**
Wink Saville36469e72014-06-11 15:17:00 -07005822 * Returns the Voice network type for a subId
5823 */
5824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005825 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5826 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005827 String functionName = "getVoiceNetworkTypeForSubscriber";
5828 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5829 mApp, functionName)) {
5830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5831 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5833 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005834 }
5835
joonhunshin4ac60942023-11-15 15:23:39 +00005836 enforceTelephonyFeatureWithException(callingPackage,
5837 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 final Phone phone = getPhone(subId);
5842 if (phone != null) {
5843 return phone.getServiceState().getVoiceNetworkType();
5844 } else {
5845 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5846 }
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005850 }
5851
5852 /**
5853 * @return true if a ICC card is present
5854 */
5855 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005856 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005857 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005858 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005859 }
5860
5861 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005862 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005863 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005864 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005865 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005866 if (!mApp.getResources().getBoolean(
5867 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5869 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5870 }
joonhunshin4ac60942023-11-15 15:23:39 +00005871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 final long identity = Binder.clearCallingIdentity();
5873 try {
5874 final Phone phone = PhoneFactory.getPhone(slotIndex);
5875 if (phone != null) {
5876 return phone.getIccCard().hasIccCard();
5877 } else {
5878 return false;
5879 }
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005883 }
5884
5885 /**
5886 * Return if the current radio is LTE on CDMA. This
5887 * is a tri-state return value as for a period of time
5888 * the mode may be unknown.
5889 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005890 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005891 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005892 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005893 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005894 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005895 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5896 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5897 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005898 }
5899
Sanket Padawe356d7632015-06-22 14:03:32 -07005900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005901 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5902 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005903 try {
5904 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5905 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005906 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5907 }
5908
joonhunshin4ac60942023-11-15 15:23:39 +00005909 enforceTelephonyFeatureWithException(callingPackage,
5910 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 final long identity = Binder.clearCallingIdentity();
5913 try {
5914 final Phone phone = getPhone(subId);
5915 if (phone == null) {
5916 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5917 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005918 return TelephonyProperties.lte_on_cdma_device()
5919 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 }
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005923 }
Wink Saville36469e72014-06-11 15:17:00 -07005924 }
5925
Wink Saville36469e72014-06-11 15:17:00 -07005926 /**
5927 * {@hide}
5928 * Returns Default subId, 0 in the case of single standby.
5929 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005930 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005931 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005932 }
5933
Shishir Agrawala9f32182016-04-12 12:00:16 -07005934 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005935 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005936 }
5937
Wink Savilleb564aae2014-10-23 10:18:09 -07005938 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005939 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005940 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005941
Pengquan Menge92a50d2018-09-21 15:54:48 -07005942 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005943 return getSubscriptionManagerService().isActiveSubId(subId,
5944 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005945 }
5946
Ihab Awadf2177b72013-11-25 13:33:23 -08005947 /**
5948 * @see android.telephony.TelephonyManager.WifiCallingChoices
5949 */
5950 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 final long identity = Binder.clearCallingIdentity();
5952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005953 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5955 getWhenToMakeWifiCallsDefaultPreference());
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005959 }
5960
5961 /**
5962 * @see android.telephony.TelephonyManager.WifiCallingChoices
5963 */
5964 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005968 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005973 }
5974
Sailesh Nepald1e68152013-12-12 19:08:02 -08005975 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005976 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005977 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005978 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005979
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005980 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5981 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5982 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005983 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005984 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005985 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005986 }
5987 return PhoneFactory.getPhone(phoneId);
5988 }
5989
Shishir Agrawal566b7612013-10-28 14:41:00 -07005990 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005991 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005992 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005993
Rambo Wanga1782702021-11-10 20:15:19 -08005994 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5995 /*message=*/ "iccOpenLogicalChannel");
5996
5997 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5998 // Verify that the callingPackage in the request belongs to the calling UID
5999 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6000
joonhunshin4ac60942023-11-15 15:23:39 +00006001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6002 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6003
Rambo Wanga1782702021-11-10 20:15:19 -08006004 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006005 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006006
Rambo Wanga1782702021-11-10 20:15:19 -08006007 private Phone getPhoneFromValidIccLogicalChannelRequest(
6008 @NonNull IccLogicalChannelRequest request, String message) {
6009 Phone phone;
6010 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, request.subId, message);
6013 phone = getPhoneFromSubId(request.subId);
6014 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6015 enforceModifyPermission();
6016 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6017 } else {
6018 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006019 }
Rambo Wanga1782702021-11-10 20:15:19 -08006020 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006021 }
6022
6023 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006024 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 final long identity = Binder.clearCallingIdentity();
6026 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006027 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006029 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6030 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006031 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6032 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 loge("The calling package is not allowed to access ISD-R.");
6034 throw new SecurityException(
6035 "The calling package is not allowed to access ISD-R.");
6036 }
Derek Tan740e1672017-06-27 14:56:27 -07006037 }
Derek Tan740e1672017-06-27 14:56:27 -07006038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006040 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6041 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 return response;
6043 } finally {
6044 Binder.restoreCallingIdentity(identity);
6045 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006046 }
6047
6048 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006049 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006050 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6051 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6052
Rambo Wanga1782702021-11-10 20:15:19 -08006053 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6054 /*message=*/"iccCloseLogicalChannel");
6055
6056 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6057
6058 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006060
Rambo Wanga1782702021-11-10 20:15:19 -08006061 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6062 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006063 // before this feature is enabled, this API should only return false if
6064 // the operation fails instead of throwing runtime exception for
6065 // backward-compatibility.
6066 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6067 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 final long identity = Binder.clearCallingIdentity();
6069 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006070 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006071 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 }
Chen Xue9d737e2022-01-01 23:41:31 -08006073 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006074 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006075 Boolean success = false;
6076 if (result instanceof RuntimeException) {
6077 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006078 if (shouldThrowExceptionOnFailure) {
6079 throw (RuntimeException) result;
6080 } else {
6081 return false;
6082 }
Chen Xue9d737e2022-01-01 23:41:31 -08006083 } else if (result instanceof Boolean) {
6084 success = (Boolean) result;
6085 } else {
6086 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6087 }
Rambo Wanga1782702021-11-10 20:15:19 -08006088 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 return success;
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006092 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006093 }
6094
6095 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006096 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006097 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6099 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006100
6101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6102 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6103
Jordan Liu4c733742019-02-28 12:03:40 -08006104 if (DBG) {
6105 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6106 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6107 + p3 + " data=" + data);
6108 }
6109 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6110 command, p1, p2, p3, data);
6111 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006112
Jordan Liu4c733742019-02-28 12:03:40 -08006113 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006114 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006115 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006116 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006117
6118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6119 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6120 "iccTransmitApduLogicalChannelBySlot");
6121
Jordan Liu4c733742019-02-28 12:03:40 -08006122 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006123 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006124 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6125 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006126 }
6127 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006128 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6129 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006130 }
6131
6132 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6133 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 final long identity = Binder.clearCallingIdentity();
6135 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006136 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 return "";
6138 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006141 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6142 null /* workSource */);
6143 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 // Append the returned status code to the end of the response payload.
6146 String s = Integer.toHexString(
6147 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6148 if (response.payload != null) {
6149 s = IccUtils.bytesToHexString(response.payload) + s;
6150 }
6151 return s;
6152 } finally {
6153 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006154 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006155 }
Jake Hambye994d462014-02-03 13:10:13 -08006156
Evan Charltonc66da362014-05-16 14:06:40 -07006157 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006158 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6159 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6161 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006163
6164 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6165 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6166
Jordan Liu4c733742019-02-28 12:03:40 -08006167 if (DBG) {
6168 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6169 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6170 }
6171 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6172 cla, command, p1, p2, p3, data);
6173 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006174
Jordan Liu4c733742019-02-28 12:03:40 -08006175 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006176 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006177 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006178 enforceModifyPermission();
6179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006180
6181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6182 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6183
Jordan Liu4c733742019-02-28 12:03:40 -08006184 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006185 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006186 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6187 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006188 }
6189
6190 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006191 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6192 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006193 }
6194
6195 // open APDU basic channel assuming the caller has sufficient permissions
6196 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6197 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 final long identity = Binder.clearCallingIdentity();
6199 try {
6200 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6201 && TextUtils.equals(ISDR_AID, data)) {
6202 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006203 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6204 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 if (bestComponent == null
6206 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6207 loge("The calling package is not allowed to select ISD-R.");
6208 throw new SecurityException(
6209 "The calling package is not allowed to select ISD-R.");
6210 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006211 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006214 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6215 null /* workSource */);
6216 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 // Append the returned status code to the end of the response payload.
6219 String s = Integer.toHexString(
6220 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6221 if (response.payload != null) {
6222 s = IccUtils.bytesToHexString(response.payload) + s;
6223 }
6224 return s;
6225 } finally {
6226 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006227 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006228 }
6229
6230 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006231 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006232 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6234 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006235
joonhunshin4ac60942023-11-15 15:23:39 +00006236 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6237 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 if (DBG) {
6242 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6243 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6244 }
6245
6246 IccIoResult response =
6247 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6248 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6249 subId);
6250
6251 if (DBG) {
6252 log("Exchange SIM_IO [R]" + response);
6253 }
6254
6255 byte[] result = null;
6256 int length = 2;
6257 if (response.payload != null) {
6258 length = 2 + response.payload.length;
6259 result = new byte[length];
6260 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6261 } else {
6262 result = new byte[length];
6263 }
6264
6265 result[length - 1] = (byte) response.sw2;
6266 result[length - 2] = (byte) response.sw1;
6267 return result;
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006270 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006271 }
6272
Nathan Haroldb3014052017-01-25 15:57:32 -08006273 /**
6274 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6275 * on a particular subscription
6276 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006277 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6278 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006280 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006281 return null;
6282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283
joonhunshin4ac60942023-11-15 15:23:39 +00006284 enforceTelephonyFeatureWithException(callingPackage,
6285 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 final long identity = Binder.clearCallingIdentity();
6288 try {
6289 if (appType != TelephonyManager.APPTYPE_USIM
6290 && appType != TelephonyManager.APPTYPE_SIM) {
6291 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6292 return null;
6293 }
6294 Object response = sendRequest(
6295 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6296 if (response instanceof String[]) {
6297 return (String[]) response;
6298 }
yincheng zhao2737e882019-09-06 17:06:54 -07006299 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006301 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 } finally {
6303 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006304 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006305 }
6306
yincheng zhao2737e882019-09-06 17:06:54 -07006307 /**
6308 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6309 * subscription.
6310 *
6311 * @param subId the id of the subscription.
6312 * @param appType the uicc app type, must be USIM or SIM.
6313 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6314 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006315 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006316 * @return number of fplmns that is successfully written to the SIM.
6317 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006318 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6319 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6321 mApp, subId, "setForbiddenPlmns");
6322
joonhunshin4ac60942023-11-15 15:23:39 +00006323 enforceTelephonyFeatureWithException(callingPackage,
6324 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6325
yincheng zhao2737e882019-09-06 17:06:54 -07006326 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6327 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6328 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6329 }
6330 if (fplmns == null) {
6331 throw new IllegalArgumentException("Fplmn List provided is null");
6332 }
6333 for (String fplmn : fplmns) {
6334 if (!CellIdentity.isValidPlmn(fplmn)) {
6335 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6336 }
6337 }
6338 final long identity = Binder.clearCallingIdentity();
6339 try {
6340 Object response = sendRequest(
6341 CMD_SET_FORBIDDEN_PLMNS,
6342 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6343 subId);
6344 return (int) response;
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
6348 }
6349
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006350 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006351 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006354
joonhunshin4ac60942023-11-15 15:23:39 +00006355 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6356 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6361 if (response.payload == null) {
6362 return "";
6363 }
Evan Charltonc66da362014-05-16 14:06:40 -07006364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 // Append the returned status code to the end of the response payload.
6366 String s = Integer.toHexString(
6367 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6368 s = IccUtils.bytesToHexString(response.payload) + s;
6369 return s;
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
Evan Charltonc66da362014-05-16 14:06:40 -07006373 }
6374
Jake Hambye994d462014-02-03 13:10:13 -08006375 /**
6376 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6377 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6378 *
6379 * @param itemID the ID of the item to read
6380 * @return the NV item as a String, or null on error.
6381 */
6382 @Override
6383 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006391 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6393 return value;
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Jake Hambye994d462014-02-03 13:10:13 -08006397 }
6398
6399 /**
6400 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6401 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6402 *
6403 * @param itemID the ID of the item to read
6404 * @param itemValue the value to write, as a String
6405 * @return true on success; false on any failure
6406 */
6407 @Override
6408 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
6413 final long identity = Binder.clearCallingIdentity();
6414 try {
6415 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6416 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006417 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6419 return success;
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
Jake Hambye994d462014-02-03 13:10:13 -08006423 }
6424
6425 /**
6426 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6427 * Used for device configuration by some CDMA operators.
6428 *
6429 * @param preferredRoamingList byte array containing the new PRL
6430 * @return true on success; false on any failure
6431 */
6432 @Override
6433 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6435 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436
6437 final long identity = Binder.clearCallingIdentity();
6438 try {
6439 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6440 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6441 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6442 return success;
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Jake Hambye994d462014-02-03 13:10:13 -08006446 }
6447
6448 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006449 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006450 * Used for device configuration by some CDMA operators.
6451 *
chen xu6dac5ab2018-10-26 17:39:23 -07006452 * @param slotIndex - device slot.
6453 *
Jake Hambye994d462014-02-03 13:10:13 -08006454 * @return true on success; false on any failure
6455 */
6456 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006457 public boolean resetModemConfig(int slotIndex) {
6458 Phone phone = PhoneFactory.getPhone(slotIndex);
6459 if (phone != null) {
6460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6461 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462
joonhunshin4ac60942023-11-15 15:23:39 +00006463 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6464 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6465
chen xu6dac5ab2018-10-26 17:39:23 -07006466 final long identity = Binder.clearCallingIdentity();
6467 try {
6468 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6469 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6470 return success;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 }
chen xu6dac5ab2018-10-26 17:39:23 -07006475 return false;
6476 }
6477
6478 /**
6479 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6480 *
6481 * @param slotIndex - device slot.
6482 *
6483 * @return true on success; false on any failure
6484 */
6485 @Override
6486 public boolean rebootModem(int slotIndex) {
6487 Phone phone = PhoneFactory.getPhone(slotIndex);
6488 if (phone != null) {
6489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6490 mApp, phone.getSubId(), "rebootModem");
6491
joonhunshin4ac60942023-11-15 15:23:39 +00006492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6493 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6494
chen xu6dac5ab2018-10-26 17:39:23 -07006495 final long identity = Binder.clearCallingIdentity();
6496 try {
6497 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6498 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6499 return success;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
6503 }
6504 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006505 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006506
Brad Ebinger51f743a2017-01-23 13:50:20 -08006507 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006508 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6509 * {@link #disableIms(int)}.
6510 * @param slotIndex device slot.
6511 */
6512 public void resetIms(int slotIndex) {
6513 enforceModifyPermission();
6514
joonhunshin4ac60942023-11-15 15:23:39 +00006515 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6516 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6517
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006518 final long identity = Binder.clearCallingIdentity();
6519 try {
6520 if (mImsResolver == null) {
6521 // may happen if the does not support IMS.
6522 return;
6523 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006524 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006525 } finally {
6526 Binder.restoreCallingIdentity(identity);
6527 }
6528 }
6529
6530 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006531 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6532 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006533 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006534 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006539 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006540 // may happen if the device does not support IMS.
6541 return;
6542 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006543 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 } finally {
6545 Binder.restoreCallingIdentity(identity);
6546 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006547 }
6548
6549 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006550 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6551 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006552 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006553 public void disableIms(int slotId) {
6554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006558 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006559 // may happen if the device does not support IMS.
6560 return;
6561 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006562 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006566 }
6567
6568 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006569 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6570 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006571 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006572 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006573 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575
6576 final long identity = Binder.clearCallingIdentity();
6577 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006578 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006579 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6580 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006581 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006582 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006586 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006587 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006588 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6589 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006590 @Override
6591 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006592 enforceModifyPermission();
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006597 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006598 } finally {
6599 Binder.restoreCallingIdentity(identity);
6600 }
6601 }
6602
6603 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006604 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006605 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006606 */
6607 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006612 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006613 // may happen if the device does not support IMS.
6614 return null;
6615 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006616 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006620 }
6621
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006622 /**
6623 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006624 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006625 */
6626 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006631 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006632 // may happen if the device does not support IMS.
6633 return null;
6634 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006635 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006639 }
6640
Brad Ebinger884c07b2018-02-15 16:17:40 -08006641 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006642 * Sets the ImsService Package Name that Telephony will bind to.
6643 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 * @param slotIndex the slot ID that the ImsService should bind for.
6645 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006646 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006647 * @param featureTypes An integer array of feature types associated with a packageName.
6648 * @param packageName The name of the package that the current configuration will be replaced
6649 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006650 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6653 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006656 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 final long identity = Binder.clearCallingIdentity();
6659 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006661 // may happen if the device does not support IMS.
6662 return false;
6663 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006664 Map<Integer, String> featureConfig = new HashMap<>();
6665 for (int featureType : featureTypes) {
6666 featureConfig.put(featureType, packageName);
6667 }
6668 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6669 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006673 }
6674
6675 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006676 * Clears any carrier ImsService overrides for the slot index specified that were previously
6677 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6678 *
6679 * This should only be used for testing.
6680 *
6681 * @param slotIndex the slot ID that the ImsService should bind for.
6682 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6683 */
6684 @Override
6685 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6687 "clearCarrierImsServiceOverride");
6688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006689 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006690
6691 final long identity = Binder.clearCallingIdentity();
6692 try {
6693 if (mImsResolver == null) {
6694 // may happen if the device does not support IMS.
6695 return false;
6696 }
6697 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
6700 }
6701 }
6702
6703 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006704 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006705 *
6706 * @param slotId The slot that the ImsService is associated with.
6707 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6708 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006709 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006710 * @return the package name of the ImsService configuration.
6711 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006712 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6713 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006714 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006715 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6716 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 final long identity = Binder.clearCallingIdentity();
6719 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006720 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006721 // may happen if the device does not support IMS.
6722 return "";
6723 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006724 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006725 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6726 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006730 }
6731
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006732 /**
6733 * Get the MmTelFeature state associated with the requested subscription id.
6734 * @param subId The subscription that the MmTelFeature is associated with.
6735 * @param callback A callback with an integer containing the
6736 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6737 */
6738 @Override
6739 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6740 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006741 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6743 "IMS not available on device.");
6744 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006745 final long token = Binder.clearCallingIdentity();
6746 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006747 int slotId = getSlotIndex(subId);
6748 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6749 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6750 + subId + "'");
6751 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6752 }
6753 verifyImsMmTelConfiguredOrThrow(slotId);
6754 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6755 try {
6756 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6757 } catch (RemoteException e) {
6758 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6759 + "Ignore");
6760 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006761 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006762 } catch (ImsException e) {
6763 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006764 } finally {
6765 Binder.restoreCallingIdentity(token);
6766 }
6767 }
6768
Daniel Brightbb5840b2021-01-12 15:48:18 -08006769 /**
6770 * Sets the ims registration state on all valid {@link Phone}s.
6771 */
6772 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006777 // NOTE: Before S, this method only set the default phone.
6778 for (final Phone phone : PhoneFactory.getPhones()) {
6779 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6780 phone.setImsRegistrationState(registered);
6781 }
6782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Wink Saville36469e72014-06-11 15:17:00 -07006786 }
6787
6788 /**
Stuart Scott54788802015-03-30 13:18:01 -07006789 * Set the network selection mode to automatic.
6790 *
6791 */
6792 @Override
6793 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6795 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796
joonhunshin4ac60942023-11-15 15:23:39 +00006797 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6798 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 final long identity = Binder.clearCallingIdentity();
6801 try {
shilufc958392020-01-20 11:36:01 -08006802 if (!isActiveSubscription(subId)) {
6803 return;
6804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006806 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6807 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 } finally {
6809 Binder.restoreCallingIdentity(identity);
6810 }
Stuart Scott54788802015-03-30 13:18:01 -07006811 }
6812
Jack Yud10cdd42020-09-28 20:28:01 -07006813 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006814 * Ask the radio to connect to the input network and change selection mode to manual.
6815 *
6816 * @param subId the id of the subscription.
6817 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6818 * the operator to attach to.
6819 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6820 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6821 * normal network selection next time.
6822 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006823 */
6824 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006825 public boolean setNetworkSelectionModeManual(
6826 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6828 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006829
joonhunshin4ac60942023-11-15 15:23:39 +00006830 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6831 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6832
Jack Yu285100e2022-12-02 22:48:35 -08006833 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006834 if (!isActiveSubscription(subId)) {
6835 return false;
6836 }
6837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006839 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006841 if (DBG) {
6842 log("setNetworkSelectionModeManual: subId: " + subId
6843 + " operator: " + operatorInfo);
6844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006849 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006850 /**
shilu84f6e8b2019-12-19 13:58:01 -08006851 * Get the manual network selection
6852 *
6853 * @param subId the id of the subscription.
6854 *
6855 * @return the previously saved user selected PLMN
6856 */
6857 @Override
6858 public String getManualNetworkSelectionPlmn(int subId) {
6859 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006860 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6861 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006862
joonhunshin4ac60942023-11-15 15:23:39 +00006863 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6864 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6865
shilu84f6e8b2019-12-19 13:58:01 -08006866 final long identity = Binder.clearCallingIdentity();
6867 try {
6868 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006869 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006870 }
6871
6872 final Phone phone = getPhone(subId);
6873 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006874 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006875 }
6876 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6877 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006878 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006883
6884 /**
6885 * Scans for available networks.
6886 */
6887 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006888 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6889 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6891 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006892 LocationAccessPolicy.LocationPermissionResult locationResult =
6893 LocationAccessPolicy.checkLocationPermission(mApp,
6894 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6895 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006896 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006897 .setCallingPid(Binder.getCallingPid())
6898 .setCallingUid(Binder.getCallingUid())
6899 .setMethod("getCellNetworkScanResults")
6900 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006901 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6902 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006903 .build());
6904 switch (locationResult) {
6905 case DENIED_HARD:
6906 throw new SecurityException("Not allowed to access scan results -- location");
6907 case DENIED_SOFT:
6908 return null;
6909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910
Pengquan Menga1bb6272018-09-06 09:59:22 -07006911 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 try {
6913 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006914 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006919 }
6920
6921 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006922 * Get the call forwarding info, given the call forwarding reason.
6923 */
6924 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006925 public void getCallForwarding(int subId, int callForwardingReason,
6926 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006927 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006928
6929 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6930 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6931
Shuo Qian4a594052020-01-23 11:59:30 -08006932 long identity = Binder.clearCallingIdentity();
6933 try {
6934 if (DBG) {
6935 log("getCallForwarding: subId " + subId
6936 + " callForwardingReason" + callForwardingReason);
6937 }
Hall Liu27d24262020-09-18 19:04:59 -07006938
6939 Phone phone = getPhone(subId);
6940 if (phone == null) {
6941 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006942 callback.onError(
6943 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006944 } catch (RemoteException e) {
6945 // ignore
6946 }
6947 return;
6948 }
6949
6950 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6951 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6952 @Override
6953 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6954 try {
6955 callback.onCallForwardingInfoAvailable(info);
6956 } catch (RemoteException e) {
6957 // ignore
6958 }
6959 }
6960
6961 @Override
6962 public void onError(int error) {
6963 try {
6964 callback.onError(error);
6965 } catch (RemoteException e) {
6966 // ignore
6967 }
6968 }
6969 });
6970 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006971 } finally {
6972 Binder.restoreCallingIdentity(identity);
6973 }
6974 }
6975
6976 /**
6977 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6978 * reason, the number to forward, and the timeout before the forwarding is attempted.
6979 */
6980 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006981 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6982 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006983 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006984
6985 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6986 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6987
Shuo Qian4a594052020-01-23 11:59:30 -08006988 long identity = Binder.clearCallingIdentity();
6989 try {
6990 if (DBG) {
6991 log("setCallForwarding: subId " + subId
6992 + " callForwardingInfo" + callForwardingInfo);
6993 }
Hall Liu27d24262020-09-18 19:04:59 -07006994
6995 Phone phone = getPhone(subId);
6996 if (phone == null) {
6997 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006998 callback.accept(
6999 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007000 } catch (RemoteException e) {
7001 // ignore
7002 }
7003 return;
7004 }
7005
7006 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7007 FunctionalUtils.ignoreRemoteException(callback::accept));
7008
7009 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
7013 }
7014
7015 /**
Hall Liu27d24262020-09-18 19:04:59 -07007016 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007017 */
7018 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007019 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007020 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007021
7022 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7023 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7024
Shuo Qian4a594052020-01-23 11:59:30 -08007025 long identity = Binder.clearCallingIdentity();
7026 try {
Hall Liu27d24262020-09-18 19:04:59 -07007027 Phone phone = getPhone(subId);
7028 if (phone == null) {
7029 try {
7030 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7031 } catch (RemoteException e) {
7032 // ignore
7033 }
7034 return;
7035 }
SongFerngWang0e767992021-03-31 22:08:45 +08007036 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7037 PersistableBundle c = configManager.getConfigForSubId(subId);
7038 boolean requireUssd = c.getBoolean(
7039 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007040
Shuo Qian4a594052020-01-23 11:59:30 -08007041 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007042 if (requireUssd) {
7043 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7044 getSubscriptionCarrierId(subId));
7045 String newUssdCommand = "";
7046 try {
7047 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007048 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007049 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7050 } catch (NullPointerException e) {
7051 loge("Failed to generate USSD number" + e);
7052 }
7053 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7054 mMainThreadHandler, callback, carrierXmlParser,
7055 CarrierXmlParser.SsEntry.SSAction.QUERY);
7056 final String ussdCommand = newUssdCommand;
7057 Executors.newSingleThreadExecutor().execute(() -> {
7058 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7059 });
7060 } else {
7061 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7062 callback::accept);
7063 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7064 }
Shuo Qian4a594052020-01-23 11:59:30 -08007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
7069
7070 /**
Hall Liu27d24262020-09-18 19:04:59 -07007071 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007072 */
7073 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007074 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007075 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007076
7077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7078 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7079
Shuo Qian4a594052020-01-23 11:59:30 -08007080 long identity = Binder.clearCallingIdentity();
7081 try {
Hall Liu27d24262020-09-18 19:04:59 -07007082 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7083
7084 Phone phone = getPhone(subId);
7085 if (phone == null) {
7086 try {
7087 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7088 } catch (RemoteException e) {
7089 // ignore
7090 }
7091 return;
7092 }
7093
SongFerngWang0e767992021-03-31 22:08:45 +08007094 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7095 PersistableBundle c = configManager.getConfigForSubId(subId);
7096 boolean requireUssd = c.getBoolean(
7097 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007098
SongFerngWang0e767992021-03-31 22:08:45 +08007099 if (DBG) log("getCallWaitingStatus: subId " + subId);
7100 if (requireUssd) {
7101 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7102 getSubscriptionCarrierId(subId));
7103 CarrierXmlParser.SsEntry.SSAction ssAction =
7104 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7105 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7106 String newUssdCommand = "";
7107 try {
7108 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007109 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007110 .makeCommand(ssAction, null);
7111 } catch (NullPointerException e) {
7112 loge("Failed to generate USSD number" + e);
7113 }
7114 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7115 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7116 final String ussdCommand = newUssdCommand;
7117 Executors.newSingleThreadExecutor().execute(() -> {
7118 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7119 });
7120 } else {
7121 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7122 FunctionalUtils.ignoreRemoteException(callback::accept));
7123
7124 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7125 }
Shuo Qian4a594052020-01-23 11:59:30 -08007126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
7129 }
7130
7131 /**
yinxub1bed742017-04-17 11:45:04 -07007132 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007133 *
yinxub1bed742017-04-17 11:45:04 -07007134 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007135 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7136 * location related information which will be sent if the caller already possess
7137 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007138 * @param request contains the radio access networks with bands/channels to scan
7139 * @param messenger callback messenger for scan results or errors
7140 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007141 * @return the id of the requested scan which can be used to stop the scan.
7142 */
7143 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007144 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7145 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007146 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7148 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007149 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007150 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7151 if (!renounceFineLocationAccess) {
7152 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007153 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7154 .setCallingPackage(callingPackage)
7155 .setCallingFeatureId(callingFeatureId)
7156 .setCallingPid(Binder.getCallingPid())
7157 .setCallingUid(Binder.getCallingUid())
7158 .setMethod("requestNetworkScan")
7159 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7160 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7161 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7162 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007163 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007164 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007165 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7166 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007167 if (e != null) {
7168 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7169 throw e;
7170 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007171 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007172 return TelephonyScanManager.INVALID_SCAN_ID;
7173 }
7174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 }
joonhunshin4ac60942023-11-15 15:23:39 +00007176
7177 enforceTelephonyFeatureWithException(callingPackage,
7178 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7179
Hall Liu912dfd32019-04-25 14:02:26 -07007180 int callingUid = Binder.getCallingUid();
7181 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007182 final long identity = Binder.clearCallingIdentity();
7183 try {
7184 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007185 renounceFineLocationAccess, request, messenger, binder,
7186 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007187 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190 }
yinxu504e1392017-04-12 16:03:22 -07007191 }
7192
Hall Liub2ac8ef2019-02-28 15:56:23 -08007193 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007194 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007195 boolean hasCarrierPriv;
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7199 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
7202 }
Hall Liu558027f2019-05-15 19:14:05 -07007203 boolean hasNetworkScanPermission =
7204 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007205 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007206
7207 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7208 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7209 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007210 }
7211
7212 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7213 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007214 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7215 return new SecurityException("Specific channels must not be"
7216 + " scanned without location access.");
7217 }
7218 }
7219 }
7220
Hall Liub2ac8ef2019-02-28 15:56:23 -08007221 return null;
7222 }
7223
yinxu504e1392017-04-12 16:03:22 -07007224 /**
7225 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007226 *
7227 * @param subId id of the subscription
7228 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007229 */
7230 @Override
7231 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7233 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
Hall Liu912dfd32019-04-25 14:02:26 -07007235 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 final long identity = Binder.clearCallingIdentity();
7237 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007238 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
yinxu504e1392017-04-12 16:03:22 -07007242 }
7243
7244 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007245 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007246 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007247 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007248 */
7249 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007250 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007251 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007252 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007253 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254
joonhunshin4ac60942023-11-15 15:23:39 +00007255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7256 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 final long identity = Binder.clearCallingIdentity();
7259 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007260 if (DBG) log("getAllowedNetworkTypesBitmask");
7261 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7262 int networkTypesBitmask = (result != null ? result[0] : -1);
7263 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7264 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007268 }
7269
7270 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007271 * Get the allowed network types for certain reason.
7272 *
7273 * @param subId the id of the subscription.
7274 * @param reason the reason the allowed network type change is taking place
7275 * @return the allowed network types.
7276 */
7277 @Override
7278 public long getAllowedNetworkTypesForReason(int subId,
7279 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007280 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007281 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007282
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007283 if (!mApp.getResources().getBoolean(
7284 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7285 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7286 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7287 "getAllowedNetworkTypesForReason");
7288 }
joonhunshin4ac60942023-11-15 15:23:39 +00007289
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007290 final long identity = Binder.clearCallingIdentity();
7291 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007292 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
7296 }
7297
7298 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007299 * Enable/Disable E-UTRA-NR Dual Connectivity
7300 * @param subId subscription id of the sim card
7301 * @param nrDualConnectivityState expected NR dual connectivity state
7302 * This can be passed following states
7303 * <ol>
7304 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7305 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7306 * <li>Disable NR dual connectivity and force secondary cell to be released
7307 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7308 * </ol>
7309 * @return operation result.
7310 */
7311 @Override
7312 public int setNrDualConnectivityState(int subId,
7313 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7315 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007316 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007317 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7318 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7319 }
7320
Sooraj Sasindran37444802020-08-11 10:40:43 -07007321 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7325 nrDualConnectivityState, subId,
7326 workSource);
7327 if (DBG) log("enableNRDualConnectivity result: " + result);
7328 return result;
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
7332 }
7333
7334 /**
7335 * Is E-UTRA-NR Dual Connectivity enabled
7336 * @return true if dual connectivity is enabled else false
7337 */
7338 @Override
7339 public boolean isNrDualConnectivityEnabled(int subId) {
7340 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007341 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007342 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007343 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007344 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7345 return false;
7346 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7351 null, subId, workSource);
7352 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7353 return isEnabled;
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
7357 }
7358
7359 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007360 * Set the allowed network types of the device and
7361 * provide the reason triggering the allowed network change.
7362 *
7363 * @param subId the id of the subscription.
7364 * @param reason the reason the allowed network type change is taking place
7365 * @param allowedNetworkTypes the allowed network types.
7366 * @return true on success; false on any failure.
7367 */
7368 @Override
7369 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007370 @TelephonyManager.AllowedNetworkTypesReason int reason,
7371 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7373 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007374 // If the caller only has carrier privileges, then they should not be able to override
7375 // any network types which were set for security reasons.
7376 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7377 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007378 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007379 throw new SecurityException(
7380 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007381 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007382 }
joonhunshin4ac60942023-11-15 15:23:39 +00007383
7384 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7385 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7386
SongFerngWang3ef3e072020-12-21 16:41:52 +08007387 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007388 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007389 return false;
7390 }
7391 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7392 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007393 return false;
7394 }
7395
Jack Yu5b494332023-01-23 18:18:04 +00007396 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7397 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007398
Jack Yue37dd262022-12-16 11:53:37 -08007399 Phone phone = getPhone(subId);
7400 if (phone == null) {
7401 return false;
7402 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007403
Jack Yue37dd262022-12-16 11:53:37 -08007404 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007405 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007406 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007407 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007408
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007409 final long identity = Binder.clearCallingIdentity();
7410 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007411 Boolean success = (Boolean) sendRequest(
7412 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7413 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7414
7415 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7416 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
7420 }
7421
7422 /**
Miaoa84611c2019-03-15 09:21:10 +08007423 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007424 *
Miaoa84611c2019-03-15 09:21:10 +08007425 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007426 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007427 * @hide
7428 */
7429 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007430 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007431 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007432
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007433 if (!mApp.getResources().getBoolean(
7434 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7436 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7437 }
joonhunshin4ac60942023-11-15 15:23:39 +00007438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007440 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 try {
Miaoa84611c2019-03-15 09:21:10 +08007442 if (phone != null) {
7443 return phone.hasMatchedTetherApnSetting();
7444 } else {
7445 return false;
7446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 } finally {
7448 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007449 }
Junda Liu475951f2014-11-07 16:45:03 -08007450 }
7451
7452 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007453 * Get the user enabled state of Mobile Data.
7454 *
7455 * TODO: remove and use isUserDataEnabled.
7456 * This can't be removed now because some vendor codes
7457 * calls through ITelephony directly while they should
7458 * use TelephonyManager.
7459 *
7460 * @return true on enabled
7461 */
7462 @Override
7463 public boolean getDataEnabled(int subId) {
7464 return isUserDataEnabled(subId);
7465 }
7466
7467 /**
7468 * Get whether mobile data is enabled per user setting.
7469 *
7470 * There are other factors deciding whether mobile data is actually enabled, but they are
7471 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007472 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007473 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7474 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007475 *
7476 * @return {@code true} if data is enabled else {@code false}
7477 */
7478 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007479 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007480 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007481 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007482 try {
7483 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7484 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007485 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007486 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7487 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007488 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007490 mApp, subId, functionName);
7491
Robert Greenwalt646120a2014-05-23 11:54:03 -07007492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493
7494 final long identity = Binder.clearCallingIdentity();
7495 try {
Jack Yu285100e2022-12-02 22:48:35 -08007496 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7498 Phone phone = PhoneFactory.getPhone(phoneId);
7499 if (phone != null) {
7500 boolean retVal = phone.isUserDataEnabled();
7501 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7502 return retVal;
7503 } else {
7504 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7505 return false;
7506 }
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007509 }
7510 }
7511
7512 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007513 * Checks if the device is capable of mobile data by considering whether whether the
7514 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7515 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007516 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007517 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007518 */
7519 @Override
7520 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007522 try {
7523 try {
7524 mApp.enforceCallingOrSelfPermission(
7525 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007527 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007528 try {
7529 mApp.enforceCallingOrSelfPermission(
7530 android.Manifest.permission.READ_PHONE_STATE,
7531 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007532 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007533 mApp.enforceCallingOrSelfPermission(
7534 permission.READ_BASIC_PHONE_STATE, functionName);
7535 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007536 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007537 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007538 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540
joonhunshin4ac60942023-11-15 15:23:39 +00007541 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7542 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
Jack Yu285100e2022-12-02 22:48:35 -08007546 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007548 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007549 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007550 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 return retVal;
7552 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007553 if (DBG) {
7554 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7555 + subId + " retVal=false");
7556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 return false;
7558 }
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007561 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007562 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007563
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007564 /**
7565 * Check if data is enabled for a specific reason
7566 * @param subId Subscription index
7567 * @param reason the reason the data enable change is taking place
7568 * @return {@code true} if the overall data is enabled; {@code false} if not.
7569 */
7570 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007571 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007572 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007573 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007574 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007575 try {
7576 mApp.enforceCallingOrSelfPermission(
7577 android.Manifest.permission.ACCESS_NETWORK_STATE,
7578 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007579 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007580 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7581 functionName);
7582 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007583 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007584 try {
7585 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007586 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007587 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007589 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007590 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007591 }
7592
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007593 if (!mApp.getResources().getBoolean(
7594 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7596 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7597 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007598
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
Jack Yu285100e2022-12-02 22:48:35 -08007601 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007603 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007604 + " reason=" + reason);
7605 }
7606 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007607 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007608 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007609 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007610 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007611 return retVal;
7612 } else {
7613 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007614 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007615 + subId + " retVal=false");
7616 }
7617 return false;
7618 }
7619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
7622 }
7623
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007624 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007625 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007626 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7627 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7628
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007629 // No permission needed; this only lets the caller inspect their own status.
7630 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007631 }
Junda Liu29340342014-07-10 15:23:27 -07007632
7633 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007634 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007635 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007636
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007637 if (!mApp.getResources().getBoolean(
7638 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7639 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7640 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7641 "getCarrierPrivilegeStatusForUid");
7642 }
joonhunshin4ac60942023-11-15 15:23:39 +00007643
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007644 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7645 }
7646
7647 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7648 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007649 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007650 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007651 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7652 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007653 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7654 if (cpt == null) {
7655 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007656 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7657 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007658 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007659 }
7660
7661 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007662 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007663 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007664
7665 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7666 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7667
chen xuf7e9fe82019-05-09 19:31:02 -07007668 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007669 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007670 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007671 Phone phone = getPhone(subId);
7672 if (phone == null) {
7673 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7674 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7675 }
7676 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7677 if (cpt == null) {
7678 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007679 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7680 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007681 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007682 }
7683
7684 @Override
7685 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007686 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007687
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007688 if (!mApp.getResources().getBoolean(
7689 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7690 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7691 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7692 "checkCarrierPrivilegesForPackageAnyPhone");
7693 }
joonhunshin4ac60942023-11-15 15:23:39 +00007694
Rambo Wange7209ce2022-02-23 13:41:02 -08007695 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7696 }
7697
7698 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007699 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007700 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007702 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007703 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7704 Phone phone = PhoneFactory.getPhone(phoneId);
7705 if (phone == null) {
7706 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007707 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7709 if (cpt == null) {
7710 continue;
7711 }
7712 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007713 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7714 break;
7715 }
7716 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007717 return result;
Junda Liu29340342014-07-10 15:23:27 -07007718 }
Derek Tan89e89d42014-07-08 17:00:10 -07007719
7720 @Override
Junda Liue64de782015-04-16 17:19:16 -07007721 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007722 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007723
7724 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7725 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7726 "getCarrierPackageNamesForIntentAndPhone");
7727
Rambo Wang8a247eb2022-02-08 21:11:18 +00007728 Phone phone = PhoneFactory.getPhone(phoneId);
7729 if (phone == null) {
7730 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007731 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007732 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7733 if (cpt == null) {
7734 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007735 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007736 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007737 }
7738
Amith Yamasani6e118872016-02-19 12:53:51 -08007739 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007740 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007741 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007742 Phone phone = PhoneFactory.getPhone(phoneId);
7743 if (phone == null) {
7744 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007745 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007746 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7747 if (cpt == null) {
7748 return Collections.emptyList();
7749 }
7750 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007751 }
7752
chen xuf7e9fe82019-05-09 19:31:02 -07007753 @Override
7754 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007755 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007756
7757 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7758 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7759 "getPackagesWithCarrierPrivilegesForAllPhones");
7760
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007761 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007762 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007763 try {
7764 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7765 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7766 }
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007769 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007770 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007771 }
7772
Rambo Wang6812ffb2022-03-15 16:54:17 -07007773 @Override
7774 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7775 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7776
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007777 if (!mApp.getResources().getBoolean(
7778 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7779 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7780 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7781 "getCarrierServicePackageNameForLogicalSlot");
7782 }
joonhunshin4ac60942023-11-15 15:23:39 +00007783
Rambo Wang6812ffb2022-03-15 16:54:17 -07007784 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7785 if (phone == null) {
7786 return null;
7787 }
7788 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7789 if (cpt == null) {
7790 return null;
7791 }
7792 return cpt.getCarrierServicePackageName();
7793 }
7794
Wink Savilleb564aae2014-10-23 10:18:09 -07007795 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007796 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007797 UiccPort port = phone == null ? null : phone.getUiccPort();
7798 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007799 return null;
7800 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007801 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007802 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007803 return null;
7804 }
7805 return iccId;
7806 }
7807
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007808 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007809 public void setCallComposerStatus(int subId, int status) {
7810 enforceModifyPermission();
7811
joonhunshin4ac60942023-11-15 15:23:39 +00007812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7813 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7814
Shuo Qiane4e11672020-12-15 22:15:33 -08007815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 Phone phone = getPhone(subId);
7818 if (phone != null) {
7819 Phone defaultPhone = phone.getImsPhone();
7820 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7821 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7822 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007823 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7824 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007825 }
7826 }
Shuo Qian284ae752020-12-22 19:10:14 -08007827 } catch (ImsException e) {
7828 throw new ServiceSpecificException(e.getCode());
7829 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007830 Binder.restoreCallingIdentity(identity);
7831 }
7832 }
7833
7834 @Override
7835 public int getCallComposerStatus(int subId) {
7836 enforceReadPrivilegedPermission("getCallComposerStatus");
7837
joonhunshin4ac60942023-11-15 15:23:39 +00007838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7839 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7840
Shuo Qiane4e11672020-12-15 22:15:33 -08007841 final long identity = Binder.clearCallingIdentity();
7842 try {
7843 Phone phone = getPhone(subId);
7844 if (phone != null) {
7845 Phone defaultPhone = phone.getImsPhone();
7846 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7847 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7848 return imsPhone.getCallComposerStatus();
7849 }
7850 }
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
7854 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7855 }
7856
7857 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007858 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7859 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007860 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007861 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007862
joonhunshin4ac60942023-11-15 15:23:39 +00007863 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7864 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7865 "setLine1NumberForDisplayForSubscriber");
7866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 final long identity = Binder.clearCallingIdentity();
7868 try {
7869 final String iccId = getIccId(subId);
7870 final Phone phone = getPhone(subId);
7871 if (phone == null) {
7872 return false;
7873 }
arunvoddub1365e62024-07-31 09:42:31 +00007874 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7875 Rlog.e(LOG_TAG, "Number is too long");
7876 return false;
7877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 final String subscriberId = phone.getSubscriberId();
7879
7880 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007881 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 + subscriberId + " to " + number);
7883 }
7884
7885 if (TextUtils.isEmpty(iccId)) {
7886 return false;
7887 }
7888
7889 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7890
7891 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7892 if (alphaTag == null) {
7893 editor.remove(alphaTagPrefKey);
7894 } else {
7895 editor.putString(alphaTagPrefKey, alphaTag);
7896 }
7897
7898 // Record both the line number and IMSI for this ICCID, since we need to
7899 // track all merged IMSIs based on line number
7900 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7901 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7902 if (number == null) {
7903 editor.remove(numberPrefKey);
7904 editor.remove(subscriberPrefKey);
7905 } else {
7906 editor.putString(numberPrefKey, number);
7907 editor.putString(subscriberPrefKey, subscriberId);
7908 }
7909
7910 editor.commit();
7911 return true;
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007914 }
Derek Tan7226c842014-07-02 17:42:23 -07007915 }
7916
7917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007918 public String getLine1NumberForDisplay(int subId, String callingPackage,
7919 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007920 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007923 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007924 return null;
7925 }
Derek Tan97ebb422014-09-05 16:55:38 -07007926
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007927 if (!mApp.getResources().getBoolean(
7928 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7929 enforceTelephonyFeatureWithException(callingPackage,
7930 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7931 }
joonhunshin4ac60942023-11-15 15:23:39 +00007932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 final long identity = Binder.clearCallingIdentity();
7934 try {
7935 String iccId = getIccId(subId);
7936 if (iccId != null) {
7937 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7938 if (DBG_MERGE) {
7939 log("getLine1NumberForDisplay returning "
7940 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7941 }
7942 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7945 return null;
7946 } finally {
7947 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007948 }
Derek Tan7226c842014-07-02 17:42:23 -07007949 }
7950
7951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007952 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7953 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007955 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007956 return null;
7957 }
Derek Tan97ebb422014-09-05 16:55:38 -07007958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 String iccId = getIccId(subId);
7962 if (iccId != null) {
7963 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7964 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7965 }
7966 return null;
7967 } finally {
7968 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007969 }
Derek Tan7226c842014-07-02 17:42:23 -07007970 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007971
7972 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007973 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7974 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007975 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7976 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007978 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007979 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007980 return null;
7981 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007982
Jordan Liub49b04b2019-05-06 14:45:15 -07007983 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7984 // the process, where TelephonyManager was instantiated.
7985 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007986 final long identity = Binder.clearCallingIdentity();
7987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 final TelephonyManager tele = TelephonyManager.from(context);
7990 final SubscriptionManager sub = SubscriptionManager.from(context);
7991
7992 // Figure out what subscribers are currently active
7993 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994
Jordan Liub49b04b2019-05-06 14:45:15 -07007995 // Only consider subs which match the current subId
7996 // This logic can be simplified. See b/131189269 for progress.
7997 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007998 activeSubscriberIds.add(tele.getSubscriberId(subId));
7999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000
8001 // First pass, find a number override for an active subscriber
8002 String mergeNumber = null;
8003 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8004 for (String key : prefs.keySet()) {
8005 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8006 final String subscriberId = (String) prefs.get(key);
8007 if (activeSubscriberIds.contains(subscriberId)) {
8008 final String iccId = key.substring(
8009 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8010 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8011 mergeNumber = (String) prefs.get(numberKey);
8012 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008013 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 + " for active subscriber " + subscriberId);
8015 }
8016 if (!TextUtils.isEmpty(mergeNumber)) {
8017 break;
8018 }
8019 }
8020 }
8021 }
8022
8023 // Shortcut when no active merged subscribers
8024 if (TextUtils.isEmpty(mergeNumber)) {
8025 return null;
8026 }
8027
8028 // Second pass, find all subscribers under that line override
8029 final ArraySet<String> result = new ArraySet<>();
8030 for (String key : prefs.keySet()) {
8031 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8032 final String number = (String) prefs.get(key);
8033 if (mergeNumber.equals(number)) {
8034 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8035 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8036 final String subscriberId = (String) prefs.get(subscriberKey);
8037 if (!TextUtils.isEmpty(subscriberId)) {
8038 result.add(subscriberId);
8039 }
8040 }
8041 }
8042 }
8043
8044 final String[] resultArray = result.toArray(new String[result.size()]);
8045 Arrays.sort(resultArray);
8046 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008047 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8049 }
8050 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008051 } finally {
8052 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008053 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008054 }
8055
8056 @Override
zoey chen38003472019-12-13 17:16:31 +08008057 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8058 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008059
joonhunshin4ac60942023-11-15 15:23:39 +00008060 enforceTelephonyFeatureWithException(callingPackage,
8061 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8062
Malcolm Chen6ca97372019-07-01 16:28:21 -07008063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 final TelephonyManager telephonyManager = mApp.getSystemService(
8066 TelephonyManager.class);
8067 String subscriberId = telephonyManager.getSubscriberId(subId);
8068 if (subscriberId == null) {
8069 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008070 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008071 + subId);
8072 }
8073 return null;
8074 }
8075
Jack Yu3beaf9d2023-04-14 09:17:27 -07008076 final SubscriptionInfo info = getSubscriptionManagerService()
8077 .getSubscriptionInfo(subId);
8078 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008079 // If it doesn't belong to any group, return just subscriberId of itself.
8080 if (groupUuid == null) {
8081 return new String[]{subscriberId};
8082 }
8083
8084 // Get all subscriberIds from the group.
8085 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008086 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8087 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8088 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008089 for (SubscriptionInfo subInfo : groupInfos) {
8090 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8091 if (subscriberId != null) {
8092 mergedSubscriberIds.add(subscriberId);
8093 }
8094 }
8095
8096 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099
8100 }
8101 }
8102
8103 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008104 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008105 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008106 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107
joonhunshin4ac60942023-11-15 15:23:39 +00008108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8109 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 final Phone phone = getPhone(subId);
8114 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8115 } finally {
8116 Binder.restoreCallingIdentity(identity);
8117 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008118 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008119
8120 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008121 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008122 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8123 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008124 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8125 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126
8127 final long identity = Binder.clearCallingIdentity();
8128 try {
8129 final Phone phone = getPhone(subId);
8130 if (phone == null) {
8131 return false;
8132 }
8133 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8134 cdmaNonRoamingList);
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008137 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008138 }
8139
8140 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008141 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008142 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008143 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008144 if (phone == null) {
8145 return raf;
8146 }
8147
Shuo Qiandee53402020-05-29 14:08:15 -07008148 try {
8149 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008150 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008151 mApp, phone.getSubId(), "getRadioAccessFamily");
8152 } catch (SecurityException e) {
8153 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8154 throw e;
8155 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008156
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008157 if (!mApp.getResources().getBoolean(
8158 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8159 enforceTelephonyFeatureWithException(callingPackage,
8160 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8161 }
joonhunshin4ac60942023-11-15 15:23:39 +00008162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163 final long identity = Binder.clearCallingIdentity();
8164 try {
chen xub97461a2018-10-26 14:17:57 -07008165 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
chen xub97461a2018-10-26 14:17:57 -07008169 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008170 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008171
8172 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008173 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008174 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008175 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8176 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008177 enforceTelephonyFeatureWithException(callingPackage,
8178 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8179
Hall Liu82694d52020-12-11 18:22:04 -08008180 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008181 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008182 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8183 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008184 if (!dialerRoleHolders.contains(callingPackage)) {
8185 throw new SecurityException("App must be the dialer role holder to"
8186 + " upload a call composer pic");
8187 }
8188
8189 Executors.newSingleThreadExecutor().execute(() -> {
8190 ByteArrayOutputStream output = new ByteArrayOutputStream(
8191 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8192 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8193 boolean readUntilEnd = false;
8194 int totalBytesRead = 0;
8195 byte[] buffer = new byte[16 * 1024];
8196 while (true) {
8197 int numRead;
8198 try {
8199 numRead = input.read(buffer);
8200 } catch (IOException e) {
8201 try {
8202 fd.checkError();
8203 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8204 null);
8205 } catch (IOException e1) {
8206 // This means that the other side closed explicitly with an error. If this
8207 // happens, log and ignore.
8208 loge("Remote end of call composer picture pipe closed: " + e1);
8209 }
8210 break;
8211 }
8212 if (numRead == -1) {
8213 readUntilEnd = true;
8214 break;
8215 }
8216 totalBytesRead += numRead;
8217 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8218 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8219 try {
8220 input.close();
8221 } catch (IOException e) {
8222 // ignore
8223 }
8224 break;
8225 }
8226 output.write(buffer, 0, numRead);
8227 }
8228 // Generally, the remote end will close the file descriptors. The only case where we
8229 // close is above, where the picture size is too big.
8230
8231 try {
8232 fd.checkError();
8233 } catch (IOException e) {
8234 loge("Remote end for call composer closed with an error: " + e);
8235 return;
8236 }
8237
Hall Liuaa4211e2021-01-20 15:43:39 -08008238 if (!readUntilEnd) {
8239 loge("Did not finish reading entire image; aborting");
8240 return;
8241 }
Hall Liu82694d52020-12-11 18:22:04 -08008242
Hall Liuaa4211e2021-01-20 15:43:39 -08008243 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8244 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8245 new CallComposerPictureTransfer.Factory() {},
8246 imageData,
8247 (result) -> {
8248 if (result.first != null) {
8249 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8250 Bundle outputResult = new Bundle();
8251 outputResult.putParcelable(
8252 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8253 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8254 outputResult);
8255 } else {
8256 callback.send(result.second, null);
8257 }
8258 }
8259 );
Hall Liu82694d52020-12-11 18:22:04 -08008260 });
8261 }
8262
8263 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008264 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008265 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267
joonhunshin4ac60942023-11-15 15:23:39 +00008268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8269 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271 final long identity = Binder.clearCallingIdentity();
8272 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008273 ImsManager.getInstance(defaultPhone.getContext(),
8274 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 } finally {
8276 Binder.restoreCallingIdentity(identity);
8277 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008278 }
8279
8280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008281 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008282 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8284 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008285 return false;
8286 }
Svet Ganovb320e182015-04-16 12:30:10 -07008287
joonhunshin4ac60942023-11-15 15:23:39 +00008288 enforceTelephonyFeatureWithException(callingPackage,
8289 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 // Check the user preference and the system-level IMS setting. Even if the user has
8294 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8295 // In the long run, we may instead need to check if there exists a connection service
8296 // which can support video calling.
8297 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008298 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 return imsManager.isVtEnabledByPlatform()
8300 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8301 && imsManager.isVtEnabledByUser();
8302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008305 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008306
Andrew Leea1239f22015-03-02 17:44:07 -08008307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008308 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8309 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008311 mApp, subId, callingPackage, callingFeatureId,
8312 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 return false;
8314 }
8315
joonhunshin4ac60942023-11-15 15:23:39 +00008316 enforceTelephonyFeatureWithException(callingPackage,
8317 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 CarrierConfigManager configManager =
8322 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008323 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
Andrew Leea1239f22015-03-02 17:44:07 -08008328 }
8329
8330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008331 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008333 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 return false;
8335 }
8336
joonhunshin4ac60942023-11-15 15:23:39 +00008337 enforceTelephonyFeatureWithException(callingPackage,
8338 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 final long identity = Binder.clearCallingIdentity();
8341 try {
8342 CarrierConfigManager configManager =
8343 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008344 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
8348 }
Andrew Leea1239f22015-03-02 17:44:07 -08008349 }
8350
Andrew Lee9431b832015-03-09 18:46:45 -07008351 @Override
8352 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008353 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008354 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008355 }
8356
8357 @Override
8358 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8360 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362 final long identity = Binder.clearCallingIdentity();
8363 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008364 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 } finally {
8366 Binder.restoreCallingIdentity(identity);
8367 }
Andrew Lee9431b832015-03-09 18:46:45 -07008368 }
8369
Hall Liuf6668912018-10-31 17:05:23 -07008370 /**
8371 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8372 * support for the feature and device firmware support.
8373 *
8374 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8375 */
8376 @Override
8377 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008378 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8379 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008382 final Phone phone = getPhone(subscriptionId);
8383 if (phone == null) {
8384 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8385 return false;
8386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008388 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008390 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8391 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8392 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 return isCarrierSupported && isDeviceSupported;
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
Hall Liu98187582018-01-22 19:15:32 -08008397 }
8398
Hall Liuf6668912018-10-31 17:05:23 -07008399 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008400 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8401 * RTT setting, will return true if the device and carrier both support RTT.
8402 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008403 */
8404 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405 final long identity = Binder.clearCallingIdentity();
8406 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008407 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8408 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8409 return false;
8410 }
8411 }
8412
Hall Liu5bab75c2019-12-11 23:58:20 +00008413 boolean isRttSupported = isRttSupported(subscriptionId);
8414 boolean isUserRttSettingOn = Settings.Secure.getInt(
8415 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8416 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8417 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8418 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419 } finally {
8420 Binder.restoreCallingIdentity(identity);
8421 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008422 }
8423
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008424 @Deprecated
8425 @Override
8426 public String getDeviceId(String callingPackage) {
8427 return getDeviceIdWithFeature(callingPackage, null);
8428 }
8429
Sanket Padawe7310cc72015-01-14 09:53:20 -08008430 /**
8431 * Returns the unique device ID of phone, for example, the IMEI for
8432 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8433 *
8434 * <p>Requires Permission:
8435 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8436 */
8437 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008438 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008439 try {
8440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8441 } catch (SecurityException se) {
8442 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8443 throw new SecurityException("Package " + callingPackage + " does not belong to "
8444 + Binder.getCallingUid());
8445 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008446 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008447 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008448 return null;
8449 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008450 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008451 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008452 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008453 return null;
8454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008455
8456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 return phone.getDeviceId();
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
8461 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008462 }
8463
Ping Sunc67b7c22016-03-02 19:16:45 +08008464 /**
8465 * {@hide}
8466 * Returns the IMS Registration Status on a particular subid
8467 *
8468 * @param subId
8469 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008470 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008471 Phone phone = getPhone(subId);
8472 if (phone != null) {
8473 return phone.isImsRegistered();
8474 } else {
8475 return false;
8476 }
8477 }
8478
Santos Cordon7a1885b2015-02-03 11:15:19 -08008479 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008480 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008481 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008483 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008484 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8485 }
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
8492 }
8493
8494 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008495 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008496 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008497 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008498 mApp,
8499 subscriptionId,
8500 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8501 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008502
8503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8504 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8505
Tyler Gunnf70ed162019-04-03 15:28:53 -07008506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 Phone phone = getPhone(subscriptionId);
8509 if (phone == null) {
8510 return null;
8511 }
8512 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
8516 }
8517
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008518 /**
8519 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008520 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008521 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 Phone phone = getPhone(subId);
8525 if (phone != null) {
8526 return phone.isWifiCallingEnabled();
8527 } else {
8528 return false;
8529 }
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008532 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008533 }
8534
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008535 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008536 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008537 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008538 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 Phone phone = getPhone(subId);
8542 if (phone != null) {
8543 return phone.isVideoEnabled();
8544 } else {
8545 return false;
8546 }
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008549 }
8550 }
8551
8552 /**
8553 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8554 * defined in {@link ImsRegistrationImplBase}.
8555 */
8556 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008557 final long identity = Binder.clearCallingIdentity();
8558 try {
8559 Phone phone = getPhone(subId);
8560 if (phone != null) {
8561 return phone.getImsRegistrationTech();
8562 } else {
8563 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8564 }
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008567 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008568 }
8569
Stuart Scott8eef64f2015-04-08 15:13:54 -07008570 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008571 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008572 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008573
8574 enforceTelephonyFeatureWithException(callingPackage,
8575 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8576
Stuart Scott981d8582015-04-21 14:09:50 -07008577 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8578 return;
8579 }
Kai Shif70f46f2021-03-03 13:59:46 -08008580 Phone defaultPhone = getDefaultPhone();
8581 if (defaultPhone != null) {
8582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8583 mApp, getDefaultPhone().getSubId(), "factoryReset");
8584 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008585 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008586
Svet Ganovcc087f82015-05-12 20:35:54 -07008587 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008588 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8589 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008590 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008591 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008592 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008593 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008594 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008595 setDataRoamingEnabled(subId, phone == null ? false
8596 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008597 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008598 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008599 // There has been issues when Sms raw table somehow stores orphan
8600 // fragments. They lead to garbled message when new fragments come
8601 // in and combined with those stale ones. In case this happens again,
8602 // user can reset all network settings which will clean up this table.
8603 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008604 // Clean up IMS settings as well here.
8605 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008606 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008607 ImsManager.getInstance(mApp, slotId).factoryReset();
8608 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008609
Kai Shif70f46f2021-03-03 13:59:46 -08008610 if (defaultPhone == null) {
8611 return;
8612 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008613 // Erase modem config if erase modem on network setting is enabled.
8614 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8615 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8616 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008617 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008618 }
Kai Shif70f46f2021-03-03 13:59:46 -08008619
8620 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008621 } finally {
8622 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008623 }
8624 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008625
SongFerngWangfd89b102021-05-27 22:44:54 +08008626 @VisibleForTesting
8627 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8628 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8629 return;
8630 }
8631 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8632 RILConstants.PREFERRED_NETWORK_MODE);
8633 SubscriptionManager.setSubscriptionProperty(subId,
8634 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8635 "user=" + defaultNetworkType);
8636 phone.loadAllowedNetworksFromSubscriptionDatabase();
8637 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8638 defaultNetworkType, null);
8639 }
8640
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008641 private void cleanUpSmsRawTable(Context context) {
8642 ContentResolver resolver = context.getContentResolver();
8643 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8644 resolver.delete(uri, null, null);
8645 }
8646
Narayan Kamath1c496c22015-04-16 14:40:19 +01008647 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008648 public String getSimLocaleForSubscriber(int subId) {
8649 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008650
8651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8652 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8653
chen xu5d3637b2019-01-21 23:31:38 -08008654 final Phone phone = getPhone(subId);
8655 if (phone == null) {
8656 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008657 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008659 final long identity = Binder.clearCallingIdentity();
8660 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008661 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8662 phone.getContext().getOpPackageName(),
8663 phone.getContext().getAttributionTag());
8664 if (info == null) {
8665 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8666 return null;
chen xu6291c472019-02-04 12:55:53 -08008667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 // Try and fetch the locale from the carrier properties or from the SIM language
8669 // preferences (EF-PL and EF-LI)...
8670 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008672 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8673 if (localeFromDefaultSim != null) {
8674 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8675 if (DBG) log("Using locale from subId: " + subId + " locale: "
8676 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008677 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008678 } else {
8679 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008680 }
8681 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 // The SIM language preferences only store a language (e.g. fr = French), not an
8684 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8685 // the SIM and carrier preferences does not include a country we add the country
8686 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008687 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008688 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008689 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008690 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691 }
8692
8693 if (DBG) log("No locale found - returning null");
8694 return null;
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008698 }
8699
tom hsu0b59d292022-09-29 23:49:21 +08008700 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008701 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008702 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008703 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008704 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008705 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8706 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008707 Locale.forLanguageTag(localeTag).getCountry())) {
8708 return localeTag;
8709 }
8710 }
8711 return inputLocale.toLanguageTag();
8712 }
8713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714 /**
8715 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8716 */
8717 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008718 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008719 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008720 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008721
Gary Jian3aa9a762022-01-24 16:41:19 +08008722 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8723 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008724
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008725 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008726 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8727 * representing the state of the modem.
8728 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008729 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8730 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008731 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008732 */
8733 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008734 public void requestModemActivityInfo(ResultReceiver result) {
8735 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008736
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008737 if (!mApp.getResources().getBoolean(
8738 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8740 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8741 }
joonhunshin4ac60942023-11-15 15:23:39 +00008742
vagdeviaf9a5b92018-08-15 16:01:53 -07008743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008744
8745 final long identity = Binder.clearCallingIdentity();
8746 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008747 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008748 } finally {
8749 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008750 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008751 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008752
Gary Jian76280a42022-12-07 16:18:33 +08008753 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008754 // less than total activity duration.
8755 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8756 if (info == null) {
8757 return false;
8758 }
8759 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008760 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008761 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8762
Hall Liu49656c02020-10-09 19:00:11 -07008763 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8764
Siddharth Rayb8114062018-06-17 15:02:38 -07008765 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008766 && (info.getSleepTimeMillis() <= activityDurationMs)
8767 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008768 }
8769
Gary Jian3aa9a762022-01-24 16:41:19 +08008770 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8771 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8772 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8773 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8774
8775 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8776 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8777 }
8778
8779 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8780 mLastModemActivityInfo.setReceiveTimeMillis(
8781 rat,
8782 freq,
8783 info.getReceiveTimeMillis(rat, freq)
8784 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8785 }
8786
8787 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8788 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8789 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8790 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8791
8792 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8793 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8794 }
8795 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8796 mLastModemActivityInfo.setReceiveTimeMillis(
8797 rat,
8798 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8799 }
8800
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008801 /**
8802 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8803 * @param info recent ModemActivityInfo
8804 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008805 private void mergeModemActivityInfo(ModemActivityInfo info) {
8806 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008807 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008808 boolean matched;
8809 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8810 matched = false;
8811 int rat = info.getSpecificInfoRat(i);
8812 int freq = info.getSpecificInfoFrequencyRange(i);
8813 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8814 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8815 //if it already exists
8816 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8817 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8818 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8819 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8820 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8821 updateLastModemActivityInfo(info, rat, freq);
8822 matched = true;
8823 }
8824 } else {
8825 updateLastModemActivityInfo(info, rat);
8826 matched = true;
8827 }
8828 }
8829 }
8830
8831 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008832 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008833 new ActivityStatsTechSpecificInfo(
8834 rat,
8835 freq,
8836 info.getTransmitTimeMillis(rat, freq),
8837 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008838 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008839 }
8840 }
8841 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8842 mLastModemActivitySpecificInfo =
8843 new ActivityStatsTechSpecificInfo[merged.size()];
8844 merged.toArray(mLastModemActivitySpecificInfo);
8845
8846 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8847 mLastModemActivityInfo.setSleepTimeMillis(
8848 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008849 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008850 mLastModemActivityInfo.setIdleTimeMillis(
8851 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008852 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008853
8854 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008855 new ModemActivityInfo(
8856 mLastModemActivityInfo.getTimestampMillis(),
8857 mLastModemActivityInfo.getSleepTimeMillis(),
8858 mLastModemActivityInfo.getIdleTimeMillis(),
8859 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008860 }
8861
8862 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8863 ActivityStatsTechSpecificInfo[] info) {
8864 int infoSize = info.length;
8865 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8866 for (int i = 0; i < infoSize; i++) {
8867 ret[i] = new ActivityStatsTechSpecificInfo(
8868 info[i].getRat(), info[i].getFrequencyRange(),
8869 info[i].getTransmitTimeMillis(),
8870 (int) info[i].getReceiveTimeMillis());
8871 }
8872 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008873 }
8874
Jack Yu85bd38a2015-11-09 11:34:32 -08008875 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008876 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008877 */
8878 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008879 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8880 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8881 Phone phone = PhoneFactory.getPhone(slotIndex);
8882 if (phone == null) {
8883 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8884 return null;
8885 }
8886
8887 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008890 return null;
8891 }
8892
joonhunshin4ac60942023-11-15 15:23:39 +00008893 enforceTelephonyFeatureWithException(callingPackage,
8894 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8895
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008896 boolean hasFinePermission = false;
8897 boolean hasCoarsePermission = false;
8898 if (!renounceFineLocationAccess) {
8899 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8900 LocationAccessPolicy.checkLocationPermission(mApp,
8901 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8902 .setCallingPackage(callingPackage)
8903 .setCallingFeatureId(callingFeatureId)
8904 .setCallingPid(Binder.getCallingPid())
8905 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008906 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008907 .setLogAsInfo(true)
8908 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8910 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8911 .build());
8912 hasFinePermission =
8913 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8914 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008915
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008916 if (!renounceCoarseLocationAccess) {
8917 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8918 LocationAccessPolicy.checkLocationPermission(mApp,
8919 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8920 .setCallingPackage(callingPackage)
8921 .setCallingFeatureId(callingFeatureId)
8922 .setCallingPid(Binder.getCallingPid())
8923 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008924 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008925 .setLogAsInfo(true)
8926 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8927 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8928 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8929 .build());
8930 hasCoarsePermission =
8931 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8932 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008933
Jordan Liu0f2bc442020-11-18 16:47:37 -08008934 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008936 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8937 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008938 if (subInfo != null && !subInfo.isActive()) {
8939 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008940 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008941 }
8942
Hall Liuf19c44f2018-11-27 14:38:17 -08008943 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008944 boolean isCallingPackageDataService = phone.getDataServicePackages()
8945 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008946
8947 // Scrub out the location info in ServiceState depending on what level of access
8948 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008949 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008950 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8951 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008956
8957 /**
8958 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8959 *
8960 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8961 * voicemail ringtone.
8962 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8963 * PhoneAccount.
8964 */
8965 @Override
8966 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8968 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970 final long identity = Binder.clearCallingIdentity();
8971 try {
8972 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8973 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008974 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8978 } finally {
8979 Binder.restoreCallingIdentity(identity);
8980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008981 }
8982
8983 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008984 * Sets the per-account voicemail ringtone.
8985 *
8986 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8987 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8988 *
8989 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8990 * voicemail ringtone.
8991 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8992 * PhoneAccount.
8993 */
8994 @Override
8995 public void setVoicemailRingtoneUri(String callingPackage,
8996 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008997 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008999 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9000 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9002 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9003 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005
joonhunshin4ac60942023-11-15 15:23:39 +00009006 enforceTelephonyFeatureWithException(callingPackage,
9007 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 }
9015 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009019 }
9020
9021 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009022 * Returns whether vibration is set for voicemail notification in Phone settings.
9023 *
9024 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9025 * voicemail vibration setting.
9026 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9027 */
9028 @Override
9029 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9031 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9036 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009037 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009044 }
9045
Youhan Wange64578a2016-05-02 15:32:42 -07009046 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009047 * Sets the per-account voicemail vibration.
9048 *
9049 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9050 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9051 *
9052 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9053 * voicemail vibration setting.
9054 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9055 * specific PhoneAccount.
9056 */
9057 @Override
9058 public void setVoicemailVibrationEnabled(String callingPackage,
9059 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009060 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009061 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009062 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9063 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9065 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9066 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009067 }
9068
joonhunshin4ac60942023-11-15 15:23:39 +00009069 enforceTelephonyFeatureWithException(callingPackage,
9070 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9075 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009076 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077 }
9078 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009081 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009082 }
9083
9084 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009085 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9086 *
9087 * @throws SecurityException if the caller does not have the required permission
9088 */
arunvoddud7401012022-12-15 16:08:12 +00009089 @VisibleForTesting
9090 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009092 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009093 }
9094
9095 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009096 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9097 * permission.
9098 *
9099 * @throws SecurityException if the caller does not have the required permission
9100 */
9101 private void enforceSendSmsPermission() {
9102 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9103 }
9104
9105 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009106 * Make sure either called from same process as self (phone) or IPC caller has interact across
9107 * users permission.
9108 *
9109 * @throws SecurityException if the caller does not have the required permission
9110 */
9111 private void enforceInteractAcrossUsersPermission(String message) {
9112 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9113 }
9114
9115 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009116 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009117 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009118 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009119 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009120 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009124 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125 if (componentName == null) {
9126 throw new SecurityException(
9127 "Caller not current active visual voicemail package[null]");
9128 }
9129 String vvmPackage = componentName.getPackageName();
9130 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009131 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132 }
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009135 }
9136 }
9137
9138 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009139 * Return the application ID for the app type.
9140 *
9141 * @param subId the subscription ID that this request applies to.
9142 * @param appType the uicc app type.
9143 * @return Application ID for specificied app type, or null if no uicc.
9144 */
9145 @Override
9146 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009147 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009148
9149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9150 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9151
Youhan Wange64578a2016-05-02 15:32:42 -07009152 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153
9154 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009155 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156 if (phone == null) {
9157 return null;
9158 }
9159 String aid = null;
9160 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009161 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009162 .getApplicationByType(appType).getAid();
9163 } catch (Exception e) {
9164 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9165 }
9166 return aid;
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009169 }
Youhan Wange64578a2016-05-02 15:32:42 -07009170 }
9171
Youhan Wang4001d252016-05-11 10:29:41 -07009172 /**
9173 * Return the Electronic Serial Number.
9174 *
9175 * @param subId the subscription ID that this request applies to.
9176 * @return ESN or null if error.
9177 */
9178 @Override
9179 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009180 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009181 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182
9183 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009184 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 if (phone == null) {
9186 return null;
9187 }
9188 String esn = null;
9189 try {
9190 esn = phone.getEsn();
9191 } catch (Exception e) {
9192 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9193 }
9194 return esn;
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009197 }
Youhan Wang4001d252016-05-11 10:29:41 -07009198 }
9199
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009200 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009201 * Return the Preferred Roaming List Version.
9202 *
9203 * @param subId the subscription ID that this request applies to.
9204 * @return PRLVersion or null if error.
9205 */
9206 @Override
9207 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009208 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009209
9210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9211 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9212
Youhan Wang66ad5d72016-07-18 17:56:58 -07009213 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009214
9215 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009216 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009217 if (phone == null) {
9218 return null;
9219 }
9220 String cdmaPrlVersion = null;
9221 try {
9222 cdmaPrlVersion = phone.getCdmaPrlVersion();
9223 } catch (Exception e) {
9224 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9225 }
9226 return cdmaPrlVersion;
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009229 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009230 }
9231
9232 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009233 * Get snapshot of Telephony histograms
9234 * @return List of Telephony histograms
9235 * @hide
9236 */
9237 @Override
9238 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9240 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009241
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 return RIL.getTelephonyRILTimingHistograms();
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009248 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009249
9250 /**
9251 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009252 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9253 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009254 * Require system privileges. In the future we may add this to carrier APIs.
9255 *
Michele Berionne482f8202018-11-27 18:57:59 -08009256 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009257 */
9258 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009259 @TelephonyManager.SetCarrierRestrictionResult
9260 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009261 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009262
9263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9264 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9265
vagdeviaf9a5b92018-08-15 16:01:53 -07009266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009267
Michele Berionne482f8202018-11-27 18:57:59 -08009268 if (carrierRestrictionRules == null) {
9269 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009270 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009272 final long identity = Binder.clearCallingIdentity();
9273 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009274 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009275 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009279 }
9280
9281 /**
9282 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009283 * Get the allowed carrier list and the excluded carrier list, including the priority between
9284 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009285 * Require system privileges. In the future we may add this to carrier APIs.
9286 *
Michele Berionne482f8202018-11-27 18:57:59 -08009287 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009288 */
9289 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009290 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009291 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009292
9293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9294 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9295
vagdeviaf9a5b92018-08-15 16:01:53 -07009296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009297
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009300 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9301 if (response instanceof CarrierRestrictionRules) {
9302 return (CarrierRestrictionRules) response;
9303 }
9304 // Response is an Exception of some kind,
9305 // which is signalled to the user as a NULL retval
9306 return null;
9307 } catch (Exception e) {
9308 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9309 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009313 }
9314
fionaxu59545b42016-05-25 15:53:37 -07009315 /**
arunvoddud7401012022-12-15 16:08:12 +00009316 * Fetches the carrier restriction status of the device and sends the status to the caller
9317 * through the callback.
9318 *
9319 * @param callback The callback that will be used to send the result.
9320 * @throws SecurityException if the caller does not have the required permission/privileges or
9321 * the caller is not allowlisted.
9322 */
9323 @Override
9324 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009325 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009326 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009327 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9328 try {
9329 mApp.enforceCallingOrSelfPermission(
9330 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9331 functionName);
9332 } catch (SecurityException e) {
9333 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9334 functionName);
9335 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009336 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9337 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009338 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9339 throw new SecurityException("Not an authorized caller");
9340 }
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009344 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009345 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 }
9350
arunvoddu567f2b42023-04-25 17:22:00 +00009351 @Override
9352 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9353 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9354 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9355 return allowListInfo.getShaIdList(pkgName, carrierId);
9356 }
9357
arunvoddud7401012022-12-15 16:08:12 +00009358 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009359 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009360 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009361 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009362 }
9363
9364 /**
fionaxu59545b42016-05-25 15:53:37 -07009365 * Action set from carrier signalling broadcast receivers to enable/disable radio
9366 * @param subId the subscription ID that this action applies to.
9367 * @param enabled control enable or disable radio.
9368 * {@hide}
9369 */
9370 @Override
9371 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9372 enforceModifyPermission();
9373 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009374
9375 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009376 if (phone == null) {
9377 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9378 return;
9379 }
9380 try {
9381 phone.carrierActionSetRadioEnabled(enabled);
9382 } catch (Exception e) {
9383 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009384 } finally {
9385 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009386 }
9387 }
9388
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009389 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009390 * Enable or disable Voice over NR (VoNR)
9391 * @param subId the subscription ID that this action applies to.
9392 * @param enabled enable or disable VoNR.
9393 * @return operation result.
9394 */
9395 @Override
9396 public int setVoNrEnabled(int subId, boolean enabled) {
9397 enforceModifyPermission();
9398 final Phone phone = getPhone(subId);
9399
9400 final long identity = Binder.clearCallingIdentity();
9401 if (phone == null) {
9402 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9403 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9404 }
9405
9406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9407 try {
9408 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9409 workSource);
9410 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009411
9412 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9413 if (DBG) {
9414 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9415 }
9416 SubscriptionManager.setSubscriptionProperty(
9417 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9418 (enabled ? "1" : "0"));
9419 }
9420
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009421 return result;
9422 } finally {
9423 Binder.restoreCallingIdentity(identity);
9424 }
9425 }
9426
9427 /**
9428 * Is voice over NR enabled
9429 * @return true if VoNR is enabled else false
9430 */
9431 @Override
9432 public boolean isVoNrEnabled(int subId) {
9433 enforceReadPrivilegedPermission("isVoNrEnabled");
9434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
9437 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9438 null, subId, workSource);
9439 if (DBG) log("isVoNrEnabled: " + isEnabled);
9440 return isEnabled;
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 }
9445
9446 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009447 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9448 * network status based on which carrier apps could apply actions accordingly,
9449 * enable/disable default url handler for example.
9450 *
9451 * @param subId the subscription ID that this action applies to.
9452 * @param report control start/stop reporting the default network status.
9453 * {@hide}
9454 */
9455 @Override
9456 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9457 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009458
9459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9460 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9461 "carrierActionReportDefaultNetworkStatus");
9462
fionaxu8da9cb12017-05-23 15:02:46 -07009463 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009464
9465 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009466 if (phone == null) {
9467 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9468 return;
9469 }
9470 try {
9471 phone.carrierActionReportDefaultNetworkStatus(report);
9472 } catch (Exception e) {
9473 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009474 } finally {
9475 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009476 }
9477 }
9478
9479 /**
fionaxud9622282017-07-17 17:51:30 -07009480 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9481 * @param subId the subscription ID that this action applies to.
9482 * {@hide}
9483 */
9484 @Override
9485 public void carrierActionResetAll(int subId) {
9486 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009487
9488 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9489 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9490
fionaxud9622282017-07-17 17:51:30 -07009491 final Phone phone = getPhone(subId);
9492 if (phone == null) {
9493 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9494 return;
9495 }
9496 try {
9497 phone.carrierActionResetAll();
9498 } catch (Exception e) {
9499 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9500 }
9501 }
9502
9503 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009504 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9505 * bug report is being generated.
9506 */
9507 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009508 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009509 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9510 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009511 writer.println("Permission Denial: can't dump Phone from pid="
9512 + Binder.getCallingPid()
9513 + ", uid=" + Binder.getCallingUid()
9514 + "without permission "
9515 + android.Manifest.permission.DUMP);
9516 return;
9517 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009518 try {
9519 DumpsysHandler.dump(mApp, fd, writer, args);
9520 } catch (Exception e) {
9521 writer.println("Failed to dump phone information: " + e);
9522 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009523 }
Jack Yueb89b242016-06-22 13:27:47 -07009524
Brad Ebingerdac2f002018-04-03 15:17:52 -07009525 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009526 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9527 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9528 @NonNull String[] args) {
9529 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9530 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009531 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009532 }
9533
Jack Yueb89b242016-06-22 13:27:47 -07009534 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009535 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009536 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009537 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009538 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009539 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009540 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009541 */
9542 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009543 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009544 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009545 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9546 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9547 try {
9548 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009549 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009550 } catch (SecurityException se) {
9551 enforceModifyPermission();
9552 }
9553 } else {
9554 enforceModifyPermission();
9555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009556
joonhunshin4ac60942023-11-15 15:23:39 +00009557 enforceTelephonyFeatureWithException(callingPackage,
9558 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9559
Nate Myren116695d2024-02-09 09:36:01 -08009560 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009561 final long identity = Binder.clearCallingIdentity();
9562 try {
Nate Myren116695d2024-02-09 09:36:01 -08009563 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9564 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009565 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009566 callingUid, callingPackage, null, null);
9567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009568 Phone phone = getPhone(subId);
9569 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009570 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9571 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009572 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009573 phone.getDataSettingsManager().setDataEnabled(
9574 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009576 }
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009579 }
9580 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009581
9582 /**
9583 * Get Client request stats
9584 * @return List of Client Request Stats
9585 * @hide
9586 */
9587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009588 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9589 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009591 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009592 return null;
9593 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009594 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 if (phone != null) {
9599 return phone.getClientRequestStats();
9600 }
9601
9602 return null;
9603 } finally {
9604 Binder.restoreCallingIdentity(identity);
9605 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009606 }
9607
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009608 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009609 PackageManager pm;
9610 if (mFeatureFlags.hsumPackageManager()) {
9611 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9612 .getPackageManager();
9613 } else {
9614 pm = mApp.getPackageManager();
9615 }
9616
9617 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009618 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009619 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9620 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9621 // exception. ROOT_UID seems not to have a valid package name returned by
9622 // PackageManager, so just fake it here to avoid issues when running telephony shell
9623 // commands that plumb through the RIL as root, like so:
9624 // $ adb root
9625 // $ adb shell cmd phone ...
9626 packageName = "root";
9627 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009628 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009629 }
Jack Yueb4124c2017-02-16 15:32:43 -08009630
9631 /**
Grace Chen70990072017-03-24 17:21:30 -07009632 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009633 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009634 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009635 * @param state State of SIM (power down, power up, pass through)
9636 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9637 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9638 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009639 *
9640 **/
9641 @Override
Grace Chen70990072017-03-24 17:21:30 -07009642 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009643 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009644
9645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9646 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9647
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009648 Phone phone = PhoneFactory.getPhone(slotIndex);
9649
vagdeviaf9a5b92018-08-15 16:01:53 -07009650 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009652 final long identity = Binder.clearCallingIdentity();
9653 try {
9654 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009655 phone.setSimPowerState(state, null, workSource);
9656 }
9657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
9660 }
9661
9662 /**
9663 * Set SIM card power state.
9664 *
9665 * @param slotIndex SIM slot id.
9666 * @param state State of SIM (power down, power up, pass through)
9667 * @param callback callback to trigger after success or failure
9668 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9669 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9670 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9671 *
9672 **/
9673 @Override
9674 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9675 IIntegerConsumer callback) {
9676 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009677
9678 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9679 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9680 "setSimPowerStateForSlotWithCallback");
9681
Jordan Liu109698e2020-11-24 14:50:34 -08009682 Phone phone = PhoneFactory.getPhone(slotIndex);
9683
9684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9685
9686 final long identity = Binder.clearCallingIdentity();
9687 try {
9688 if (phone != null) {
9689 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9690 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009691 }
9692 } finally {
9693 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009694 }
9695 }
Shuo Qiandd210312017-04-12 22:11:33 +00009696
Tyler Gunn65d45c22017-06-05 11:22:26 -07009697 private boolean isUssdApiAllowed(int subId) {
9698 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009699 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009700 if (configManager == null) {
9701 return false;
9702 }
9703 PersistableBundle pb = configManager.getConfigForSubId(subId);
9704 if (pb == null) {
9705 return false;
9706 }
9707 return pb.getBoolean(
9708 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9709 }
9710
Shuo Qiandd210312017-04-12 22:11:33 +00009711 /**
Ling Mac28f0212023-03-24 16:07:15 -07009712 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009713 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009714 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009715 */
goneil9c5f4872017-12-05 14:07:56 -08009716 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009717 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009718 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009719
9720 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9721 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009723 final long identity = Binder.clearCallingIdentity();
9724 try {
Ling Mac28f0212023-03-24 16:07:15 -07009725 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009726 } finally {
9727 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009728 }
9729 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009730
9731 /**
9732 * Get the current signal strength information for the given subscription.
9733 * Because this information is not updated when the device is in a low power state
9734 * it should not be relied-upon to be current.
9735 * @param subId Subscription index
9736 * @return the most recent cached signal strength info from the modem
9737 */
9738 @Override
9739 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9741 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009743 final long identity = Binder.clearCallingIdentity();
9744 try {
9745 Phone p = getPhone(subId);
9746 if (p == null) {
9747 return null;
9748 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009750 return p.getSignalStrength();
9751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009754 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009755
Pengquan Meng77b7f132018-08-22 14:49:57 -07009756 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009757 * Get the current modem radio state for the given slot.
9758 * @param slotIndex slot index.
9759 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009760 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009761 * @return the current radio power state from the modem
9762 */
9763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009764 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009765 Phone phone = PhoneFactory.getPhone(slotIndex);
9766 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9768 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009769 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9770 }
9771
joonhunshin4ac60942023-11-15 15:23:39 +00009772 enforceTelephonyFeatureWithException(callingPackage,
9773 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9774
Chen Xuf792fd62018-10-17 17:54:36 +00009775 final long identity = Binder.clearCallingIdentity();
9776 try {
9777 return phone.getRadioPowerState();
9778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9783 }
9784
9785 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009786 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9787 *
9788 * <p>Requires one of the following permissions:
9789 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009790 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009791 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9792 * privileges.
9793 *
9794 * @param subId subscription id
9795 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9796 * {@code false}.
9797 */
9798 @Override
9799 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009800 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009801 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009802 try {
9803 mApp.enforceCallingOrSelfPermission(
9804 android.Manifest.permission.ACCESS_NETWORK_STATE,
9805 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009806 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009807 mApp.enforceCallingOrSelfPermission(
9808 permission.READ_BASIC_PHONE_STATE, functionName);
9809 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009810 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009811 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009812 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009813 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009814
joonhunshin4ac60942023-11-15 15:23:39 +00009815 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9816 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9817
Pengquan Menga1bb6272018-09-06 09:59:22 -07009818 boolean isEnabled = false;
9819 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009820 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009821 Phone phone = getPhone(subId);
9822 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009823 } finally {
9824 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009825 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009826 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009827 }
9828
9829
9830 /**
9831 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9832 *
9833 * <p> Requires permission:
9834 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9835 * privileges.
9836 *
9837 * @param subId subscription id
9838 * @param isEnabled {@code true} means enable, {@code false} means disable.
9839 */
9840 @Override
9841 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9843 mApp, subId, "setDataRoamingEnabled");
9844
joonhunshin4ac60942023-11-15 15:23:39 +00009845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9846 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9847
Pengquan Menga1bb6272018-09-06 09:59:22 -07009848 final long identity = Binder.clearCallingIdentity();
9849 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009850 Phone phone = getPhone(subId);
9851 if (phone != null) {
9852 phone.setDataRoamingEnabled(isEnabled);
9853 }
9854 } finally {
9855 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009856 }
9857 }
9858
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009859 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009860 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009861 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009862 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009863 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009864
joonhunshin4ac60942023-11-15 15:23:39 +00009865 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9866 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9867
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009868 boolean isAllowed = true;
9869 final long identity = Binder.clearCallingIdentity();
9870 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009871 Phone phone = getPhone(subId);
9872 if (phone != null) {
9873 isAllowed = phone.isCspPlmnEnabled();
9874 }
9875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 return isAllowed;
9879 }
9880
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009881 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9882 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009883 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009884 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009885 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009886 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9887 if (phone == null) {
9888 return false;
9889 }
9890 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9891 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9892 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009893 }
9894
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009895 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009896 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009897 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009898 mApp.getSystemService(AppOpsManager.class)
9899 .checkPackage(Binder.getCallingUid(), callingPackage);
9900
Jordan Liu1e142fc2019-04-22 15:10:43 -07009901 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009902 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009903 try {
9904 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009905 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009906 } catch (SecurityException e) {
9907 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9908 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009909 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009910 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009911 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009912 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009913 }
joonhunshin4ac60942023-11-15 15:23:39 +00009914
9915 enforceTelephonyFeatureWithException(callingPackage,
9916 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9917
sandeepjsb6c87872021-09-27 15:34:44 +00009918 // checking compatibility, if calling app's target SDK is T and beyond.
9919 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9920 Binder.getCallingUid())) {
9921 isIccIdAccessRestricted = true;
9922 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009923 final long identity = Binder.clearCallingIdentity();
9924 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009925 UiccController uiccController = UiccController.getInstance();
9926 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009927 if (hasReadPermission) {
9928 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009929 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009930
9931 // Remove private info if the caller doesn't have access
9932 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9933 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009934 //setting the value after compatibility check
9935 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009936 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9937 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009938 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009939 if (card == null) {
9940 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009941 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009942 continue;
9943 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009944 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9945 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009946 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009947 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009948 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009949 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9950 for (UiccPortInfo portInfo : portInfos) {
9951 UiccPort port = uiccController.getUiccPortForSlot(
9952 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9953 if (port == null) {
9954 // assume no access if port is null
9955 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9956 continue;
9957 }
9958 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9959 uiccPortInfos.add(portInfo);
9960 } else {
9961 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9962 }
9963 }
9964 filteredInfos.add(new UiccCardInfo(
9965 cardInfo.isEuicc(),
9966 cardInfo.getCardId(),
9967 null,
9968 cardInfo.getPhysicalSlotIndex(),
9969 cardInfo.isRemovable(),
9970 cardInfo.isMultipleEnabledProfilesSupported(),
9971 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009972 }
9973 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009974 } finally {
9975 Binder.restoreCallingIdentity(identity);
9976 }
9977 }
9978
sandeepjsb6c87872021-09-27 15:34:44 +00009979 /**
9980 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9981 * generally private and require carrier privileges to view.
9982 *
9983 * @hide
9984 */
9985 @NonNull
9986 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9987 List<UiccPortInfo> portinfo = new ArrayList<>();
9988 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9989 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9990 }
9991 return new UiccCardInfo(
9992 cardInfo.isEuicc(),
9993 cardInfo.getCardId(),
9994 null,
9995 cardInfo.getPhysicalSlotIndex(),
9996 cardInfo.isRemovable(),
9997 cardInfo.isMultipleEnabledProfilesSupported(),
9998 portinfo
9999 );
10000 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010001
sandeepjsb6c87872021-09-27 15:34:44 +000010002 /**
10003 * @hide
10004 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10005 * These values are generally private and require carrier privileges to view.
10006 */
10007 @NonNull
10008 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10009 return new UiccPortInfo(
10010 UiccPortInfo.ICCID_REDACTED,
10011 portInfo.getPortIndex(),
10012 portInfo.getLogicalSlotIndex(),
10013 portInfo.isActive()
10014 );
10015 }
10016 @Override
10017 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010018 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010019 mApp.getSystemService(AppOpsManager.class)
10020 .checkPackage(Binder.getCallingUid(), callingPackage);
10021
sandeepjsb6c87872021-09-27 15:34:44 +000010022 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010023
Aman Guptaf3c90b32022-03-17 04:54:16 +000010024 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10025 // we are reading iccId which is PII data.
10026 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010027
joonhunshin4ac60942023-11-15 15:23:39 +000010028 enforceTelephonyFeatureWithException(callingPackage,
10029 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10030
sandeepjsb6c87872021-09-27 15:34:44 +000010031 // checking compatibility, if calling app's target SDK is T and beyond.
10032 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10033 Binder.getCallingUid())) {
10034 isLogicalSlotAccessRestricted = true;
10035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010039 if (slots == null || slots.length == 0) {
10040 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010041 return null;
10042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010043 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10044 for (int i = 0; i < slots.length; i++) {
10045 UiccSlot slot = slots[i];
10046 if (slot == null) {
10047 continue;
10048 }
10049
Jordan Liu7be7e652019-05-06 18:55:02 +000010050 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010051 UiccCard card = slot.getUiccCard();
10052 if (card != null) {
10053 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010054 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010055 cardId = slot.getEid();
10056 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010057 // If cardId is null, use iccId of default port as cardId.
10058 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010060 }
10061
Jordan Liu857451f2019-05-09 16:35:35 -070010062 if (cardId != null) {
10063 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10064 // if cardId is an EID, it's all digits so this is fine
10065 cardId = IccUtils.stripTrailingFs(cardId);
10066 }
10067
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010068 int cardState = 0;
10069 switch (slot.getCardState()) {
10070 case CARDSTATE_ABSENT:
10071 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10072 break;
10073 case CARDSTATE_PRESENT:
10074 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10075 break;
10076 case CARDSTATE_ERROR:
10077 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10078 break;
10079 case CARDSTATE_RESTRICTED:
10080 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10081 break;
10082 default:
10083 break;
10084
10085 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010086 List<UiccPortInfo> portInfos = new ArrayList<>();
10087 int[] portIndexes = slot.getPortList();
10088 for (int portIdx : portIndexes) {
10089 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010090 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010091 portInfos.add(new UiccPortInfo(iccId, portIdx,
10092 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010094 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010095 slot.isEuicc(),
10096 cardId,
10097 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010098 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010099 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010100 //setting the value after compatibility check
10101 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010102 }
10103 return infos;
10104 } finally {
10105 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010106 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010107 }
10108
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010109 /* Returns null if doesn't have read permission or carrier privilege access. */
10110 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10111 boolean hasReadPermission) {
10112 String iccId = slot.getIccId(portIndex);
10113 if (hasReadPermission) { // if has read permission
10114 return iccId;
10115 } else {
10116 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10117 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10118 // if no read permission, checking carrier privilege access
10119 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10120 return iccId;
10121 }
10122 }
10123 }
10124 // No read permission or carrier privilege access.
10125 return UiccPortInfo.ICCID_REDACTED;
10126 }
10127
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010128 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010129 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010130 public boolean switchSlots(int[] physicalSlots) {
10131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010132
joonhunshin4ac60942023-11-15 15:23:39 +000010133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10134 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10135
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010136 final long identity = Binder.clearCallingIdentity();
10137 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010138 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10139 for (int i = 0; i < physicalSlots.length; i++) {
10140 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10141 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10142 physicalSlots[i], i));
10143 }
10144 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010145 } finally {
10146 Binder.restoreCallingIdentity(identity);
10147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010148 }
Jack Yu4c988042018-02-27 15:30:01 -080010149
10150 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010151 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10152 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10153 enforceModifyPermission();
10154
joonhunshin4ac60942023-11-15 15:23:39 +000010155 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10156 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10157
sandeepjsb6c87872021-09-27 15:34:44 +000010158 final long identity = Binder.clearCallingIdentity();
10159 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010160 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164 }
10165
10166 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010167 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010168 enforceTelephonyFeatureWithException(callingPackage,
10169 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10170
Jordan Liu7de49fa2018-12-06 14:48:49 -080010171 final long identity = Binder.clearCallingIdentity();
10172 try {
10173 return UiccController.getInstance().getCardIdForDefaultEuicc();
10174 } finally {
10175 Binder.restoreCallingIdentity(identity);
10176 }
10177 }
10178
Pengquan Meng85728fb2018-03-12 16:31:21 -070010179 /**
goneil47ffb6e2018-04-06 15:40:58 -070010180 * A test API to reload the UICC profile.
10181 *
10182 * <p>Requires that the calling app has permission
10183 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10184 * @hide
10185 */
10186 @Override
10187 public void refreshUiccProfile(int subId) {
10188 enforceModifyPermission();
10189
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 Phone phone = getPhone(subId);
10193 if (phone == null) {
10194 return;
10195 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010196 UiccPort uiccPort = phone.getUiccPort();
10197 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010198 return;
10199 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010200 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010201 if (uiccProfile == null) {
10202 return;
10203 }
10204 uiccProfile.refresh();
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
10209
10210 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010211 * Returns false if the mobile data is disabled by default, otherwise return true.
10212 */
10213 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010214 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010215 }
10216
10217 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010218 * Returns the default network type for the given {@code subId}, if the default network type is
10219 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10220 */
10221 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010222 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010223 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010224 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10225 return list.get(phoneId);
10226 }
10227 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010228 }
fionaxua13278b2018-03-21 00:08:13 -070010229
10230 @Override
10231 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010232 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010233 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010234
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 final Phone phone = getPhone(subId);
10238 if (phone == null) {
10239 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10240 return;
10241 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010242 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10243 if (cpt != null) {
10244 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10245 }
10246 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010247 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10248 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010249 if (carrierPrivilegeRules == null) {
10250 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10251 } else {
10252 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010254 } finally {
10255 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010256 }
fionaxua13278b2018-03-21 00:08:13 -070010257 }
10258
10259 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010260 public void setCarrierServicePackageOverride(
10261 int subId, String carrierServicePackage, String callingPackage) {
10262 TelephonyPermissions.enforceShellOnly(
10263 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10264
Benedict Wong66477622023-02-03 23:30:57 +000010265 final long identity = Binder.clearCallingIdentity();
10266 try {
10267 final Phone phone = getPhone(subId);
10268 if (phone == null || phone.getSubId() != subId) {
10269 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10270 throw new IllegalArgumentException("No phone for subid");
10271 }
10272 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10273 if (cpt == null) {
10274 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10275 throw new IllegalStateException("No CPT for phone");
10276 }
10277 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10278 } finally {
10279 Binder.restoreCallingIdentity(identity);
10280 }
10281 }
10282
10283 @Override
fionaxua13278b2018-03-21 00:08:13 -070010284 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010285 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010286
10287 final long identity = Binder.clearCallingIdentity();
10288 try {
10289 final Phone phone = getPhone(subId);
10290 if (phone == null) {
10291 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10292 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10293 }
10294 return phone.getCarrierIdListVersion();
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010297 }
fionaxua13278b2018-03-21 00:08:13 -070010298 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010299
10300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010301 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10302 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010304 mApp, subId, callingPackage, callingFeatureId,
10305 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010306 return -1;
10307 }
10308
10309 final long identity = Binder.clearCallingIdentity();
10310 try {
10311 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10312 } finally {
10313 Binder.restoreCallingIdentity(identity);
10314 }
10315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010316
10317 @Override
10318 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010321 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010322
joonhunshin4ac60942023-11-15 15:23:39 +000010323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10324 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10325
Pengquan Menga1bb6272018-09-06 09:59:22 -070010326 final long identity = Binder.clearCallingIdentity();
10327 try {
10328 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
10333
10334 @Override
10335 public boolean setCdmaRoamingMode(int subId, int mode) {
10336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10337 mApp, subId, "setCdmaRoamingMode");
10338
joonhunshin4ac60942023-11-15 15:23:39 +000010339 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10340 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10341
Pengquan Menga1bb6272018-09-06 09:59:22 -070010342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348 }
10349
10350 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010351 public int getCdmaSubscriptionMode(int subId) {
10352 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010353 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010354 mApp, subId, "getCdmaSubscriptionMode");
10355
joonhunshin4ac60942023-11-15 15:23:39 +000010356 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10357 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10358
Sarah Chinbaab1432020-10-28 13:46:24 -070010359 final long identity = Binder.clearCallingIdentity();
10360 try {
10361 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10362 } finally {
10363 Binder.restoreCallingIdentity(identity);
10364 }
10365 }
10366
10367 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010368 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10370 mApp, subId, "setCdmaSubscriptionMode");
10371
joonhunshin4ac60942023-11-15 15:23:39 +000010372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10373 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10374
Pengquan Menga1bb6272018-09-06 09:59:22 -070010375 final long identity = Binder.clearCallingIdentity();
10376 try {
10377 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10378 } finally {
10379 Binder.restoreCallingIdentity(identity);
10380 }
10381 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010382
sqianc5eccab2018-10-19 18:46:41 -070010383 @Override
sqian8c685422019-02-22 15:55:18 -080010384 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010385 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010387 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10388 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010389 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10390 }
joonhunshin4ac60942023-11-15 15:23:39 +000010391
10392 enforceTelephonyFeatureWithException(callingPackage,
10393 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10394
sqian11b7a0e2018-12-05 18:48:28 -080010395 final long identity = Binder.clearCallingIdentity();
10396 try {
sqian854d44b2018-12-12 16:48:18 -080010397 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10398 for (Phone phone: PhoneFactory.getPhones()) {
10399 if (phone.getEmergencyNumberTracker() != null
10400 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10401 emergencyNumberListInternal.put(
10402 phone.getSubId(),
10403 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10404 }
sqian11b7a0e2018-12-05 18:48:28 -080010405 }
sqian854d44b2018-12-12 16:48:18 -080010406 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
sqianc5eccab2018-10-19 18:46:41 -070010410 }
10411
10412 @Override
sqian8c685422019-02-22 15:55:18 -080010413 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010414 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010415 if (!exactMatch) {
10416 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010417 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010418 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010419 }
joonhunshin4ac60942023-11-15 15:23:39 +000010420
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010421 if (!mApp.getResources().getBoolean(
10422 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10424 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10425 }
joonhunshin4ac60942023-11-15 15:23:39 +000010426
sqian11b7a0e2018-12-05 18:48:28 -080010427 final long identity = Binder.clearCallingIdentity();
10428 try {
sqian854d44b2018-12-12 16:48:18 -080010429 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010430 //Note: we ignore passed in param exactMatch. We can remove it once
10431 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010432 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010433 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010434 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010435 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010436 }
sqian11b7a0e2018-12-05 18:48:28 -080010437 }
10438 return false;
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
sqianf4ca7ed2019-01-15 18:32:07 -080010444 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010445 * Start emergency callback mode for GsmCdmaPhone for testing.
10446 */
10447 @Override
10448 public void startEmergencyCallbackMode() {
10449 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10450 "startEmergencyCallbackMode");
10451 enforceModifyPermission();
10452 final long identity = Binder.clearCallingIdentity();
10453 try {
10454 for (Phone phone : PhoneFactory.getPhones()) {
10455 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10456 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10457 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10458 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10459 gsmCdmaPhone.obtainMessage(
10460 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10461 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10462 }
10463 }
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
10469 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010470 * Update emergency number list for test mode.
10471 */
10472 @Override
10473 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10474 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10475 "updateEmergencyNumberListTestMode");
10476
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 for (Phone phone: PhoneFactory.getPhones()) {
10480 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10481 if (tracker != null) {
10482 tracker.executeEmergencyNumberTestModeCommand(action, num);
10483 }
10484 }
10485 } finally {
10486 Binder.restoreCallingIdentity(identity);
10487 }
10488 }
10489
10490 /**
10491 * Get the full emergency number list for test mode.
10492 */
10493 @Override
10494 public List<String> getEmergencyNumberListTestMode() {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10496 "getEmergencyNumberListTestMode");
10497
10498 final long identity = Binder.clearCallingIdentity();
10499 try {
10500 Set<String> emergencyNumbers = new HashSet<>();
10501 for (Phone phone: PhoneFactory.getPhones()) {
10502 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10503 if (tracker != null) {
10504 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10505 emergencyNumbers.add(num.getNumber());
10506 }
10507 }
10508 }
10509 return new ArrayList<>(emergencyNumbers);
10510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 }
10514
chen xud6b45bd2018-10-30 22:27:10 -070010515 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010516 public int getEmergencyNumberDbVersion(int subId) {
10517 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10518
joonhunshin4ac60942023-11-15 15:23:39 +000010519 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10520 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10521
Shuo Qian3b6ee772019-11-13 17:43:31 -080010522 final long identity = Binder.clearCallingIdentity();
10523 try {
10524 final Phone phone = getPhone(subId);
10525 if (phone == null) {
10526 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10527 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10528 }
10529 return phone.getEmergencyNumberDbVersion();
10530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
10534
10535 @Override
10536 public void notifyOtaEmergencyNumberDbInstalled() {
10537 enforceModifyPermission();
10538
joonhunshin4ac60942023-11-15 15:23:39 +000010539 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10540 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10541
Shuo Qian3b6ee772019-11-13 17:43:31 -080010542 final long identity = Binder.clearCallingIdentity();
10543 try {
10544 for (Phone phone: PhoneFactory.getPhones()) {
10545 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10546 if (tracker != null) {
10547 tracker.updateOtaEmergencyNumberDatabase();
10548 }
10549 }
10550 } finally {
10551 Binder.restoreCallingIdentity(identity);
10552 }
10553 }
10554
10555 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010556 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010557 enforceActiveEmergencySessionPermission();
10558
joonhunshin4ac60942023-11-15 15:23:39 +000010559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10560 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10561
Shuo Qian3b6ee772019-11-13 17:43:31 -080010562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 for (Phone phone: PhoneFactory.getPhones()) {
10565 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10566 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010567 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10568 }
10569 }
10570 } finally {
10571 Binder.restoreCallingIdentity(identity);
10572 }
10573 }
10574
10575 @Override
10576 public void resetOtaEmergencyNumberDbFilePath() {
10577 enforceActiveEmergencySessionPermission();
10578
joonhunshin4ac60942023-11-15 15:23:39 +000010579 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10580 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10581
Shuo Qianc373f112020-03-05 17:55:34 -080010582 final long identity = Binder.clearCallingIdentity();
10583 try {
10584 for (Phone phone: PhoneFactory.getPhones()) {
10585 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10586 if (tracker != null) {
10587 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010588 }
10589 }
10590 } finally {
10591 Binder.restoreCallingIdentity(identity);
10592 }
10593 }
10594
10595 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010596 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10597 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10598 Phone phone = getPhone(subId);
10599 if (phone == null) {
10600 return null;
10601 }
10602 final long identity = Binder.clearCallingIdentity();
10603 try {
10604 UiccProfile profile = UiccController.getInstance()
10605 .getUiccProfileForPhone(phone.getPhoneId());
10606 if (profile != null) {
10607 return profile.getCertsFromCarrierPrivilegeAccessRules();
10608 }
10609 } finally {
10610 Binder.restoreCallingIdentity(identity);
10611 }
10612 return null;
10613 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010614
10615 /**
10616 * Enable or disable a modem stack.
10617 */
10618 @Override
10619 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10620 enforceModifyPermission();
10621
joonhunshin4ac60942023-11-15 15:23:39 +000010622 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10623 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10624
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010625 final long identity = Binder.clearCallingIdentity();
10626 try {
10627 Phone phone = PhoneFactory.getPhone(slotIndex);
10628 if (phone == null) {
10629 return false;
10630 } else {
10631 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10632 }
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
Michelecea4cf22018-12-21 15:00:11 -080010637
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010638 /**
10639 * Whether a modem stack is enabled or not.
10640 */
10641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010642 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10643 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010644 Phone phone = PhoneFactory.getPhone(slotIndex);
10645 if (phone == null) return false;
10646
10647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010648 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10649 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010650 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10651 }
10652
joonhunshin4ac60942023-11-15 15:23:39 +000010653 enforceTelephonyFeatureWithException(callingPackage,
10654 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10655
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010656 final long identity = Binder.clearCallingIdentity();
10657 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010658 try {
10659 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10660 } catch (NoSuchElementException ex) {
10661 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10662 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
Michelecea4cf22018-12-21 15:00:11 -080010668 @Override
Michele0ea7d782019-03-19 14:58:42 -070010669 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010670 enforceModifyPermission();
10671
joonhunshin4ac60942023-11-15 15:23:39 +000010672 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10673 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10674
Michelecea4cf22018-12-21 15:00:11 -080010675 final long identity = Binder.clearCallingIdentity();
10676 try {
10677 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010678 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010679 .commit();
10680 } finally {
10681 Binder.restoreCallingIdentity(identity);
10682 }
10683 }
10684
10685 @Override
Michele0ea7d782019-03-19 14:58:42 -070010686 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010687 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010689 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10690 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010691 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010692 }
Michelecea4cf22018-12-21 15:00:11 -080010693
joonhunshin4ac60942023-11-15 15:23:39 +000010694 enforceTelephonyFeatureWithException(callingPackage,
10695 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10696
Michelecea4cf22018-12-21 15:00:11 -080010697 final long identity = Binder.clearCallingIdentity();
10698 try {
Michele0ea7d782019-03-19 14:58:42 -070010699 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010700 } finally {
10701 Binder.restoreCallingIdentity(identity);
10702 }
10703 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010704
Michele0ea7d782019-03-19 14:58:42 -070010705 @TelephonyManager.IsMultiSimSupportedResult
10706 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010707 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10708 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10709 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010710 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10711 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010712 }
10713 // Check if the hardware supports multisim functionality. If usage of multisim is not
10714 // supported by the modem, indicate that it is restricted.
10715 PhoneCapability staticCapability =
10716 mPhoneConfigurationManager.getStaticPhoneCapability();
10717 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010718 loge("isMultiSimSupportedInternal: no static configuration available");
10719 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010720 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010721 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010722 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10723 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010724 }
10725 // Check if support of multiple SIMs is restricted by carrier
10726 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010727 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010728 }
10729
Michele0ea7d782019-03-19 14:58:42 -070010730 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010731 }
10732
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010733 /**
10734 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010735 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10736 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10737 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010738 * @param numOfSims number of active sims we want to switch to
10739 */
10740 @Override
10741 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010742 if (numOfSims == 1) {
10743 enforceModifyPermission();
10744 } else {
10745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10746 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10747 }
joonhunshin4ac60942023-11-15 15:23:39 +000010748
10749 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10750 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10751
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010752 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010753
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010754 try {
Michele30b57b22019-03-01 12:01:14 -080010755 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010756 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010757 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10758 return;
10759 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010760 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010766 @Override
10767 public boolean isApplicationOnUicc(int subId, int appType) {
10768 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010769
10770 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10771 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10772
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010773 Phone phone = getPhone(subId);
10774 if (phone == null) {
10775 return false;
10776 }
10777 final long identity = Binder.clearCallingIdentity();
10778 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010779 UiccPort uiccPort = phone.getUiccPort();
10780 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010781 return false;
10782 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010783 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010784 if (uiccProfile == null) {
10785 return false;
10786 }
10787 if (TelephonyManager.APPTYPE_SIM <= appType
10788 && appType <= TelephonyManager.APPTYPE_ISIM) {
10789 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10790 }
10791 return false;
10792 } finally {
10793 Binder.restoreCallingIdentity(identity);
10794 }
10795 }
10796
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010797 /**
chen xub4baa772019-04-03 10:23:41 -070010798 * Get whether making changes to modem configurations will trigger reboot.
10799 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010800 */
10801 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010802 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10803 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010805 mApp, subId, callingPackage, callingFeatureId,
10806 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010807 return false;
10808 }
joonhunshin4ac60942023-11-15 15:23:39 +000010809
10810 enforceTelephonyFeatureWithException(callingPackage,
10811 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10812 "doesSwitchMultiSimConfigTriggerReboot");
10813
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010814 final long identity = Binder.clearCallingIdentity();
10815 try {
10816 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
10821
Nathan Harold29f5f052019-02-15 13:41:57 -080010822 private void updateModemStateMetrics() {
10823 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10824 // TODO: check the state for each modem if the api is ready.
10825 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10826 }
10827
Pengquan Meng3889a572019-01-23 11:16:29 -080010828 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010829 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010830 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010831 // Verify that the callingPackage belongs to the calling UID
10832 mApp.getSystemService(AppOpsManager.class)
10833 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010834
10835 enforceTelephonyFeatureWithException(callingPackage,
10836 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10837
Pengquan Meng3889a572019-01-23 11:16:29 -080010838 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010839 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010840 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010841 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10842 if (slotInfos != null) {
10843 for (int i = 0; i < slotInfos.length; i++) {
10844 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10845 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10846 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10847 portInfo.getLogicalSlotIndex()));
10848 }
10849 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010850 }
10851 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010852 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010857
10858 /**
10859 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010860 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010861 */
jimsunf9ec1622022-09-13 21:18:43 +080010862 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010863 @Override
10864 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010865 return getHalVersion(HAL_SERVICE_RADIO);
10866 }
10867
10868 /**
10869 * Get the HAL Version of a specific service
10870 */
10871 @Override
10872 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010873 Phone phone = getDefaultPhone();
10874 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010875 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010876 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10877 return hv.major * 100 + hv.minor;
10878 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010879
10880 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010881 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010882 *
10883 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010884 */
10885 @Override
sangyun097dcf72024-01-04 10:35:49 +090010886 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010887 if (mFeatureFlags.hsumPackageManager()) {
10888 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10889 Binder.getCallingUserHandle(), 0).getPackageManager();
10890 if (pm == null) return null;
10891 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10892 return (callingUids == null) ? null : callingUids[0];
10893 }
10894 if (mPackageManager == null) return null;
10895 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10896 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010897 }
10898
10899 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010900 * @return The calling package name or "phone" if the caller is the phone process. This is done
10901 * because multiple Phone has multiple packages in it and the first element in the array is not
10902 * actually always the caller.
10903 * Note: This is for logging purposes only and should not be used for security checks.
10904 */
10905 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010906 PackageManager pm;
10907 if (mFeatureFlags.hsumPackageManager()) {
10908 pm = mApp.getBaseContext().createContextAsUser(
10909 Binder.getCallingUserHandle(), 0).getPackageManager();
10910 } else {
10911 pm = mApp.getPackageManager();
10912 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010913 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10914 if (uidName != null && !uidName.isEmpty()) return uidName;
10915 return getCurrentPackageName();
10916 }
10917
10918 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010919 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10920 * corresponding network requests on a subId.
10921 *
10922 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010923 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010924 * 2) APN is un-metered for this subscription, or
10925 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010926 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010927 *
10928 * @return whether data is allowed for a apn type.
10929 *
10930 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010931 */
10932 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010933 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010934 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10935 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010936
joonhunshin4ac60942023-11-15 15:23:39 +000010937 enforceTelephonyFeatureWithException(callingPackage,
10938 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10939
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010940 // Now that all security checks passes, perform the operation as ourselves.
10941 final long identity = Binder.clearCallingIdentity();
10942 try {
10943 Phone phone = getPhone(subId);
10944 if (phone == null) return false;
10945
Jack Yu27422a52022-03-21 10:38:05 -070010946 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010947 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010948 isMetered = phone.getDataNetworkController().getDataConfigManager()
10949 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10950 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010951 isDataEnabled = (phone.getDataSettingsManager() != null)
10952 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010953 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010954 } finally {
10955 Binder.restoreCallingIdentity(identity);
10956 }
10957 }
10958
10959 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010960 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010961 enforceReadPrivilegedPermission("isApnMetered");
10962
joonhunshin4ac60942023-11-15 15:23:39 +000010963 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10964 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10965
Malcolm Chene5ad5792019-04-18 13:51:02 -070010966 // Now that all security checks passes, perform the operation as ourselves.
10967 final long identity = Binder.clearCallingIdentity();
10968 try {
10969 Phone phone = getPhone(subId);
10970 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010971 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10972 DataUtils.apnTypeToNetworkCapability(apnType),
10973 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010974 } finally {
10975 Binder.restoreCallingIdentity(identity);
10976 }
10977 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010978
10979 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010980 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10981 int subscriptionId, IBooleanConsumer resultCallback) {
10982 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010983
10984 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10985 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10986
Hall Liu73f5d362020-01-20 13:42:00 -080010987 long token = Binder.clearCallingIdentity();
10988 try {
10989 Phone phone = getPhone(subscriptionId);
10990 if (phone == null) {
10991 try {
10992 if (resultCallback != null) {
10993 resultCallback.accept(false);
10994 }
10995 } catch (RemoteException e) {
10996 // ignore
10997 }
10998 return;
10999 }
11000 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11001 Pair.create(specifiers, (x) -> {
11002 try {
11003 if (resultCallback != null) {
11004 resultCallback.accept(x);
11005 }
11006 } catch (RemoteException e) {
11007 // ignore
11008 }
11009 });
11010 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11011 } finally {
11012 Binder.restoreCallingIdentity(token);
11013 }
11014 }
11015
11016 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011017 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11018 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011019 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011020 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011021
11022 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11023 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11024
Sarah Chin679c08a2020-11-18 13:39:35 -080011025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11026 final long identity = Binder.clearCallingIdentity();
11027 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011028 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11029 if (result instanceof IllegalStateException) {
11030 throw (IllegalStateException) result;
11031 }
11032 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011033 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11034 return specifiers;
11035 } finally {
11036 Binder.restoreCallingIdentity(identity);
11037 }
11038 }
11039
11040 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011041 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011042 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011043
11044 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11045 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11046
Jack Yu8b766fc2022-03-21 09:42:33 -070011047 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011048 }
11049
11050 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011051 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11052 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011053 if (callingPackage == null) {
11054 callingPackage = getCurrentPackageName();
11055 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011056 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11057 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011058 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11059 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011060 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11061 }
11062 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11063 Intent intent = new Intent();
11064 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11065 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11066 // Bring up choose default SMS subscription dialog right now
11067 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11068 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011069 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011070 }
chen xud5ca2d52019-05-28 15:20:57 -070011071
11072 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011073 public void showSwitchToManagedProfileDialog() {
11074 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011075 try {
11076 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11077 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11078 // for work telephony.
11079 Intent intent = new Intent(Intent.ACTION_SENDTO);
11080 intent.setData(Uri.parse("smsto:"));
11081 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011082 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011083 } catch (ActivityNotFoundException e) {
11084 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11085 Intent intent = new Intent();
11086 intent.setClass(mApp, ErrorDialogActivity.class);
11087 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011088 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011089 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011090 }
11091
11092 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011093 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11095 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11096
chen xud5ca2d52019-05-28 15:20:57 -070011097 //TODO investigate if this API should require proper permission check in R b/133791609
11098 final long identity = Binder.clearCallingIdentity();
11099 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011100 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11101 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11102 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11103 return carrierUAProfUrl;
11104 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011105 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11106 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011107 } finally {
11108 Binder.restoreCallingIdentity(identity);
11109 }
11110 }
11111
11112 @Override
11113 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011114 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11115 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11116
chen xud5ca2d52019-05-28 15:20:57 -070011117 //TODO investigate if this API should require proper permission check in R b/133791609
11118 final long identity = Binder.clearCallingIdentity();
11119 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011120 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11121 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11122 if (!TextUtils.isEmpty(carrierUserAgent)) {
11123 return carrierUserAgent;
11124 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011125 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11126 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011127 } finally {
11128 Binder.restoreCallingIdentity(identity);
11129 }
11130 }
Jack Yub07d4972019-05-28 16:12:25 -070011131
11132 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011133 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11134 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011135
joonhunshin4ac60942023-11-15 15:23:39 +000011136 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11137 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11138
Jack Yub07d4972019-05-28 16:12:25 -070011139 final long identity = Binder.clearCallingIdentity();
11140 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011141 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011142 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011143
Ling Maf188d502022-09-16 15:22:36 -070011144 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011145 } finally {
11146 Binder.restoreCallingIdentity(identity);
11147 }
11148 }
11149
11150 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011151 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011152 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011153 enforceModifyPermission();
11154
joonhunshin4ac60942023-11-15 15:23:39 +000011155 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11156 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11157
changbettyd5c246e2019-12-24 15:40:37 +080011158 final long identity = Binder.clearCallingIdentity();
11159 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011160 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011161 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011162
Ling Maf188d502022-09-16 15:22:36 -070011163 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011164 } finally {
11165 Binder.restoreCallingIdentity(identity);
11166 }
11167 }
11168
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011169 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011170 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011171 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11172 * otherwise.
11173 */
11174 @Override
11175 public void setCepEnabled(boolean isCepEnabled) {
11176 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11177
11178 final long identity = Binder.clearCallingIdentity();
11179 try {
11180 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11181 for (Phone phone : PhoneFactory.getPhones()) {
11182 Phone defaultPhone = phone.getImsPhone();
11183 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11184 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11185 ImsPhoneCallTracker imsPhoneCallTracker =
11186 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11187 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11188 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11189 + imsPhone.getMsisdn());
11190 }
11191 }
11192 } finally {
11193 Binder.restoreCallingIdentity(identity);
11194 }
11195 }
allenwtsu46dcc572020-01-08 18:24:03 +080011196
11197 /**
11198 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11199 *
11200 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11201 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11202 * before being read.
11203 */
11204 @Override
11205 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11206 isCompressed) {
11207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11208 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011209 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11210 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11211 }
joonhunshin4ac60942023-11-15 15:23:39 +000011212
11213 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11214 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11215 Binder.getCallingUserHandle())) {
11216 if (!isImsAvailableOnDevice()) {
11217 // ProvisioningManager can not handle ServiceSpecificException.
11218 // Throw the IllegalStateException and annotate ProvisioningManager.
11219 throw new IllegalStateException("IMS not available on device.");
11220 }
11221 } else {
11222 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11223 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11224 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011225 }
11226
11227 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011228 try {
Hui Wang761a6682020-10-31 05:12:53 +000011229 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11230 } finally {
11231 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011232 }
11233 }
zoey chene02881a2019-12-30 16:11:23 +080011234
11235 @Override
11236 public boolean isIccLockEnabled(int subId) {
11237 enforceReadPrivilegedPermission("isIccLockEnabled");
11238
joonhunshin4ac60942023-11-15 15:23:39 +000011239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11240 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11241
zoey chene02881a2019-12-30 16:11:23 +080011242 // Now that all security checks passes, perform the operation as ourselves.
11243 final long identity = Binder.clearCallingIdentity();
11244 try {
11245 Phone phone = getPhone(subId);
11246 if (phone != null && phone.getIccCard() != null) {
11247 return phone.getIccCard().getIccLockEnabled();
11248 } else {
11249 return false;
11250 }
11251 } finally {
11252 Binder.restoreCallingIdentity(identity);
11253 }
11254 }
11255
11256 /**
11257 * Set the ICC pin lock enabled or disabled.
11258 *
11259 * @return an integer representing the status of IccLock enabled or disabled in the following
11260 * three cases:
11261 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11262 * successfully.
11263 * - Positive number and zero for remaining password attempts.
11264 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11265 *
11266 */
11267 @Override
11268 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11269 enforceModifyPermission();
11270
joonhunshin4ac60942023-11-15 15:23:39 +000011271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11272 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11273
zoey chene02881a2019-12-30 16:11:23 +080011274 Phone phone = getPhone(subId);
11275 if (phone == null) {
11276 return 0;
11277 }
11278 // Now that all security checks passes, perform the operation as ourselves.
11279 final long identity = Binder.clearCallingIdentity();
11280 try {
11281 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11282 new Pair<Boolean, String>(enabled, password), phone, null);
11283 return attemptsRemaining;
11284
11285 } catch (Exception e) {
11286 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11287 } finally {
11288 Binder.restoreCallingIdentity(identity);
11289 }
11290 return 0;
11291 }
11292
11293 /**
11294 * Change the ICC password used in ICC pin lock.
11295 *
11296 * @return an integer representing the status of IccLock changed in the following three cases:
11297 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11298 * - Positive number and zero for remaining password attempts.
11299 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11300 *
11301 */
11302 @Override
11303 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11304 enforceModifyPermission();
11305
joonhunshin4ac60942023-11-15 15:23:39 +000011306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11307 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11308
zoey chene02881a2019-12-30 16:11:23 +080011309 Phone phone = getPhone(subId);
11310 if (phone == null) {
11311 return 0;
11312 }
11313 // Now that all security checks passes, perform the operation as ourselves.
11314 final long identity = Binder.clearCallingIdentity();
11315 try {
11316 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11317 new Pair<String, String>(oldPassword, newPassword), phone, null);
11318 return attemptsRemaining;
11319
11320 } catch (Exception e) {
11321 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11322 } finally {
11323 Binder.restoreCallingIdentity(identity);
11324 }
11325 return 0;
11326 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011327
11328 /**
11329 * Request for receiving user activity notification
11330 */
11331 @Override
11332 public void requestUserActivityNotification() {
11333 if (!mNotifyUserActivity.get()
11334 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11335 mNotifyUserActivity.set(true);
11336 }
11337 }
11338
11339 /**
11340 * Called when userActivity is signalled in the power manager.
11341 * This is safe to call from any thread, with any window manager locks held or not.
11342 */
11343 @Override
11344 public void userActivity() {
11345 // ***************************************
11346 // * Inherited from PhoneWindowManager *
11347 // ***************************************
11348 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11349 // WITH ITS LOCKS HELD.
11350 //
11351 // This code must be VERY careful about the locks
11352 // it acquires.
11353 // In fact, the current code acquires way too many,
11354 // and probably has lurking deadlocks.
11355
Jack Yu86374492024-09-16 13:05:44 -070011356 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011357 throw new SecurityException("Only the OS may call notifyUserActivity()");
11358 }
11359
11360 if (mNotifyUserActivity.getAndSet(false)) {
11361 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11362 USER_ACTIVITY_NOTIFICATION_DELAY);
11363 }
11364 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011365
11366 @Override
11367 public boolean canConnectTo5GInDsdsMode() {
11368 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11369 }
Jack Yud10cdd42020-09-28 20:28:01 -070011370
11371 @Override
11372 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11373 String callingFeatureId) {
11374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11375 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11376 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11377 }
11378
joonhunshin4ac60942023-11-15 15:23:39 +000011379 enforceTelephonyFeatureWithException(callingPackage,
11380 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11381
Jack Yud10cdd42020-09-28 20:28:01 -070011382 Phone phone = getPhone(subId);
11383 if (phone == null) {
11384 throw new RuntimeException("phone is not available");
11385 }
11386 // Now that all security checks passes, perform the operation as ourselves.
11387 final long identity = Binder.clearCallingIdentity();
11388 try {
11389 return phone.getEquivalentHomePlmns();
11390 } finally {
11391 Binder.restoreCallingIdentity(identity);
11392 }
11393 }
Daniel Bright59e67312020-11-13 11:49:37 -080011394
11395 @Override
11396 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011397 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011398 if (!mApp.getResources().getBoolean(
11399 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11400 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11401 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11402 "isRadioInterfaceCapabilitySupported");
11403 }
joonhunshin4ac60942023-11-15 15:23:39 +000011404
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011405 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011406 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011407 if (radioInterfaceCapabilities == null) {
11408 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011409 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011410 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011411 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011412
Hui Wang641e81c2020-10-12 12:14:23 -070011413 @Override
11414 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11415 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011416 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11417 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11418 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11419 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11420 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011421
11422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11423 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11424
Hui Wang641e81c2020-10-12 12:14:23 -070011425 if (DBG) {
11426 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11427 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11428 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11429 }
11430
11431 if (!SubscriptionManager.isValidSubscriptionId(subId)
11432 || appType < TelephonyManager.APPTYPE_UNKNOWN
11433 || appType > TelephonyManager.APPTYPE_ISIM
11434 || nafUrl == null || securityProtocol == null || callback == null) {
11435 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11436 if (callback != null) {
11437 try {
11438 callback.onAuthenticationFailure(
11439 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11440 } catch (RemoteException exception) {
11441 log("Fail to notify onAuthenticationFailure due to " + exception);
11442 }
11443 return;
11444 }
11445 }
11446
11447 final long token = Binder.clearCallingIdentity();
11448 try {
11449 getGbaManager(subId).bootstrapAuthenticationRequest(
11450 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011451 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011452 } finally {
11453 Binder.restoreCallingIdentity(token);
11454 }
11455 }
11456
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011457 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011458 * Attempts to set the radio power state for all phones for thermal reason.
11459 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011460 * requested radio power state will actually be set. See {@link
11461 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11462 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011463 * @param enable {@code true} if trying to turn radio on.
11464 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11465 * false}.
11466 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011467 private boolean setRadioPowerForThermal(boolean enable) {
11468 boolean isPhoneAvailable = false;
11469 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11470 Phone phone = PhoneFactory.getPhone(i);
11471 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011472 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011473 isPhoneAvailable = true;
11474 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011475 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011476
11477 // return true if successfully informed the phone object about the thermal radio power
11478 // request.
11479 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011480 }
11481
11482 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011483 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011484 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11485 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11486 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11487 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11488 throw new IllegalArgumentException("modem does not support data throttling");
11489 }
11490
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011491 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11492 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011493 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011494 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11495 }
11496
Sarah Chinecc78c42022-03-31 21:16:48 -070011497 setDataEnabledForReason(
11498 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011499
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011500 if (isDataThrottlingSupported) {
11501 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011502 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011503 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11504 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11505 } else if (thermalMitigationResult
11506 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011507 log("Modem likely does not support data throttling on secondary carrier. Data " +
11508 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11509 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011510 }
11511 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011512 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011513
11514 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 }
11516
Jack Nudelman644b91a2021-03-12 14:09:48 -080011517 private static List<String> getThermalMitigationAllowlist(Context context) {
11518 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11519 for (String pckg : context.getResources()
11520 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11521 sThermalMitigationAllowlistedPackages.add(pckg);
11522 }
11523 }
11524
11525 return sThermalMitigationAllowlistedPackages;
11526 }
11527
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011528 private boolean isAnyPhoneInEmergencyState() {
11529 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11530 if (tm.isInEmergencyCall()) {
11531 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11532 return true;
11533 }
11534 for (Phone phone : PhoneFactory.getPhones()) {
11535 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11536 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011537 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11538 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011539 return true;
11540 }
11541 }
11542
11543 return false;
11544 }
11545
Jack Nudelman644b91a2021-03-12 14:09:48 -080011546 /**
11547 * Used by shell commands to add an authorized package name for thermal mitigation.
11548 * @param packageName name of package to be allowlisted
11549 * @param context
11550 */
11551 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11552 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11553 sThermalMitigationAllowlistedPackages.add(packageName);
11554 }
11555
11556 /**
11557 * Used by shell commands to remove an authorized package name for thermal mitigation.
11558 * @param packageName name of package to remove from allowlist
11559 * @param context
11560 */
11561 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11562 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11563 sThermalMitigationAllowlistedPackages.remove(packageName);
11564 }
11565
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011566 /**
11567 * Thermal mitigation request to control functionalities at modem.
11568 *
11569 * @param subId the id of the subscription.
11570 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011571 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011572 *
11573 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11574 */
11575 @Override
11576 @ThermalMitigationResult
11577 public int sendThermalMitigationRequest(
11578 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011579 ThermalMitigationRequest thermalMitigationRequest,
11580 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011581 enforceModifyPermission();
11582
Jack Nudelman644b91a2021-03-12 14:09:48 -080011583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011584
11585 enforceTelephonyFeatureWithException(callingPackage,
11586 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11587
Jack Nudelman644b91a2021-03-12 14:09:48 -080011588 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11589 .contains(callingPackage)) {
11590 throw new SecurityException("Calling package must be configured in the device config. "
11591 + "calling package: " + callingPackage);
11592 }
11593
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11595 final long identity = Binder.clearCallingIdentity();
11596
11597 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11598 try {
11599 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11600 switch (thermalMitigationAction) {
11601 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11602 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011603 handleDataThrottlingRequest(subId,
11604 thermalMitigationRequest.getDataThrottlingRequest(),
11605 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011606 break;
11607 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11608 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11609 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11610 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11611 }
11612
11613 // Ensure that radio is on. If not able to power on due to phone being
11614 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011615 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011616 thermalMitigationResult =
11617 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11618 break;
11619 }
11620
11621 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011622 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011623 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11624 break;
11625 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11626 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11627 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11628 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11629 }
11630
11631 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11632 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011633 Phone phone = getPhone(subId);
11634 if (phone == null) {
11635 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011636 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011637 break;
11638 }
11639
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011640 TelephonyConnectionService service =
11641 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011642 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011643 Log.e(LOG_TAG, "An emergency call is pending");
11644 thermalMitigationResult =
11645 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11646 break;
11647 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011648 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011649 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011650 break;
11651 }
11652 } else {
11653 thermalMitigationResult =
11654 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11655 break;
11656 }
11657
11658 // Turn radio off. If not able to power off due to phone being unavailable,
11659 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011660 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011661 thermalMitigationResult =
11662 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11663 break;
11664 }
11665 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011666 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011667 break;
11668 default:
11669 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11670 + "not exist. Requested action: " + thermalMitigationAction);
11671 }
11672 } catch (IllegalArgumentException e) {
11673 throw e;
11674 } catch (Exception e) {
11675 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11676 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11677 } finally {
11678 Binder.restoreCallingIdentity(identity);
11679 }
11680
11681 if (DBG) {
11682 log("thermalMitigationRequest returning with thermalMitigationResult: "
11683 + thermalMitigationResult);
11684 }
11685
11686 return thermalMitigationResult;
11687 }
Hui Wang641e81c2020-10-12 12:14:23 -070011688
11689 /**
11690 * Set the GbaService Package Name that Telephony will bind to.
11691 *
11692 * @param subId The sim that the GbaService is associated with.
11693 * @param packageName The name of the package to be replaced with.
11694 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11695 */
11696 @Override
11697 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11698 enforceModifyPermission();
11699
11700 final long identity = Binder.clearCallingIdentity();
11701 try {
11702 return getGbaManager(subId).overrideServicePackage(packageName);
11703 } finally {
11704 Binder.restoreCallingIdentity(identity);
11705 }
11706 }
11707
11708 /**
11709 * Return the package name of the currently bound GbaService.
11710 *
11711 * @param subId The sim that the GbaService is associated with.
11712 * @return the package name of the GbaService configuration, null if GBA is not supported.
11713 */
11714 @Override
11715 public String getBoundGbaService(int subId) {
11716 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11717
11718 final long identity = Binder.clearCallingIdentity();
11719 try {
11720 return getGbaManager(subId).getServicePackage();
11721 } finally {
11722 Binder.restoreCallingIdentity(identity);
11723 }
11724 }
11725
11726 /**
11727 * Set the release time for telephony to unbind GbaService.
11728 *
11729 * @param subId The sim that the GbaService is associated with.
11730 * @param interval The release time to unbind GbaService by millisecond.
11731 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11732 */
11733 @Override
11734 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11735 enforceModifyPermission();
11736
11737 final long identity = Binder.clearCallingIdentity();
11738 try {
11739 return getGbaManager(subId).overrideReleaseTime(interval);
11740 } finally {
11741 Binder.restoreCallingIdentity(identity);
11742 }
11743 }
11744
11745 /**
11746 * Return the release time for telephony to unbind GbaService.
11747 *
11748 * @param subId The sim that the GbaService is associated with.
11749 * @return The release time to unbind GbaService by millisecond.
11750 */
11751 @Override
11752 public int getGbaReleaseTime(int subId) {
11753 enforceReadPrivilegedPermission("getGbaReleaseTime");
11754
11755 final long identity = Binder.clearCallingIdentity();
11756 try {
11757 return getGbaManager(subId).getReleaseTime();
11758 } finally {
11759 Binder.restoreCallingIdentity(identity);
11760 }
11761 }
11762
11763 private GbaManager getGbaManager(int subId) {
11764 GbaManager instance = GbaManager.getInstance(subId);
11765 if (instance == null) {
11766 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11767 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11768 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11769 }
11770 return instance;
11771 }
Hui Wang761a6682020-10-31 05:12:53 +000011772
11773 /**
11774 * indicate whether the device and the carrier can support
11775 * RCS VoLTE single registration.
11776 */
11777 @Override
11778 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011779 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11780 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11781 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11782 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011783
11784 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11785 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11786 }
11787
11788 final long identity = Binder.clearCallingIdentity();
11789 try {
11790 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11791 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011792 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11793 if (isCapable != null) {
11794 return isCapable;
11795 }
Hui Wang761a6682020-10-31 05:12:53 +000011796 }
Hui Wang67af90e2021-06-04 16:57:15 -070011797 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11798 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011799 } finally {
11800 Binder.restoreCallingIdentity(identity);
11801 }
11802 }
11803
11804 /**
11805 * Register RCS provisioning callback.
11806 */
11807 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011808 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011809 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011810 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011811 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011812 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11813 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011814
11815 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11816 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11817 }
joonhunshin4ac60942023-11-15 15:23:39 +000011818 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11819 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11820 Binder.getCallingUserHandle())) {
11821 if (!isImsAvailableOnDevice()) {
11822 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11823 "IMS not available on device.");
11824 }
11825 } else {
11826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11827 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011828 }
11829
11830 final long identity = Binder.clearCallingIdentity();
11831 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011832 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011833 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011834 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11835 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011836 }
Hui Wang761a6682020-10-31 05:12:53 +000011837 } finally {
11838 Binder.restoreCallingIdentity(identity);
11839 }
11840 }
11841
11842 /**
11843 * Unregister RCS provisioning callback.
11844 */
11845 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011846 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011847 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011848 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011849 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011850 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11851 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011852
11853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11854 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11855 }
joonhunshin4ac60942023-11-15 15:23:39 +000011856
11857 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11858 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11859 Binder.getCallingUserHandle())) {
11860 if (!isImsAvailableOnDevice()) {
11861 // operation failed silently
11862 Rlog.w(LOG_TAG, "IMS not available on device.");
11863 return;
11864 }
11865 } else {
11866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11867 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11868 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011869 }
11870
11871 final long identity = Binder.clearCallingIdentity();
11872 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011873 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011874 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011875 } finally {
11876 Binder.restoreCallingIdentity(identity);
11877 }
11878 }
11879
11880 /**
11881 * trigger RCS reconfiguration.
11882 */
11883 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011884 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11885 "triggerRcsReconfiguration",
11886 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011887
11888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11889 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11890 }
joonhunshin4ac60942023-11-15 15:23:39 +000011891 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11892 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11893 Binder.getCallingUserHandle())) {
11894 if (!isImsAvailableOnDevice()) {
11895 // ProvisioningManager can not handle ServiceSpecificException.
11896 // Throw the IllegalStateException and annotate ProvisioningManager.
11897 throw new IllegalStateException("IMS not available on device.");
11898 }
11899 } else {
11900 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11901 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011902 }
11903
11904 final long identity = Binder.clearCallingIdentity();
11905 try {
11906 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11907 } finally {
11908 Binder.restoreCallingIdentity(identity);
11909 }
11910 }
11911
11912 /**
11913 * Provide the client configuration parameters of the RCS application.
11914 */
11915 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011916 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11917 "setRcsClientConfiguration",
11918 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011919
11920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11922 }
joonhunshin4ac60942023-11-15 15:23:39 +000011923 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11924 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11925 Binder.getCallingUserHandle())) {
11926 if (!isImsAvailableOnDevice()) {
11927 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11928 "IMS not available on device.");
11929 }
11930 } else {
11931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11932 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011933 }
11934
11935 final long identity = Binder.clearCallingIdentity();
11936
11937 try {
11938 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11939 if (configBinder == null) {
11940 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011941 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11942 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011943 } else {
11944 configBinder.setRcsClientConfiguration(rcc);
11945 }
joonhunshin3e154242021-09-17 06:33:39 +000011946
11947 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11948 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011949 } catch (RemoteException e) {
11950 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011951 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11952 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011953 } finally {
11954 Binder.restoreCallingIdentity(identity);
11955 }
11956 }
11957
11958 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011959 * Enables or disables the test mode for RCS VoLTE single registration.
11960 */
11961 @Override
11962 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11964 "setRcsSingleRegistrationTestModeEnabled");
11965
11966 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11967 }
11968
11969 /**
11970 * Gets the test mode for RCS VoLTE single registration.
11971 */
11972 @Override
11973 public boolean getRcsSingleRegistrationTestModeEnabled() {
11974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11975 "getRcsSingleRegistrationTestModeEnabled");
11976
11977 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11978 }
11979
11980 /**
Hui Wang761a6682020-10-31 05:12:53 +000011981 * Overrides the config of RCS VoLTE single registration enabled for the device.
11982 */
11983 @Override
11984 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11986 "setDeviceSingleRegistrationEnabledOverride");
11987 enforceModifyPermission();
11988
11989 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11990 : Boolean.parseBoolean(enabledStr);
11991 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011992 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011993 }
11994
11995 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011996 * Sends a device to device communication message. Only usable via shell.
11997 * @param message message to send.
11998 * @param value message value.
11999 */
12000 @Override
12001 public void sendDeviceToDeviceMessage(int message, int value) {
12002 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012003 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012004 enforceModifyPermission();
12005
12006 final long identity = Binder.clearCallingIdentity();
12007 try {
12008 TelephonyConnectionService service =
12009 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12010 if (service == null) {
12011 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12012 return;
12013 }
12014 service.sendTestDeviceToDeviceMessage(message, value);
12015 } finally {
12016 Binder.restoreCallingIdentity(identity);
12017 }
12018 }
12019
Tyler Gunnbabbda02021-02-10 11:05:02 -080012020 /**
12021 * Sets the specified device to device transport active.
12022 * @param transport The transport to set active.
12023 */
12024 @Override
12025 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12027 "setActiveDeviceToDeviceTransport");
12028 enforceModifyPermission();
12029
12030 final long identity = Binder.clearCallingIdentity();
12031 try {
12032 TelephonyConnectionService service =
12033 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12034 if (service == null) {
12035 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12036 return;
12037 }
12038 service.setActiveDeviceToDeviceTransport(transport);
12039 } finally {
12040 Binder.restoreCallingIdentity(identity);
12041 }
12042 }
Tyler Gunn92479152021-01-20 16:30:10 -080012043
Tyler Gunnd4339262021-05-03 14:46:49 -070012044 @Override
12045 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12047 "setDeviceToDeviceForceEnabled");
12048
12049 final long identity = Binder.clearCallingIdentity();
12050 try {
12051 Arrays.stream(PhoneFactory.getPhones()).forEach(
12052 p -> {
12053 Phone thePhone = p.getImsPhone();
12054 if (thePhone != null && thePhone instanceof ImsPhone) {
12055 ImsPhone imsPhone = (ImsPhone) thePhone;
12056 CallTracker tracker = imsPhone.getCallTracker();
12057 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12058 ImsPhoneCallTracker imsPhoneCallTracker =
12059 (ImsPhoneCallTracker) tracker;
12060 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12061 }
12062 }
12063 }
12064 );
12065 } finally {
12066 Binder.restoreCallingIdentity(identity);
12067 }
12068 }
12069
Tyler Gunn92479152021-01-20 16:30:10 -080012070 /**
Hui Wang761a6682020-10-31 05:12:53 +000012071 * Gets the config of RCS VoLTE single registration enabled for the device.
12072 */
12073 @Override
12074 public boolean getDeviceSingleRegistrationEnabled() {
12075 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12076 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12077 }
12078
12079 /**
12080 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12081 */
12082 @Override
12083 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12085 "setCarrierSingleRegistrationEnabledOverride");
12086 enforceModifyPermission();
12087
12088 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12089 : Boolean.parseBoolean(enabledStr);
12090 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12091 subId, enabled);
12092 }
12093
12094 /**
12095 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12096 */
12097 @Override
12098 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12099 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12100 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12101 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012102
12103 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012104 * Overrides the ims feature validation result
12105 */
12106 @Override
12107 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12109 "setImsFeatureValidationOverride");
12110
12111 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12112 : Boolean.parseBoolean(enabledStr);
12113 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12114 subId, enabled);
12115 }
12116
12117 /**
12118 * Gets the ims feature validation override value
12119 */
12120 @Override
12121 public boolean getImsFeatureValidationOverride(int subId) {
12122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12123 "getImsFeatureValidationOverride");
12124 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12125 }
12126
12127 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012128 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12129 * their mobile plan.
12130 */
12131 @Override
12132 public String getMobileProvisioningUrl() {
12133 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12134 final long identity = Binder.clearCallingIdentity();
12135 try {
12136 return getDefaultPhone().getMobileProvisioningUrl();
12137 } finally {
12138 Binder.restoreCallingIdentity(identity);
12139 }
12140 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012141
James.cf Linbcdf8b32021-01-14 16:44:13 +080012142 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012143 * Get the EAB contact from the EAB database.
12144 */
12145 @Override
12146 public String getContactFromEab(String contact) {
12147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12148 enforceModifyPermission();
12149 final long identity = Binder.clearCallingIdentity();
12150 try {
12151 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12152 } finally {
12153 Binder.restoreCallingIdentity(identity);
12154 }
12155 }
12156
12157 /**
Calvin Pana1434322021-07-01 19:27:01 +080012158 * Get the EAB capability from the EAB database.
12159 */
12160 @Override
12161 public String getCapabilityFromEab(String contact) {
12162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12163 enforceModifyPermission();
12164 final long identity = Binder.clearCallingIdentity();
12165 try {
12166 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12167 } finally {
12168 Binder.restoreCallingIdentity(identity);
12169 }
12170 }
12171
12172 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012173 * Remove the EAB contacts from the EAB database.
12174 */
12175 @Override
12176 public int removeContactFromEab(int subId, String contacts) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12178 enforceModifyPermission();
12179 final long identity = Binder.clearCallingIdentity();
12180 try {
12181 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12182 } finally {
12183 Binder.restoreCallingIdentity(identity);
12184 }
12185 }
12186
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012187 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012188 public boolean getDeviceUceEnabled() {
12189 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12190 final long identity = Binder.clearCallingIdentity();
12191 try {
12192 return mApp.getDeviceUceEnabled();
12193 } finally {
12194 Binder.restoreCallingIdentity(identity);
12195 }
12196 }
12197
12198 @Override
12199 public void setDeviceUceEnabled(boolean isEnabled) {
12200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12201 final long identity = Binder.clearCallingIdentity();
12202 try {
12203 mApp.setDeviceUceEnabled(isEnabled);
12204 } finally {
12205 Binder.restoreCallingIdentity(identity);
12206 }
12207 }
12208
Brad Ebinger14d467f2021-02-12 06:18:28 +000012209 /**
12210 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12211 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12212 */
12213 // Used for SHELL command only right now.
12214 @Override
12215 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12216 List<String> featureTags) {
12217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12218 "addUceRegistrationOverrideShell");
12219 final long identity = Binder.clearCallingIdentity();
12220 try {
12221 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12222 new ArraySet<>(featureTags));
12223 } catch (ImsException e) {
12224 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12225 } finally {
12226 Binder.restoreCallingIdentity(identity);
12227 }
12228 }
12229
12230 /**
12231 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12232 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12233 */
12234 // Used for SHELL command only right now.
12235 @Override
12236 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12237 List<String> featureTags) {
12238 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12239 "removeUceRegistrationOverrideShell");
12240 final long identity = Binder.clearCallingIdentity();
12241 try {
12242 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12243 new ArraySet<>(featureTags));
12244 } catch (ImsException e) {
12245 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12246 } finally {
12247 Binder.restoreCallingIdentity(identity);
12248 }
12249 }
12250
12251 /**
12252 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12253 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12254 */
12255 // Used for SHELL command only right now.
12256 @Override
12257 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12258 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12259 "clearUceRegistrationOverrideShell");
12260 final long identity = Binder.clearCallingIdentity();
12261 try {
12262 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12263 } catch (ImsException e) {
12264 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12265 } finally {
12266 Binder.restoreCallingIdentity(identity);
12267 }
12268 }
12269
12270 /**
12271 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12272 */
12273 // Used for SHELL command only right now.
12274 @Override
12275 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12276 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12277 "getLatestRcsContactUceCapabilityShell");
12278 final long identity = Binder.clearCallingIdentity();
12279 try {
12280 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12281 } catch (ImsException e) {
12282 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12283 } finally {
12284 Binder.restoreCallingIdentity(identity);
12285 }
12286 }
12287
12288 /**
12289 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12290 * device does not have an active PUBLISH.
12291 */
12292 // Used for SHELL command only right now.
12293 @Override
12294 public String getLastUcePidfXmlShell(int subId) {
12295 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12296 final long identity = Binder.clearCallingIdentity();
12297 try {
12298 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12299 } catch (ImsException e) {
12300 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12301 } finally {
12302 Binder.restoreCallingIdentity(identity);
12303 }
12304 }
12305
James.cf Line8713a42021-04-29 16:04:26 +080012306 /**
12307 * Remove UCE requests cannot be sent to the network status.
12308 */
12309 // Used for SHELL command only right now.
12310 @Override
12311 public boolean removeUceRequestDisallowedStatus(int subId) {
12312 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12313 final long identity = Binder.clearCallingIdentity();
12314 try {
12315 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12316 } catch (ImsException e) {
12317 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12318 } finally {
12319 Binder.restoreCallingIdentity(identity);
12320 }
12321 }
12322
James.cf Lin18bb9002021-05-25 01:37:38 +080012323 /**
12324 * Remove UCE requests cannot be sent to the network status.
12325 */
12326 // Used for SHELL command only.
12327 @Override
12328 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12330 final long identity = Binder.clearCallingIdentity();
12331 try {
12332 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12333 } catch (ImsException e) {
12334 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12335 } finally {
12336 Binder.restoreCallingIdentity(identity);
12337 }
12338 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012339
James.cf Lin4b784aa2021-01-31 03:25:15 +080012340 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012341 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12342 String callingPackage) {
12343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12344 mApp, subId, "setSignalStrengthUpdateRequest");
12345
joonhunshin4ac60942023-11-15 15:23:39 +000012346 enforceTelephonyFeatureWithException(callingPackage,
12347 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12348
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012349 final int callingUid = Binder.getCallingUid();
12350 // Verify that tha callingPackage belongs to the calling UID
12351 mApp.getSystemService(AppOpsManager.class)
12352 .checkPackage(callingUid, callingPackage);
12353
Rambo Wang3607f502021-02-01 21:51:40 -080012354 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012355
12356 final long identity = Binder.clearCallingIdentity();
12357 try {
12358 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12359 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12360
12361 if (result instanceof IllegalStateException) {
12362 throw (IllegalStateException) result;
12363 }
12364 } finally {
12365 Binder.restoreCallingIdentity(identity);
12366 }
12367 }
12368
12369 @Override
12370 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12371 String callingPackage) {
12372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12373 mApp, subId, "clearSignalStrengthUpdateRequest");
12374
joonhunshin4ac60942023-11-15 15:23:39 +000012375 enforceTelephonyFeatureWithException(callingPackage,
12376 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12377
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012378 final int callingUid = Binder.getCallingUid();
12379 // Verify that tha callingPackage belongs to the calling UID
12380 mApp.getSystemService(AppOpsManager.class)
12381 .checkPackage(callingUid, callingPackage);
12382
12383 final long identity = Binder.clearCallingIdentity();
12384 try {
12385 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12386 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12387
12388 if (result instanceof IllegalStateException) {
12389 throw (IllegalStateException) result;
12390 }
12391 } finally {
12392 Binder.restoreCallingIdentity(identity);
12393 }
12394 }
12395
Rambo Wang3607f502021-02-01 21:51:40 -080012396 private static void validateSignalStrengthUpdateRequest(Context context,
12397 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012398 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012399 // phone/system process do not have further restriction on request
12400 return;
12401 }
12402
12403 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012404 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012405 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012406 context.enforceCallingOrSelfPermission(
12407 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12408 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012409 }
12410
12411 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012412 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012413 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012414 || info.isEnabled()) {
12415 throw new IllegalArgumentException(
12416 "Only system can set hide fields in SignalThresholdInfo");
12417 }
12418
12419 // Thresholds length for each RAN need in range. This has been validated in
12420 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12421 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12422 final int[] thresholds = info.getThresholds();
12423 Objects.requireNonNull(thresholds);
12424 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12425 || thresholds.length
12426 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12427 throw new IllegalArgumentException(
12428 "thresholds length is out of range: " + thresholds.length);
12429 }
12430 }
12431 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012432
12433 /**
12434 * Gets the current phone capability.
12435 *
12436 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12437 * @return the PhoneCapability which describes the data connection capability of modem.
12438 * It's used to evaluate possible phone config change, for example from single
12439 * SIM device to multi-SIM device.
12440 */
12441 @Override
12442 public PhoneCapability getPhoneCapability() {
12443 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012444
12445 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12446 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12447
SongFerngWang8236caa2021-01-17 21:51:44 +080012448 final long identity = Binder.clearCallingIdentity();
12449 try {
12450 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12451 } finally {
12452 Binder.restoreCallingIdentity(identity);
12453 }
12454 }
Michele Berionne5e411512020-11-13 02:36:59 +000012455
12456 /**
12457 * Prepare TelephonyManager for an unattended reboot. The reboot is
12458 * required to be done shortly after the API is invoked.
12459 */
12460 @Override
12461 @TelephonyManager.PrepareUnattendedRebootResult
12462 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012463 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012464 enforceRebootPermission();
12465
joonhunshin4ac60942023-11-15 15:23:39 +000012466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12467 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12468
Michele Berionne5e411512020-11-13 02:36:59 +000012469 final long identity = Binder.clearCallingIdentity();
12470 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012471 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012472 } finally {
12473 Binder.restoreCallingIdentity(identity);
12474 }
12475 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012476
12477 /**
12478 * Request to get the current slicing configuration including URSP rules and
12479 * NSSAIs (configured, allowed and rejected).
12480 *
12481 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12482 */
12483 @Override
12484 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012485 TelephonyPermissions
12486 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12487 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012488
joonhunshin4ac60942023-11-15 15:23:39 +000012489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12490 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12491 "getSlicingConfig");
12492
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012493 final long identity = Binder.clearCallingIdentity();
12494 try {
12495 Phone phone = getDefaultPhone();
12496 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12497 } finally {
12498 Binder.restoreCallingIdentity(identity);
12499 }
12500 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012501
12502 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012503 * Check whether the given premium capability is available for purchase from the carrier.
12504 *
12505 * @param capability The premium capability to check.
12506 * @param subId The subId to check the premium capability for.
12507 *
12508 * @return Whether the given premium capability is available to purchase.
12509 */
12510 @Override
12511 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12512 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12513 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12514 log("Premium capability "
12515 + TelephonyManager.convertPremiumCapabilityToString(capability)
12516 + " is not available for purchase due to missing permissions.");
12517 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12518 + "permission READ_BASIC_PHONE_STATE.");
12519 }
12520
joonhunshin4ac60942023-11-15 15:23:39 +000012521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12522 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12523
Sarah Chin2ec39f62022-08-31 17:03:26 -070012524 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012525 if (phone == null) {
12526 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12527 return false;
12528 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012529 final long identity = Binder.clearCallingIdentity();
12530 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012531 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012532 .isPremiumCapabilityAvailableForPurchase(capability);
12533 } finally {
12534 Binder.restoreCallingIdentity(identity);
12535 }
12536 }
12537
12538 /**
12539 * Purchase the given premium capability from the carrier.
12540 *
12541 * @param capability The premium capability to purchase.
12542 * @param callback The result of the purchase request.
12543 * @param subId The subId to purchase the premium capability for.
12544 */
12545 @Override
12546 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12547 log("purchasePremiumCapability: capability="
12548 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12549 + getCurrentPackageName());
12550
12551 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12552 mApp, "purchasePremiumCapability")) {
12553 log("purchasePremiumCapability "
12554 + TelephonyManager.convertPremiumCapabilityToString(capability)
12555 + " failed due to missing permissions.");
12556 throw new SecurityException("purchasePremiumCapability requires permission "
12557 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012558 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12559 mApp, "purchasePremiumCapability")) {
12560 log("purchasePremiumCapability "
12561 + TelephonyManager.convertPremiumCapabilityToString(capability)
12562 + " failed due to missing permissions.");
12563 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012564 }
12565
joonhunshin4ac60942023-11-15 15:23:39 +000012566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12567 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12568
Sarah Chin2ec39f62022-08-31 17:03:26 -070012569 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012570 if (phone == null) {
12571 try {
12572 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12573 callback.accept(result);
12574 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12575 } catch (RemoteException e) {
12576 String logStr = "Purchase premium capability "
12577 + TelephonyManager.convertPremiumCapabilityToString(capability)
12578 + " failed due to RemoteException handling null phone: " + e;
12579 if (DBG) log(logStr);
12580 AnomalyReporter.reportAnomaly(
12581 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12582 }
12583 return;
12584 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012585
12586 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012587 try {
Jack Yube3fa442024-09-16 14:39:45 -070012588 if (mFeatureFlags.hsumPackageManager()) {
12589 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12590 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12591 } else {
12592 callingProcess = mApp.getPackageManager().getApplicationInfo(
12593 getCurrentPackageName(), 0).processName;
12594 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012595 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012596 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012597 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012598
12599 boolean isVisible = false;
12600 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12601 if (am != null) {
12602 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12603 if (processes != null) {
12604 for (ActivityManager.RunningAppProcessInfo process : processes) {
12605 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012606 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012607 if (process.processName.equals(callingProcess) && process.importance
12608 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12609 isVisible = true;
12610 break;
12611 }
12612 }
12613 }
12614 }
12615
12616 if (!isVisible) {
12617 try {
12618 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12619 callback.accept(result);
12620 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12621 } catch (RemoteException e) {
12622 String logStr = "Purchase premium capability "
12623 + TelephonyManager.convertPremiumCapabilityToString(capability)
12624 + " failed due to RemoteException handling background application: " + e;
12625 if (DBG) log(logStr);
12626 AnomalyReporter.reportAnomaly(
12627 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12628 }
12629 return;
12630 }
12631
Sarah Chin71b3a852022-09-28 15:54:19 -070012632 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012633 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012634 }
12635
12636 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012637 * Register an IMS connection state callback
12638 */
12639 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012640 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12641 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012642 if (feature == ImsFeature.FEATURE_MMTEL) {
12643 // ImsMmTelManager
12644 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12645 TelephonyPermissions
12646 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12647 mApp, subId, "registerImsStateCallback");
12648 } else if (feature == ImsFeature.FEATURE_RCS) {
12649 // ImsRcsManager or SipDelegateManager
12650 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12651 Binder.getCallingUid(), "registerImsStateCallback",
12652 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12653 Manifest.permission.READ_PRECISE_PHONE_STATE,
12654 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12655 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12656 }
12657
12658 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12659 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12660 "IMS not available on device.");
12661 }
12662
12663 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12664 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12665 }
12666
12667 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12668 if (controller == null) {
12669 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12670 "IMS not available on device.");
12671 }
12672
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012673 if (callingPackage == null) {
12674 callingPackage = getCurrentPackageName();
12675 }
12676
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012677 final long token = Binder.clearCallingIdentity();
12678 try {
12679 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012680 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012681 } catch (ImsException e) {
12682 throw new ServiceSpecificException(e.getCode());
12683 } finally {
12684 Binder.restoreCallingIdentity(token);
12685 }
12686 }
12687
12688 /**
12689 * Unregister an IMS connection state callback
12690 */
12691 @Override
12692 public void unregisterImsStateCallback(IImsStateCallback cb) {
12693 final long token = Binder.clearCallingIdentity();
12694 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12695 if (controller == null) {
12696 return;
12697 }
12698 try {
12699 controller.unregisterImsStateCallback(cb);
12700 } finally {
12701 Binder.restoreCallingIdentity(token);
12702 }
12703 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012704
12705 /**
12706 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12707 *
12708 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012709 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012710 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012711 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012712 * If there is current registered network this value will be same as the registered cell
12713 * identity. If the device goes out of service the previous cell identity is cached and
12714 * will be returned. If the cache age of the Cell identity is more than 24 hours
12715 * it will be cleared and null will be returned.
12716 *
12717 */
12718 @Override
12719 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12720 String callingFeatureId) {
12721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12722 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12723 LocationAccessPolicy.checkLocationPermission(mApp,
12724 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12725 .setCallingPackage(callingPackage)
12726 .setCallingFeatureId(callingFeatureId)
12727 .setCallingPid(Binder.getCallingPid())
12728 .setCallingUid(Binder.getCallingUid())
12729 .setMethod("getLastKnownCellIdentity")
12730 .setLogAsInfo(true)
12731 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12732 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12733 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12734 .build());
12735
12736 boolean hasFinePermission =
12737 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12738 if (!hasFinePermission
12739 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12740 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012741 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012742 }
12743
12744 final long identity = Binder.clearCallingIdentity();
12745 try {
Ling Mac28f0212023-03-24 16:07:15 -070012746 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012747 if (sst == null) return null;
12748 return sst.getLastKnownCellIdentity();
12749 } finally {
12750 Binder.restoreCallingIdentity(identity);
12751 }
12752 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012753
jimsun3b9ccac2021-10-26 15:01:23 +080012754 /**
12755 * Sets the modem service class Name that Telephony will bind to.
12756 *
12757 * @param serviceName The class name of the modem service.
12758 * @return true if the operation is succeed, otherwise false.
12759 */
12760 public boolean setModemService(String serviceName) {
12761 Log.d(LOG_TAG, "setModemService - " + serviceName);
12762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012764 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12765 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012766 return mPhoneConfigurationManager.setModemService(serviceName);
12767 }
12768
12769 /**
12770 * Return the class name of the currently bounded modem service.
12771 *
12772 * @return the class name of the modem service.
12773 */
12774 public String getModemService() {
12775 String result;
12776 Log.d(LOG_TAG, "getModemService");
12777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12778 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012779 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012780 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12781 "getModemService");
12782 result = mPhoneConfigurationManager.getModemService();
12783 Log.d(LOG_TAG, "result = " + result);
12784 return result;
12785 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012786
Hakjun Choi3ee81112023-12-19 15:40:58 +000012787 /**
12788 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12789 * including carrier config, entitlement server, and config update.
12790 *
12791 * @param subId subId The subscription ID of the carrier.
12792 *
12793 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12794 * be returned.
12795 *
12796 * @throws SecurityException if the caller doesn't have the required permission.
12797 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012798 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12799 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012800 final long identity = Binder.clearCallingIdentity();
12801 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012802 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012803 } finally {
12804 Binder.restoreCallingIdentity(identity);
12805 }
12806 }
12807
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012808 @Override
12809 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12810 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12811 mApp.enforceCallingOrSelfPermission(
12812 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12813 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12814
12815 final long identity = Binder.clearCallingIdentity();
12816 try {
12817 Phone phone = getPhone(subId);
12818 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012819 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12820 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012821 phone.setVoiceServiceStateOverride(hasService);
12822 } finally {
12823 Binder.restoreCallingIdentity(identity);
12824 }
12825 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012826
12827 /**
12828 * set removable eSIM as default eUICC.
12829 *
12830 * @hide
12831 */
12832 @Override
12833 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12834 enforceModifyPermission();
12835 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12836
12837 final long identity = Binder.clearCallingIdentity();
12838 try {
12839 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12840 } finally {
12841 Binder.restoreCallingIdentity(identity);
12842 }
12843 }
12844
12845 /**
12846 * Returns whether the removable eSIM is default eUICC or not.
12847 *
12848 * @hide
12849 */
12850 @Override
12851 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12852 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12853 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12854
12855 final long identity = Binder.clearCallingIdentity();
12856 try {
12857 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12858 } finally {
12859 Binder.restoreCallingIdentity(identity);
12860 }
12861 }
12862
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012863 /**
12864 * Get the component name of the default app to direct respond-via-message intent for the
12865 * user associated with this subscription, update the cache if there is no respond-via-message
12866 * application currently configured for this user.
12867 * @return component name of the app and class to direct Respond Via Message intent to, or
12868 * {@code null} if the functionality is not supported.
12869 * @hide
12870 */
12871 @Override
12872 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12873 boolean updateIfNeeded) {
12874 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012875
joonhunshin4ac60942023-11-15 15:23:39 +000012876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12877 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12878 "getDefaultRespondViaMessageApplication");
12879
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012880 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12881
Grant Menkeb0372492024-09-19 18:01:29 -070012882 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12883 UserHandle mainUser = null;
12884 Context userContext = null;
12885 final long identity = Binder.clearCallingIdentity();
12886 try {
12887 mainUser = mUserManager.getMainUser();
12888 userContext = context.createContextAsUser(mainUser, 0);
12889 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12890 } finally {
12891 Binder.restoreCallingIdentity(identity);
12892 }
12893 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12894 updateIfNeeded, mainUser);
12895 } else {
12896 UserHandle userHandle = null;
12897 final long identity = Binder.clearCallingIdentity();
12898 try {
12899 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12900 } finally {
12901 Binder.restoreCallingIdentity(identity);
12902 }
12903 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12904 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012905 }
Grant Menkeb0372492024-09-19 18:01:29 -070012906
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012907 }
Jack Yuf5badd92022-12-08 00:50:53 -080012908
12909 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012910 * Set whether the device is able to connect with null ciphering or integrity
12911 * algorithms. This is a global setting and will apply to all active subscriptions
12912 * and all new subscriptions after this.
12913 *
12914 * @param enabled when true, null cipher and integrity algorithms are allowed.
12915 * @hide
12916 */
12917 @Override
12918 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12919 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12920 enforceModifyPermission();
12921 checkForNullCipherAndIntegritySupport();
12922
12923 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12924 // for listening to these preference changes and applying them immediately.
12925 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12926 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12927 editor.apply();
12928
12929 for (Phone phone: PhoneFactory.getPhones()) {
12930 phone.handleNullCipherEnabledChange();
12931 }
12932 }
12933
12934
12935 /**
12936 * Get whether the device is able to connect with null ciphering or integrity
12937 * algorithms. Note that this retrieves the phone-global preference and not
12938 * the state of the radio.
12939 *
12940 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12941 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12942 * version for this feature.
12943 * @hide
12944 */
12945 @Override
12946 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12947 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12948 enforceReadPermission();
12949 checkForNullCipherAndIntegritySupport();
12950 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12951 }
12952
12953 private void checkForNullCipherAndIntegritySupport() {
12954 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12955 throw new UnsupportedOperationException(
12956 "Null cipher and integrity operations require HAL 2.1 or above");
12957 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012958 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12959 throw new UnsupportedOperationException(
12960 "Null cipher and integrity operations unsupported by modem");
12961 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012962 }
12963
Gil Cukierman06403e12023-11-29 16:33:03 +000012964 private void checkForIdentifierDisclosureNotificationSupport() {
12965 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12966 throw new UnsupportedOperationException(
12967 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12968 + "above");
12969 }
12970 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12971 throw new UnsupportedOperationException(
12972 "Cellular identifier disclosure transparency operations unsupported by modem");
12973 }
12974 }
12975
Michael Groover826b71d2023-12-21 22:08:06 -060012976 private void checkForNullCipherNotificationSupport() {
12977 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12978 throw new UnsupportedOperationException(
12979 "Null cipher notification operations require HAL 2.2 or above");
12980 }
12981 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12982 throw new UnsupportedOperationException(
12983 "Null cipher notification operations unsupported by modem");
12984 }
12985 }
12986
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012987 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012988 * Get the SIM state for the slot index.
12989 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12990 *
12991 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12992 */
12993 @Override
12994 @SimState
12995 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012996 if (!mApp.getResources().getBoolean(
12997 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12999 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13000 }
joonhunshin4ac60942023-11-15 15:23:39 +000013001
Jack Yuf5badd92022-12-08 00:50:53 -080013002 IccCardConstants.State simState;
13003 if (slotIndex < 0) {
13004 simState = IccCardConstants.State.UNKNOWN;
13005 } else {
13006 Phone phone = null;
13007 try {
13008 phone = PhoneFactory.getPhone(slotIndex);
13009 } catch (IllegalStateException e) {
13010 // ignore
13011 }
13012 if (phone == null) {
13013 simState = IccCardConstants.State.UNKNOWN;
13014 } else {
13015 IccCard icc = phone.getIccCard();
13016 if (icc == null) {
13017 simState = IccCardConstants.State.UNKNOWN;
13018 } else {
13019 simState = icc.getState();
13020 }
13021 }
13022 }
13023 return simState.ordinal();
13024 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013025
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013026 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13027 boolean enableLogcat,
13028 long logcatStartTimestampMillis, boolean enableTelecomDump,
13029 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013030 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013031 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13032 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13033 ecdDataBuilder
13034 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13035 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013036 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013037 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013038 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013039 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13040 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013041 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13042 Executors.newCachedThreadPool(), db,
13043 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013044 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013045 }
13046
13047 /**
13048 * Request telephony to persist state for debugging emergency call failures.
13049 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013050 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013051 * @param enableLogcat whether to collect logcat output
13052 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13053 * @param enableTelecomDump whether to collect telecom dumpsys
13054 * @param enableTelephonyDump whether to collect telephony dumpsys
13055 */
13056 @Override
13057 @RequiresPermission(android.Manifest.permission.DUMP)
13058 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13059 long logcatStartTimestampMillis, boolean enableTelecomDump,
13060 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013061 // Verify that the caller has READ_DROPBOX_DATA permission.
13062 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13063 && Flags.enableReadDropboxPermission()) {
13064 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13065 "persistEmergencyCallDiagnosticData");
13066 } else {
13067 // Otherwise, enforce legacy permission.
13068 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13069 "persistEmergencyCallDiagnosticData");
13070 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013071 final long identity = Binder.clearCallingIdentity();
13072 try {
13073 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13074 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13075
13076 } finally {
13077 Binder.restoreCallingIdentity(identity);
13078 }
13079 }
13080
Hui Wang9b5793a2022-12-05 14:38:06 -060013081 /**
13082 * Get current cell broadcast ranges.
13083 */
13084 @Override
13085 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13086 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13087 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13088 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013089
13090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13091 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13092
Hui Wang9b5793a2022-12-05 14:38:06 -060013093 final long identity = Binder.clearCallingIdentity();
13094 try {
13095 return getPhone(subId).getCellBroadcastIdRanges();
13096 } finally {
13097 Binder.restoreCallingIdentity(identity);
13098 }
13099 }
13100
13101 /**
13102 * Set reception of cell broadcast messages with the list of the given ranges
13103 *
13104 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13105 */
13106 @Override
13107 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13108 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13109 @Nullable IIntegerConsumer callback) {
13110 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13111 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013112
13113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13114 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13115
Hui Wang9b5793a2022-12-05 14:38:06 -060013116 final long identity = Binder.clearCallingIdentity();
13117 try {
13118 Phone phone = getPhoneFromSubId(subId);
13119 if (DBG) {
13120 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13121 }
13122 phone.setCellBroadcastIdRanges(ranges, result -> {
13123 if (callback != null) {
13124 try {
13125 callback.accept(result);
13126 } catch (RemoteException e) {
13127 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13128 }
13129 }
13130 });
13131 } finally {
13132 Binder.restoreCallingIdentity(identity);
13133 }
13134 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013135
13136 /**
13137 * Returns whether the device supports the domain selection service.
13138 *
13139 * @return {@code true} if the device supports the domain selection service.
13140 */
13141 @Override
13142 public boolean isDomainSelectionSupported() {
13143 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13144 "isDomainSelectionSupported");
13145
13146 final long identity = Binder.clearCallingIdentity();
13147 try {
13148 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13149 } finally {
13150 Binder.restoreCallingIdentity(identity);
13151 }
13152 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013153
13154 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013155 * Returns whether the AOSP domain selection service is supported.
13156 *
13157 * @return {@code true} if the AOSP domain selection service is supported,
13158 * {@code false} otherwise.
13159 */
13160 @Override
13161 public boolean isAospDomainSelectionService() {
13162 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13163 "isAospDomainSelectionService");
13164
13165 final long identity = Binder.clearCallingIdentity();
13166 try {
13167 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13168 String dssComponentName = mApp.getResources().getString(
13169 R.string.config_domain_selection_service_component_name);
13170 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13171 TelephonyDomainSelectionService.class.getName());
13172 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13173 + ", aosp=" + componentName.flattenToString());
13174 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13175 }
13176 } finally {
13177 Binder.restoreCallingIdentity(identity);
13178 }
13179 return false;
13180 }
13181
13182 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013183 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13184 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13185 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013186 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013187 * @param enableSatellite {@code true} to enable the satellite modem and
13188 * {@code false} to disable.
13189 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013190 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013191 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013192 *
13193 * @throws SecurityException if the caller doesn't have the required permission.
13194 */
13195 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013196 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013197 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013198 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013199 if (enableSatellite) {
13200 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13201 @Override
13202 protected void onReceiveResult(int resultCode, Bundle resultData) {
13203 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13204 + ", resultData=" + resultData);
13205 boolean isAllowed = false;
13206 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13207 callback::accept);
13208 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13209 if (resultData != null
13210 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13211 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13212 } else {
13213 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13214 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013215 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013216 result.accept(resultCode);
13217 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013218 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013219 if (isAllowed) {
13220 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013221 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013222 } else {
13223 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13224 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013225 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013226 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013227 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
youngtaecha2e6cfdd2024-09-04 04:59:10 +000013228 resultReceiver, true);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013229 } else {
13230 // No need to check if satellite is allowed at current location when disabling satellite
13231 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013232 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013233 }
Sarah Chin503828c2023-02-01 23:54:20 -080013234 }
13235
13236 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013237 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013238 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013239 * @param result The result receiver that returns whether the satellite modem is enabled
13240 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013241 *
13242 * @throws SecurityException if the caller doesn't have the required permission.
13243 */
13244 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013245 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013246 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013247 mSatelliteController.requestIsSatelliteEnabled(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013248 }
13249
13250 /**
Sarah Chin43457982023-02-15 17:50:38 -080013251 * Request to get whether the satellite service demo mode is enabled.
13252 *
Sarah Chin43457982023-02-15 17:50:38 -080013253 * @param result The result receiver that returns whether the satellite demo mode is enabled
13254 * if the request is successful or an error code if the request failed.
13255 *
13256 * @throws SecurityException if the caller doesn't have the required permission.
13257 */
13258 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013259 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013260 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013261 mSatelliteController.requestIsDemoModeEnabled(result);
Sarah Chin43457982023-02-15 17:50:38 -080013262 }
13263
13264 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013265 * Request to get whether the satellite service is enabled with emergency mode.
13266 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013267 * @param result The result receiver that returns whether the satellite emergency mode is
13268 * enabled if the request is successful or an error code if the request failed.
13269 *
13270 * @throws SecurityException if the caller doesn't have the required permission.
13271 */
13272 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013273 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013274 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013275 mSatelliteController.requestIsEmergencyModeEnabled(result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013276 }
13277
13278 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013279 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013280 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013281 * @param result The result receiver that returns whether the satellite service is supported on
13282 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013283 */
13284 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013285 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
13286 mSatelliteController.requestIsSatelliteSupported(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013287 }
13288
13289 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013290 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013291 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013292 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13293 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013294 *
13295 * @throws SecurityException if the caller doesn't have required permission.
13296 */
13297 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013298 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013299 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
joonhunshin83da7cd2024-08-22 08:53:35 +000013300 mSatelliteController.requestSatelliteCapabilities(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013301 }
13302
13303 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013304 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013305 * This can be called by the pointing UI when the user starts pointing to the satellite.
13306 * Modem should continue to report the pointing input as the device or satellite moves.
13307 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013308 * @param resultCallback The callback to get the result of the request.
13309 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013310 *
13311 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013312 */
13313 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013314 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013315 @NonNull IIntegerConsumer resultCallback,
13316 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13317 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013318 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013319 }
13320
13321 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013322 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013323 * This can be called by the pointing UI when the user stops pointing to the satellite.
13324 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013325 * @param resultCallback The callback to get the result of the request.
13326 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013327 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013328 *
13329 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013330 */
13331 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013332 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013333 @NonNull IIntegerConsumer resultCallback,
13334 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13335 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013336 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013337 }
13338
13339 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013340 * Register the subscription with a satellite provider.
13341 * This is needed to register the subscription if the provider allows dynamic registration.
13342 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013343 * @param token The token to be used as a unique identifier for provisioning with satellite
13344 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013345 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013346 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013347 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013348 * @return The signal transport used by the caller to cancel the provision request,
13349 * or {@code null} if the request failed.
13350 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013351 * @throws SecurityException if the caller doesn't have the required permission.
13352 */
13353 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013354 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013355 @NonNull String token, @NonNull byte[] provisionData,
13356 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013357 enforceSatelliteCommunicationPermission("provisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013358 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013359 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013360 }
13361
13362 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013363 * Unregister the device/subscription with the satellite provider.
13364 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013365 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013366 * should report as deprovisioned.
13367 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013368 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013369 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013370 *
13371 * @throws SecurityException if the caller doesn't have the required permission.
13372 */
13373 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013374 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013375 @NonNull String token, @NonNull IIntegerConsumer callback) {
13376 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013377 mSatelliteController.deprovisionSatelliteService(token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013378 }
13379
13380 /**
Sarah Chin43457982023-02-15 17:50:38 -080013381 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013382 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013383 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013384 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013385 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013386 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013387 * @throws SecurityException if the caller doesn't have the required permission.
13388 */
13389 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013390 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013391 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013392 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013393 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013394 }
13395
13396 /**
Sarah Chin43457982023-02-15 17:50:38 -080013397 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013398 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013400 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013401 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013402 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013403 * @throws SecurityException if the caller doesn't have the required permission.
13404 */
13405 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013406 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013407 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013408 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013409 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013410 }
13411
13412 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013413 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013414 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013415 * @param result The result receiver that returns whether the device is provisioned with a
13416 * satellite provider if the request is successful or an error code if the
13417 * request failed.
13418 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013419 * @throws SecurityException if the caller doesn't have the required permission.
13420 */
13421 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013422 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013423 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
joonhunshin83da7cd2024-08-22 08:53:35 +000013424 mSatelliteController.requestIsSatelliteProvisioned(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013425 }
13426
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013427 /**
Sarah Chin43457982023-02-15 17:50:38 -080013428 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013429 *
Sarah Chin43457982023-02-15 17:50:38 -080013430 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013431 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013432 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013433 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013434 * @throws SecurityException if the caller doesn't have the required permission.
13435 */
13436 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013437 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013438 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013439 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013440 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013441 }
13442
13443 /**
Sarah Chin43457982023-02-15 17:50:38 -080013444 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013445 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013446 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013447 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013448 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013449 *
13450 * @throws SecurityException if the caller doesn't have the required permission.
13451 */
13452 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013453 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013454 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013455 mSatelliteController.unregisterForModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013456 }
13457
13458 /**
13459 * Register to receive incoming datagrams over satellite.
13460 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013461 * @param callback The callback to handle incoming datagrams over satellite.
13462 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013463 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013464 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013465 * @throws SecurityException if the caller doesn't have the required permission.
13466 */
13467 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013468 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013469 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013470 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013471 return mSatelliteController.registerForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013472 }
13473
13474 /**
13475 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013476 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013477 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013478 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013479 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013480 *
13481 * @throws SecurityException if the caller doesn't have the required permission.
13482 */
13483 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013484 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013485 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013486 mSatelliteController.unregisterForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013487 }
13488
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013489 /**
13490 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013491 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013492 * This method requests modem to check if there are any pending datagrams to be received over
13493 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013494 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013495 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013496 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013497 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013498 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013499 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013500 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013501 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
joonhunshin83da7cd2024-08-22 08:53:35 +000013502 mSatelliteController.pollPendingDatagrams(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013503 }
13504
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013505 /**
13506 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013507 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013508 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13509 * input to this method. Datagram received here will be passed down to modem without any
13510 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013511 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013512 * @param datagramType datagram type indicating whether the datagram is of type
13513 * SOS_SMS or LOCATION_SHARING.
13514 * @param datagram encoded gateway datagram which is encrypted by the caller.
13515 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013516 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13517 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013518 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013519 *
13520 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013521 */
13522 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013523 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013524 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13525 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013526 enforceSatelliteCommunicationPermission("sendDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013527 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013528 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013529 }
13530
Sarah Chindf715ec2023-02-13 13:46:24 -080013531 /**
13532 * Request to get whether satellite communication is allowed for the current location.
13533 *
13534 * @param subId The subId of the subscription to check whether satellite communication is
13535 * allowed for the current location for.
13536 * @param result The result receiver that returns whether satellite communication is allowed
13537 * for the current location if the request is successful or an error code
13538 * if the request failed.
13539 *
13540 * @throws SecurityException if the caller doesn't have the required permission.
13541 */
13542 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013543 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013544 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013545 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
youngtaecha2e6cfdd2024-09-04 04:59:10 +000013546 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, false);
Sarah Chindf715ec2023-02-13 13:46:24 -080013547 }
13548
13549 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013550 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013551 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013552 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013553 * be visible if the request is successful or an error code if the request failed.
13554 *
13555 * @throws SecurityException if the caller doesn't have the required permission.
13556 */
13557 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013558 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013559 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
joonhunshin83da7cd2024-08-22 08:53:35 +000013560 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013561 }
13562
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013563 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013564 * Inform that Device is aligned to satellite for demo mode.
13565 *
Hakjun Choiae365972023-04-25 11:00:31 +000013566 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13567 * {@code false} Device fails to align with the satellite for demo mode.
13568 *
13569 * @throws SecurityException if the caller doesn't have required permission.
13570 */
13571 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13572
joonhunshin83da7cd2024-08-22 08:53:35 +000013573 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013574 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
joonhunshin83da7cd2024-08-22 08:53:35 +000013575 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013576 }
13577
13578 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013579 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13580 * by modem.
13581 *
13582 * @param subId The subId of the subscription to request for.
13583 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013584 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013585 * operation.
13586 *
13587 * @throws SecurityException if the caller doesn't have required permission.
13588 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013589 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013590 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13591 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013592 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013593 final long identity = Binder.clearCallingIdentity();
13594 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013595 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013596 } finally {
13597 Binder.restoreCallingIdentity(identity);
13598 }
13599 }
13600
13601 /**
13602 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13603 * by modem.
13604 *
13605 * @param subId The subId of the subscription to request for.
13606 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013607 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013608 * operation.
13609 *
13610 * @throws SecurityException if the caller doesn't have required permission.
13611 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013612 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013613 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13614 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013615 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013616 final long identity = Binder.clearCallingIdentity();
13617 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013618 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013619 } finally {
13620 Binder.restoreCallingIdentity(identity);
13621 }
13622 }
13623
13624 /**
13625 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013626 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013627 *
13628 * @param subId The subId of the subscription to request for.
13629 *
13630 * @return Integer array of reasons for disallowing satellite communication.
13631 *
13632 * @throws SecurityException if the caller doesn't have the required permission.
13633 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013634 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013635 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013636 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013637 final long identity = Binder.clearCallingIdentity();
13638 try {
13639 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013640 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013641 return reasonSet.stream().mapToInt(i->i).toArray();
13642 } finally {
13643 Binder.restoreCallingIdentity(identity);
13644 }
13645 }
13646
13647 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013648 * Request to get the signal strength of the satellite connection.
13649 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013650 * @param result Result receiver to get the error code of the request and the current signal
13651 * strength of the satellite connection.
13652 *
13653 * @throws SecurityException if the caller doesn't have required permission.
13654 */
13655 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013656 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013657 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13658 final long identity = Binder.clearCallingIdentity();
13659 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013660 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013661 } finally {
13662 Binder.restoreCallingIdentity(identity);
13663 }
13664 }
13665
13666 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013667 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13668 * is not successful, a {@link ServiceSpecificException} that contains
13669 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013670 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013671 * @param callback The callback to handle the NTN signal strength changed event. If the
13672 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13673 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13674 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13675 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013676 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013677 * @throws SecurityException If the caller doesn't have the required permission.
13678 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013679 */
13680 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013681 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013682 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013683 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13684 final long identity = Binder.clearCallingIdentity();
13685 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013686 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013687 } finally {
13688 Binder.restoreCallingIdentity(identity);
13689 }
13690 }
13691
13692 /**
13693 * Unregisters for NTN signal strength changed from satellite modem.
13694 * If callback was not registered before, the request will be ignored.
13695 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013696 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013697 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013698 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013699 *
13700 * @throws SecurityException if the caller doesn't have the required permission.
13701 */
13702 @Override
13703 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013704 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013705 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13706 final long identity = Binder.clearCallingIdentity();
13707 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013708 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013709 } finally {
13710 Binder.restoreCallingIdentity(identity);
13711 }
13712 }
13713
13714 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013715 * Registers for satellite capabilities change event from the satellite service.
13716 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013717 * @param callback The callback to handle the satellite capabilities changed event.
13718 *
13719 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13720 *
13721 * @throws SecurityException if the caller doesn't have required permission.
13722 */
13723 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013724 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013725 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013726 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013727 final long identity = Binder.clearCallingIdentity();
13728 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013729 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013730 } finally {
13731 Binder.restoreCallingIdentity(identity);
13732 }
13733 }
13734
13735 /**
13736 * Unregisters for satellite capabilities change event from the satellite service.
13737 * If callback was not registered before, the request will be ignored.
13738 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013739 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013740 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013741 *
13742 * @throws SecurityException if the caller doesn't have required permission.
13743 */
13744 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013745 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013746 @NonNull ISatelliteCapabilitiesCallback callback) {
13747 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013748 final long identity = Binder.clearCallingIdentity();
13749 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013750 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013751 } finally {
13752 Binder.restoreCallingIdentity(identity);
13753 }
13754 }
13755
13756 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013757 * Registers for the satellite supported state changed.
13758 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013759 * @param callback The callback to handle the satellite supported state changed event.
13760 *
13761 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13762 *
13763 * @throws SecurityException if the caller doesn't have the required permission.
13764 */
13765 @Override
13766 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013767 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013768 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013769 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013770 }
13771
13772 /**
13773 * Unregisters for the satellite supported state changed.
13774 * If callback was not registered before, the request will be ignored.
13775 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013776 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013777 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000013778 *
13779 * @throws SecurityException if the caller doesn't have the required permission.
13780 */
13781 @Override
13782 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013783 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013784 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013785 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013786 }
13787
13788 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013789 * This API can be used by only CTS to update satellite vendor service package name.
13790 *
13791 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013792 * @param provisioned Whether satellite should be provisioned or not.
13793 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013794 * @return {@code true} if the satellite vendor service is set successfully,
13795 * {@code false} otherwise.
13796 */
Hakjun Choic3393242024-06-26 18:02:08 +000013797 public boolean setSatelliteServicePackageName(String servicePackageName,
13798 String provisioned) {
13799 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13800 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013801 TelephonyPermissions.enforceShellOnly(
13802 Binder.getCallingUid(), "setSatelliteServicePackageName");
13803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13804 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13805 "setSatelliteServicePackageName");
Hakjun Choic3393242024-06-26 18:02:08 +000013806 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13807 provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013808 }
13809
13810 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013811 * This API can be used by only CTS to update satellite gateway service package name.
13812 *
13813 * @param servicePackageName The package name of the satellite gateway service.
13814 * @return {@code true} if the satellite gateway service is set successfully,
13815 * {@code false} otherwise.
13816 */
13817 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13818 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13819 TelephonyPermissions.enforceShellOnly(
13820 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13822 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13823 "setSatelliteGatewayServicePackageName");
13824 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13825 }
13826
13827 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013828 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13829 *
13830 * @param packageName The package name of the satellite pointing UI app.
13831 * @param className The class name of the satellite pointing UI app.
13832 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13833 * {@code false} otherwise.
13834 */
13835 public boolean setSatellitePointingUiClassName(
13836 @Nullable String packageName, @Nullable String className) {
13837 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13838 + ", className=" + className);
13839 TelephonyPermissions.enforceShellOnly(
13840 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13842 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13843 "setSatelliteGatewayServicePackageName");
13844 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13845 }
13846
13847 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013848 * This API can be used by only CTS to update the timeout duration in milliseconds that
13849 * satellite should stay at listening mode to wait for the next incoming page before disabling
13850 * listening mode.
13851 *
13852 * @param timeoutMillis The timeout duration in millisecond.
13853 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13854 */
13855 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13856 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13857 TelephonyPermissions.enforceShellOnly(
13858 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13860 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13861 "setSatelliteListeningTimeoutDuration");
13862 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13863 }
13864
13865 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013866 * This API can be used by only CTS to override the timeout durations used by the
13867 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013868 *
13869 * @param timeoutMillis The timeout duration in millisecond.
13870 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13871 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013872 public boolean setDatagramControllerTimeoutDuration(
13873 boolean reset, int timeoutType, long timeoutMillis) {
13874 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13875 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013876 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013877 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13879 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013880 "setDatagramControllerTimeoutDuration");
13881 return mSatelliteController.setDatagramControllerTimeoutDuration(
13882 reset, timeoutType, timeoutMillis);
13883 }
13884
13885 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013886 * This API can be used by only CTS to override the boolean configs used by the
13887 * DatagramController module.
13888 *
13889 * @param enable Whether to enable or disable boolean config.
13890 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13891 */
13892 public boolean setDatagramControllerBooleanConfig(
13893 boolean reset, int booleanType, boolean enable) {
13894 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13895 + ", reset=" + reset + ", enable=" + enable);
13896 TelephonyPermissions.enforceShellOnly(
13897 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13899 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13900 "ssetDatagramControllerBooleanConfig");
13901 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13902 }
13903
13904
13905 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013906 * This API can be used by only CTS to override the timeout durations used by the
13907 * SatelliteController module.
13908 *
13909 * @param timeoutMillis The timeout duration in millisecond.
13910 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13911 */
13912 public boolean setSatelliteControllerTimeoutDuration(
13913 boolean reset, int timeoutType, long timeoutMillis) {
13914 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13915 + reset + ", timeoutMillis=" + timeoutMillis);
13916 TelephonyPermissions.enforceShellOnly(
13917 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13919 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13920 "setSatelliteControllerTimeoutDuration");
13921 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13922 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013923 }
13924
13925 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013926 * This API can be used in only testing to override connectivity status in monitoring emergency
13927 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13928 *
13929 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13930 * of the following values to enable the override:
13931 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13932 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13933 * To disable the override, use -1 for handoverType.
13934 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13935 * delaySeconds after the emergency call starts.
13936 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13937 */
13938 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13939 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13940 TelephonyPermissions.enforceShellOnly(
13941 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13943 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13944 "setEmergencyCallToSatelliteHandoverType");
13945 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13946 handoverType, delaySeconds);
13947 }
13948
13949 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013950 * This API can be used in only testing to override oem-enabled satellite provision status.
13951 *
13952 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13953 * otherwise.
13954 * @param isProvisioned The overriding provision status.
13955 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13956 */
13957 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13958 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13959 + ", isProvisioned=" + isProvisioned);
13960 TelephonyPermissions.enforceShellOnly(
13961 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13963 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13964 "setOemEnabledSatelliteProvisionStatus");
13965 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13966 }
13967
13968 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013969 * This API should be used by only CTS tests to forcefully set telephony country codes.
13970 *
13971 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13972 */
13973 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13974 Map cachedNetworkCountryCodes, String locationCountryCode,
13975 long locationCountryCodeTimestampNanos) {
13976 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13977 + String.join(", ", currentNetworkCountryCodes)
13978 + ", locationCountryCode=" + locationCountryCode
13979 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13980 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13981 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13982 TelephonyPermissions.enforceShellOnly(
13983 Binder.getCallingUid(), "setCachedLocationCountryCode");
13984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13985 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13986 "setCachedLocationCountryCode");
youngtaecha31b141d2024-07-15 12:01:39 +000013987 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), mFeatureFlags)
13988 .setCountryCodes(reset, currentNetworkCountryCodes, cachedNetworkCountryCodes,
13989 locationCountryCode, locationCountryCodeTimestampNanos);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013990 }
13991
13992 /**
13993 * This API should be used by only CTS tests to override the overlay configs of satellite
13994 * access controller.
13995 *
13996 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13997 * otherwise.
13998 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13999 */
14000 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14001 String s2CellFile, long locationFreshDurationNanos,
14002 List<String> satelliteCountryCodes) {
14003 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14004 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14005 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14006 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
14007 ? String.join(", ", satelliteCountryCodes) : null));
14008 TelephonyPermissions.enforceShellOnly(
14009 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14011 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14012 "setSatelliteAccessControlOverlayConfigs");
14013 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
14014 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
14015 }
14016
14017 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014018 * This API can be used by only CTS to override the cached value for the device overlay config
14019 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14020 * outgoing satellite datagrams should be sent to modem in demo mode.
14021 *
14022 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14023 * satellite modem or not.
14024 *
14025 * @return {@code true} if the operation is successful, {@code false} otherwise.
14026 */
14027 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14028 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14029 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14030 + "disabled");
14031 return false;
14032 }
14033 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14034 TelephonyPermissions.enforceShellOnly(
14035 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14037 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14038 "setShouldSendDatagramToModemInDemoMode");
14039 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14040 shouldSendToModemInDemoMode);
14041 }
14042
14043 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014044 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14045 *
14046 * @param state a state indicates whether satellite access allowed state should be cached and
14047 * the allowed state.
14048 * @return {@code true} if the setting is successful, {@code false} otherwise.
14049 */
14050 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14051 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14052 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14053 + "oemEnabledSatelliteFlag is disabled");
14054 return false;
14055 }
14056
14057 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14058 + "state=" + state);
14059 TelephonyPermissions.enforceShellOnly(
14060 Binder.getCallingUid(),
14061 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14063 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14064 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14065 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14066 state);
14067 }
14068
14069 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014070 * Sets the service defined in ComponentName to be bound.
14071 *
14072 * This should only be used for testing.
14073 * @return {@code true} if the DomainSelectionService to bind to was set,
14074 * {@code false} otherwise.
14075 */
14076 @Override
14077 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14078 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14079
14080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14081 "setDomainSelectionServiceOverride");
14082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14083 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14084
14085 final long identity = Binder.clearCallingIdentity();
14086 try {
14087 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14088 return DomainSelectionResolver.getInstance()
14089 .setDomainSelectionServiceOverride(componentName);
14090 }
14091 } finally {
14092 Binder.restoreCallingIdentity(identity);
14093 }
14094 return false;
14095 }
14096
14097 /**
14098 * Clears the DomainSelectionService override.
14099 *
14100 * This should only be used for testing.
14101 * @return {@code true} if the DomainSelectionService override was cleared,
14102 * {@code false} otherwise.
14103 */
14104 @Override
14105 public boolean clearDomainSelectionServiceOverride() {
14106 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14107
14108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14109 "clearDomainSelectionServiceOverride");
14110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14111 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14112
14113 final long identity = Binder.clearCallingIdentity();
14114 try {
14115 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14116 return DomainSelectionResolver.getInstance()
14117 .clearDomainSelectionServiceOverride();
14118 }
14119 } finally {
14120 Binder.restoreCallingIdentity(identity);
14121 }
14122 return false;
14123 }
14124
14125 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014126 * Enable or disable notifications sent for cellular identifier disclosure events.
14127 *
14128 * Disclosure events are defined as instances where a device has sent a cellular identifier
14129 * on the Non-access stratum (NAS) before a security context is established. As a result the
14130 * identifier is sent in the clear, which has privacy implications for the user.
14131 *
14132 * @param enable if notifications about disclosure events should be enabled
14133 * @throws SecurityException if the caller does not have the required privileges
14134 * @throws UnsupportedOperationException if the modem does not support this feature.
14135 */
14136 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014137 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014138 enforceModifyPermission();
14139 checkForIdentifierDisclosureNotificationSupport();
14140
14141 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14142 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14143 editor.apply();
14144
14145 // Each phone instance is responsible for updating its respective modem immediately
14146 // after we've made a preference change.
14147 for (Phone phone : PhoneFactory.getPhones()) {
14148 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14149 }
14150 }
14151
14152 /**
14153 * Get whether or not cellular identifier disclosure notifications are enabled.
14154 *
14155 * @throws SecurityException if the caller does not have the required privileges
14156 * @throws UnsupportedOperationException if the modem does not support this feature.
14157 */
14158 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014159 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014160 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14161 checkForIdentifierDisclosureNotificationSupport();
14162 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14163 }
14164
14165 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014166 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14167 * are in use by the cellular modem.
14168 *
14169 * @throws IllegalStateException if the Telephony process is not currently available
14170 * @throws SecurityException if the caller does not have the required privileges
14171 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14172 * and integrity algorithms in use
14173 * @hide
14174 */
14175 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014176 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014177 enforceModifyPermission();
14178 checkForNullCipherNotificationSupport();
14179
14180 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14181 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14182 editor.apply();
14183
14184 // Each phone instance is responsible for updating its respective modem immediately
14185 // after a preference change.
14186 for (Phone phone : PhoneFactory.getPhones()) {
14187 phone.handleNullCipherNotificationPreferenceChanged();
14188 }
14189 }
14190
14191 /**
14192 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14193 * cellular modem.
14194 *
14195 * @throws IllegalStateException if the Telephony process is not currently available
14196 * @throws SecurityException if the caller does not have the required privileges
14197 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14198 * and integrity algorithms in use
14199 * @hide
14200 */
14201 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14202 public boolean isNullCipherNotificationsEnabled() {
14203 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14204 checkForNullCipherNotificationSupport();
14205 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14206 }
14207
14208 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014209 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14210 *
14211 * <p>This method behaves in one of the following ways:
14212 * <ul>
14213 * <li>return true : if the calling package has the appop permission {@link
14214 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14215 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14216 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14217 * Owner device identifier access check, or the calling package has carrier privileges</>
14218 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14219 * </ul>
14220 */
14221 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14222 String callingPackage, @Nullable String callingFeatureId, String message) {
14223 for (Phone phone : PhoneFactory.getPhones()) {
14224 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14225 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14226 return true;
14227 }
14228 }
14229 return false;
14230 }
arunvoddud7401012022-12-15 16:08:12 +000014231
14232 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014233 * @return The subscription manager service instance.
14234 */
14235 public SubscriptionManagerService getSubscriptionManagerService() {
14236 return SubscriptionManagerService.getInstance();
14237 }
14238
14239 /**
arunvoddud7401012022-12-15 16:08:12 +000014240 * Class binds the consumer[callback] and carrierId.
14241 */
14242 private static class CallerCallbackInfo {
14243 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014244 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014245
Steve Statia28b7cb32024-03-11 23:58:50 +000014246 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014247 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014248 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014249 }
14250
14251 public Consumer<Integer> getConsumer() {
14252 return mConsumer;
14253 }
14254
Steve Statia28b7cb32024-03-11 23:58:50 +000014255 public Set<Integer> getCarrierIds() {
14256 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014257 }
14258 }
joonhunshin4ac60942023-11-15 15:23:39 +000014259
14260 /*
14261 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14262 * But the context that is passed in is unused if the phone app is already alive.
14263 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14264 */
14265 @VisibleForTesting
14266 public void setPackageManager(PackageManager packageManager) {
14267 mPackageManager = packageManager;
14268 }
14269
14270 /*
Nate Myren453c3472024-03-13 11:28:11 -070014271 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14272 * But the context that is passed in is unused if the phone app is already alive.
14273 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14274 */
14275 @VisibleForTesting
14276 public void setAppOpsManager(AppOpsManager appOps) {
14277 mAppOps = appOps;
14278 }
14279
14280 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014281 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14282 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14283 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14284 */
14285 @VisibleForTesting
14286 public void setFeatureFlags(FeatureFlags featureFlags) {
14287 mFeatureFlags = featureFlags;
14288 }
14289
14290 /**
14291 * Make sure the device has required telephony feature
14292 *
14293 * @throws UnsupportedOperationException if the device does not have required telephony feature
14294 */
14295 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14296 @NonNull String telephonyFeature, @NonNull String methodName) {
14297 if (callingPackage == null || mPackageManager == null) {
14298 return;
14299 }
14300
14301 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14302 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014303 Binder.getCallingUserHandle())
14304 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14305 // Skip to check associated telephony feature,
14306 // if compatibility change is not enabled for the current process or
14307 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014308 return;
14309 }
14310
14311 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14312 throw new UnsupportedOperationException(
14313 methodName + " is unsupported without " + telephonyFeature);
14314 }
14315 }
youngtaecha5d483d52024-04-29 17:05:45 +000014316
14317 /**
14318 * Registers for the satellite communication allowed state changed.
14319 *
14320 * @param subId The subId of the subscription to register for the satellite communication
14321 * allowed state changed.
14322 * @param callback The callback to handle the satellite communication allowed
14323 * state changed event.
14324 *
14325 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14326 *
14327 * @throws SecurityException if the caller doesn't have the required permission.
14328 */
14329 @Override
14330 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14331 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14332 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014333 final long identity = Binder.clearCallingIdentity();
14334 try {
14335 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14336 subId, callback);
14337 } finally {
14338 Binder.restoreCallingIdentity(identity);
14339 }
youngtaecha5d483d52024-04-29 17:05:45 +000014340 }
14341
14342 /**
14343 * Unregisters for the satellite communication allowed state changed.
14344 * If callback was not registered before, the request will be ignored.
14345 *
14346 * @param subId The subId of the subscription to unregister for the satellite communication
14347 * allowed state changed.
14348 * @param callback The callback that was passed to
14349 * {@link #registerForCommunicationAllowedStateChanged(int,
14350 * ISatelliteCommunicationAllowedStateCallback)}. *
14351 * @throws SecurityException if the caller doesn't have the required permission.
14352 */
14353 @Override
14354 public void unregisterForCommunicationAllowedStateChanged(
14355 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14356 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014357 final long identity = Binder.clearCallingIdentity();
14358 try {
14359 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14360 callback);
14361 } finally {
14362 Binder.restoreCallingIdentity(identity);
14363 }
youngtaecha5d483d52024-04-29 17:05:45 +000014364 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014365
14366 /**
14367 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14368 *
14369 * @param subId The subId of the subscription to the satellite session stats for.
14370 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14371 * if the request is successful or an error code if the request failed.
14372 *
14373 * @throws SecurityException if the caller doesn't have required permission.
14374 */
14375 @Override
14376 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14377 enforceModifyPermission();
14378 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014379 final long identity = Binder.clearCallingIdentity();
14380 try {
14381 mSatelliteController.requestSatelliteSessionStats(subId, result);
14382 } finally {
14383 Binder.restoreCallingIdentity(identity);
14384 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014385 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014386
14387 /**
14388 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14389 *
14390 * @param result The result receiver, which returns the list of prioritized satellite tokens
14391 * to be used for provision if the request is successful or an error code if the request failed.
14392 *
14393 * @throws SecurityException if the caller doesn't have the required permission.
14394 */
14395 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014396 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14397 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014398 final long identity = Binder.clearCallingIdentity();
14399 try {
14400 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14401 } finally {
14402 Binder.restoreCallingIdentity(identity);
14403 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014404 }
14405
14406 /**
14407 * Deliver the list of provisioned satellite subscriber ids.
14408 *
14409 * @param list List of provisioned satellite subscriber ids.
14410 * @param result The result receiver that returns whether deliver success or fail.
14411 *
14412 * @throws SecurityException if the caller doesn't have the required permission.
14413 */
14414 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014415 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014416 @NonNull ResultReceiver result) {
14417 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014418 final long identity = Binder.clearCallingIdentity();
14419 try {
14420 mSatelliteController.provisionSatellite(list, result);
14421 } finally {
14422 Binder.restoreCallingIdentity(identity);
14423 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014424 }
Hyosund6aaf062024-08-23 23:02:10 +000014425
14426 /**
14427 * This API can be used by only CTS to override the cached value for the device overlay config
14428 * value :
14429 * config_satellite_gateway_service_package and
14430 * config_satellite_carrier_roaming_esos_provisioned_class.
14431 * These values are set before sending an intent to broadcast there are any change to list of
14432 * subscriber informations.
14433 *
14434 * @param name the name is one of the following that constitute an intent.
14435 * Component package name, or component class name.
14436 * @return {@code true} if the setting is successful, {@code false} otherwise.
14437 */
14438 @Override
14439 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14440 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14441 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14442 + " carrierRoamingNbIotNtn is disabled");
14443 return false;
14444 }
14445 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14446 TelephonyPermissions.enforceShellOnly(
14447 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14449 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14450 "setSatelliteSubscriberIdListChangedIntentComponent");
14451 final long identity = Binder.clearCallingIdentity();
14452 try {
14453 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14454 } finally {
14455 Binder.restoreCallingIdentity(identity);
14456 }
14457 }
Jack Yufa8ed012023-02-11 15:42:28 -080014458}