blob: cf83585a99e366440c2d6fdafa0f2a5dfac60f2b [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
28import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080029
Shuo Qianccbaf742021-02-22 18:32:21 -080030import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
31import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070032import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070033import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000034import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070035
Brad Ebinger34c09a52021-02-17 23:23:21 +000036import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080037import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080038import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070039import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080041import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080043import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070044import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000045import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080046import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000047import android.compat.annotation.ChangeId;
48import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000049import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070050import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070051import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.content.Context;
53import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070055import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070056import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.net.Uri;
58import android.os.AsyncResult;
59import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080060import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080062import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070064import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080065import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080066import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.Looper;
68import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070069import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080070import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070071import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080073import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080074import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070075import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070076import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080077import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000078import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000159import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteDatagramCallback;
Duke Lee8852e512024-10-06 12:55:43 +0900161import android.telephony.satellite.ISatelliteDisallowedReasonsCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000162import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000164import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800165import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Daniel Banta93320242024-11-21 00:34:41 +0000166import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000167import android.telephony.satellite.NtnSignalStrength;
168import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800169import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000170import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800172import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800173import android.telephony.satellite.SatelliteProvisionStateCallback;
Hyosun Kimb11f3ea2024-08-07 23:35:59 +0000174import android.telephony.satellite.SatelliteSubscriberInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700177import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800179import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800180
Andrew Lee312e8172014-10-23 17:01:36 -0700181import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800182import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800183import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800184import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800185import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700187import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700188import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800189import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800190import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700191import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800193import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700194import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800195import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800196import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800197import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700198import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000199import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700200import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800201import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800203import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800204import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800205import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700206import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700207import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700208import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700210import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800211import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700212import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700213import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700214import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700215import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800216import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800217import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700218import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000219import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700220import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700221import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800222import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800223import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800224import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700225import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000226import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800227import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700228import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700229import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800230import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700231import com.android.internal.telephony.imsphone.ImsPhone;
232import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000233import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800234import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000235import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800236import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
237import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700238import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700239import com.android.internal.telephony.uicc.IccIoResult;
240import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700242import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800243import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700244import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000245import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800246import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000247import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800248import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000249import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700250import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700251import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800252import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800253import com.android.phone.callcomposer.CallComposerPictureManager;
254import com.android.phone.callcomposer.CallComposerPictureTransfer;
255import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800256import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000257import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700258import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700259import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000260import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800262import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700263import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700264import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800265import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800266import com.android.services.telephony.TelecomAccountRegistry;
267import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000268import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800269import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800270
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700272import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800273import java.io.IOException;
274import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700275import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800277import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000278import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800279import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800280import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800281import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800282import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100283import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800284import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700285import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800286import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800287import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700288import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800289import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800290import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800291import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
293/**
294 * Implementation of the ITelephony interface.
295 */
Santos Cordon117fee72014-05-16 17:56:12 -0700296public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 private static final String LOG_TAG = "PhoneInterfaceManager";
298 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
299 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800300 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301
302 // Message codes used with mMainThreadHandler
303 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700304 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
305 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700306 private static final int CMD_OPEN_CHANNEL = 9;
307 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
308 private static final int CMD_CLOSE_CHANNEL = 11;
309 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800310 private static final int CMD_NV_READ_ITEM = 13;
311 private static final int EVENT_NV_READ_ITEM_DONE = 14;
312 private static final int CMD_NV_WRITE_ITEM = 15;
313 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
314 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
315 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700316 private static final int CMD_RESET_MODEM_CONFIG = 19;
317 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800318 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
319 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800320 private static final int CMD_SEND_ENVELOPE = 25;
321 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700322 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
323 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
324 private static final int CMD_EXCHANGE_SIM_IO = 31;
325 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800326 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
327 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700328 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
329 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700330 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
331 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700332 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
333 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
334 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
335 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700336 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
337 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
338 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
339 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700340 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800341 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
342 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000343 private static final int CMD_SWITCH_SLOTS = 50;
344 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700345 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
346 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
347 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
348 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
349 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
350 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
351 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
352 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700353 private static final int CMD_GET_ALL_CELL_INFO = 60;
354 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
355 private static final int CMD_GET_CELL_LOCATION = 62;
356 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700357 private static final int CMD_MODEM_REBOOT = 64;
358 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700359 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
360 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800361 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
362 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700363 private static final int CMD_GET_MODEM_STATUS = 70;
364 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700365 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
366 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700367 private static final int CMD_ERASE_MODEM_CONFIG = 74;
368 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800369 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
370 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
371 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
372 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800373 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
374 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800375 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800376 private static final int CMD_GET_CALL_FORWARDING = 83;
377 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
378 private static final int CMD_SET_CALL_FORWARDING = 85;
379 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
380 private static final int CMD_GET_CALL_WAITING = 87;
381 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
382 private static final int CMD_SET_CALL_WAITING = 89;
383 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700384 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
385 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
386 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
387 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700388 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
389 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800390 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
391 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800392 private static final int CMD_SET_DATA_THROTTLING = 99;
393 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800394 private static final int CMD_SET_SIM_POWER = 101;
395 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800396 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
397 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
398 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
399 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800400 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
401 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000402 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800403 private static final int CMD_GET_SLICING_CONFIG = 110;
404 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800405 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700406 private static final int CMD_ENABLE_VONR = 113;
407 private static final int EVENT_ENABLE_VONR_DONE = 114;
408 private static final int CMD_IS_VONR_ENABLED = 115;
409 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700410 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
411 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000412
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800413 // Parameters of select command.
414 private static final int SELECT_COMMAND = 0xA4;
415 private static final int SELECT_P1 = 0x04;
416 private static final int SELECT_P2 = 0;
417 private static final int SELECT_P3 = 0x10;
418
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000419 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
420 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000421 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
422 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600423 // Null cipher notification support was added in IRadioNetwork 2.2
424 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000425
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 /** The singleton instance. */
427 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800428 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429
Sarah Chin4beb2b72023-02-14 14:47:54 -0800430 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000431 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800432 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final CallManager mCM;
434 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000435
436 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800437 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800439 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800440 private final SharedPreferences mTelephonySharedPreferences;
441 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800442 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700443 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000444 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000445 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446
Jack Yu26735292024-09-25 14:33:49 -0700447 @Nullable
448 private ComponentName mTestEuiccUiComponent;
449
Peter Wangdafb9ac2020-01-15 14:13:38 -0800450 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800451 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800452 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800453 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800454
Derek Tan97ebb422014-09-05 16:55:38 -0700455 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
456 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800457 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800458 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700459
Michelecea4cf22018-12-21 15:00:11 -0800460 // String to store multi SIM allowed
461 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
462
Derek Tan740e1672017-06-27 14:56:27 -0700463 // The AID of ISD-R.
464 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
465
yinxub1bed742017-04-17 11:45:04 -0700466 private NetworkScanRequestTracker mNetworkScanRequestTracker;
467
David Kelly5e06a7f2018-03-12 14:10:59 +0000468 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
469 private static final int MANUFACTURER_CODE_LENGTH = 8;
470
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800471 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800472 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800473
Sarah Chin2ec39f62022-08-31 17:03:26 -0700474 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
475 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
476
Derek Tan89e89d42014-07-08 17:00:10 -0700477 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700478 * Experiment flag to enable erase modem config on reset network, default value is false
479 */
480 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
481 "reset_network_erase_modem_config_enabled";
482
Nathan Harolddc3bcec2024-05-16 14:06:40 -0700483 private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800484
Gary Jian76280a42022-12-07 16:18:33 +0800485 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
486
arunvoddub1365e62024-07-31 09:42:31 +0000487 private static final int LINE1_NUMBER_MAX_LEN = 50;
488
sandeepjsb6c87872021-09-27 15:34:44 +0000489 /**
490 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
491 * one ICCID active at the same time.
492 * Apps should use below API signatures if targeting SDK is T and beyond.
493 *
494 * @hide
495 */
496 @ChangeId
497 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
498 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800499
Naina Nallurid63128d2019-09-17 14:10:30 -0700500 /**
Chen Xu540470b2021-12-14 17:15:47 -0800501 * Apps targeting on Android T and beyond will get exception whenever icc close channel
502 * operation fails.
503 */
504 @ChangeId
505 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
506 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
507
508 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 * A request object to use for transmitting data to an ICC.
510 */
511 private static final class IccAPDUArgument {
512 public int channel, cla, command, p1, p2, p3;
513 public String data;
514
515 public IccAPDUArgument(int channel, int cla, int command,
516 int p1, int p2, int p3, String data) {
517 this.channel = channel;
518 this.cla = cla;
519 this.command = command;
520 this.p1 = p1;
521 this.p2 = p2;
522 this.p3 = p3;
523 this.data = data;
524 }
525 }
526
527 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700528 * A request object to use for transmitting data to an ICC.
529 */
530 private static final class ManualNetworkSelectionArgument {
531 public OperatorInfo operatorInfo;
532 public boolean persistSelection;
533
534 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
535 this.operatorInfo = operatorInfo;
536 this.persistSelection = persistSelection;
537 }
538 }
539
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 private static final class PurchasePremiumCapabilityArgument {
541 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700542 public @NonNull IIntegerConsumer callback;
543
544 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800545 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700546 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700547 this.callback = callback;
548 }
549 }
550
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700551 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
553 * request after sending. The main thread will notify the request when it is complete.
554 */
555 private static final class MainThreadRequest {
556 /** The argument to use for the request */
557 public Object argument;
558 /** The result of the request that is run on the main thread */
559 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800560 // The subscriber id that this request applies to. Defaults to
561 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
562 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563
Nathan Harold92bed182018-10-12 18:16:49 -0700564 // In cases where subId is unavailable, the caller needs to specify the phone.
565 public Phone phone;
566
vagdeviaf9a5b92018-08-15 16:01:53 -0700567 public WorkSource workSource;
568
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 public MainThreadRequest(Object argument) {
570 this.argument = argument;
571 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800572
Nathan Harold92bed182018-10-12 18:16:49 -0700573 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
574 this.argument = argument;
575 if (phone != null) {
576 this.phone = phone;
577 }
578 this.workSource = workSource;
579 }
580
vagdeviaf9a5b92018-08-15 16:01:53 -0700581 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800582 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800583 if (subId != null) {
584 this.subId = subId;
585 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700586 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700588 }
589
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800590 private static final class IncomingThirdPartyCallArgs {
591 public final ComponentName component;
592 public final String callId;
593 public final String callerDisplayName;
594
595 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
596 String callerDisplayName) {
597 this.component = component;
598 this.callId = callId;
599 this.callerDisplayName = callerDisplayName;
600 }
601 }
602
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 /**
604 * A handler that processes messages on the main thread in the phone process. Since many
605 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
606 * inbound binder threads to the main thread in the phone process. The Binder thread
607 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
608 * on, which will be notified when the operation completes and will contain the result of the
609 * request.
610 *
611 * <p>If a MainThreadRequest object is provided in the msg.obj field,
612 * note that request.result must be set to something non-null for the calling thread to
613 * unblock.
614 */
615 private final class MainThreadHandler extends Handler {
616 @Override
617 public void handleMessage(Message msg) {
618 MainThreadRequest request;
619 Message onCompleted;
620 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800623 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624
625 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 case CMD_HANDLE_USSD_REQUEST: {
627 request = (MainThreadRequest) msg.obj;
628 final Phone phone = getPhoneFromRequest(request);
629 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800630 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700632
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 if (!isUssdApiAllowed(request.subId)) {
634 // Carrier does not support use of this API, return failure.
635 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
636 UssdResponse response = new UssdResponse(ussdRequest, null);
637 Bundle returnData = new Bundle();
638 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
639 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700640
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 request.result = true;
642 notifyRequester(request);
643 return;
644 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700645
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 try {
647 request.result = phone != null
648 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
649 } catch (CallStateException cse) {
650 request.result = false;
651 }
652 // Wake up the requesting thread
653 notifyRequester(request);
654 break;
pkanwar32d516d2016-10-14 19:37:38 -0700655 }
656
Yorke Lee716f67e2015-06-17 15:39:16 -0700657 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700659 final Phone phone = getPhoneFromRequest(request);
660 request.result = phone != null ?
661 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
662 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort = getUiccPortFromRequest(request);
672 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800674 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000679 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800680 iccArgument.channel, iccArgument.cla, iccArgument.command,
681 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
682 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
689 if (ar.exception == null && ar.result != null) {
690 request.result = ar.result;
691 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 if (ar.result == null) {
694 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800695 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800697 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 } else {
699 loge("iccTransmitApduLogicalChannel: Unknown exception");
700 }
701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 break;
704
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
707 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000708 uiccPort = getUiccPortFromRequest(request);
709 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800711 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 } else {
714 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000716 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800717 iccArgument.cla, iccArgument.command, iccArgument.p1,
718 iccArgument.p2,
719 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 }
721 break;
722
723 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
726 if (ar.exception == null && ar.result != null) {
727 request.result = ar.result;
728 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800729 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 if (ar.result == null) {
731 loge("iccTransmitApduBasicChannel: Empty response");
732 } else if (ar.exception instanceof CommandException) {
733 loge("iccTransmitApduBasicChannel: CommandException: " +
734 ar.exception);
735 } else {
736 loge("iccTransmitApduBasicChannel: Unknown exception");
737 }
738 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 break;
741
742 case CMD_EXCHANGE_SIM_IO:
743 request = (MainThreadRequest) msg.obj;
744 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000745 uiccPort = getUiccPortFromRequest(request);
746 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700747 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800748 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
752 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000753 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
755 iccArgument.data, onCompleted);
756 }
757 break;
758
759 case EVENT_EXCHANGE_SIM_IO_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 if (ar.exception == null && ar.result != null) {
763 request.result = ar.result;
764 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800765 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700768 break;
769
Derek Tan4d5e5c12014-02-04 11:54:58 -0800770 case CMD_SEND_ENVELOPE:
771 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 uiccPort = getUiccPortFromRequest(request);
773 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800775 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 } else {
778 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800779 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700780 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800781 break;
782
783 case EVENT_SEND_ENVELOPE_DONE:
784 ar = (AsyncResult) msg.obj;
785 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700786 if (ar.exception == null && ar.result != null) {
787 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800788 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800789 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700790 if (ar.result == null) {
791 loge("sendEnvelopeWithStatus: Empty response");
792 } else if (ar.exception instanceof CommandException) {
793 loge("sendEnvelopeWithStatus: CommandException: " +
794 ar.exception);
795 } else {
796 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
797 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800798 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800800 break;
801
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 case CMD_OPEN_CHANNEL:
803 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000804 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800805 IccLogicalChannelRequest openChannelRequest =
806 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000807 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700808 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800809 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800810 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700811 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700812 } else {
813 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800814 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
815 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 break;
818
819 case EVENT_OPEN_CHANNEL_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700822 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700823 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700824 int[] result = (int[]) ar.result;
825 int channelId = result[0];
826 byte[] selectResponse = null;
827 if (result.length > 1) {
828 selectResponse = new byte[result.length - 1];
829 for (int i = 1; i < result.length; ++i) {
830 selectResponse[i - 1] = (byte) result[i];
831 }
832 }
833 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800834 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800835
836 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700837 if (uiccPort == null) {
838 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
839 } else {
840 IccLogicalChannelRequest channelRequest =
841 (IccLogicalChannelRequest) request.argument;
842 channelRequest.channel = channelId;
843 uiccPort.onLogicalChannelOpened(channelRequest);
844 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700845 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 if (ar.result == null) {
847 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700849 if (ar.exception != null) {
850 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
851 }
852
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700854 if (ar.exception instanceof CommandException) {
855 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800856 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700857 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700858 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700859 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700860 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700861 }
862 }
863 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800864 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700865 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700866 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700867 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 break;
869
870 case CMD_CLOSE_CHANNEL:
871 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000872 uiccPort = getUiccPortFromRequest(request);
873 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700874 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800875 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800876 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800877 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700878 } else {
879 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000880 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700881 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700882 break;
883
884 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null) {
888 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800889 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700890 if (uiccPort == null) {
891 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
892 } else {
893 final int channelId = (Integer) request.argument;
894 uiccPort.onLogicalChannelClosed(channelId);
895 }
Chen Xu540470b2021-12-14 17:15:47 -0800896 } else {
897 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800898 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800899 if (ar.exception instanceof CommandException) {
900 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
901 CommandException.Error error =
902 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800903 if (error == CommandException.Error.INVALID_ARGUMENTS) {
904 // should only throw exceptions from the binder threads.
905 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800906 "iccCloseLogicalChannel: invalid argument ");
907 }
908 } else {
909 loge("iccCloseLogicalChannel: Unknown exception");
910 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800911 request.result = (exception != null) ? exception :
912 new IllegalStateException(
913 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800914 }
915 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
918 case CMD_NV_READ_ITEM:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
922 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800923 break;
924
925 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800931 request.result = "";
932 if (ar.result == null) {
933 loge("nvReadItem: Empty response");
934 } else if (ar.exception instanceof CommandException) {
935 loge("nvReadItem: CommandException: " +
936 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700937 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800938 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700942 break;
943
Jake Hambye994d462014-02-03 13:10:13 -0800944 case CMD_NV_WRITE_ITEM:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
947 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800948 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700949 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800950 break;
951
952 case EVENT_NV_WRITE_ITEM_DONE:
953 handleNullReturnEvent(msg, "nvWriteItem");
954 break;
955
956 case CMD_NV_WRITE_CDMA_PRL:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800959 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800960 break;
961
962 case EVENT_NV_WRITE_CDMA_PRL_DONE:
963 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
964 break;
965
chen xu6dac5ab2018-10-26 17:39:23 -0700966 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800967 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700968 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800969 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800970 break;
971
chen xu6dac5ab2018-10-26 17:39:23 -0700972 case EVENT_RESET_MODEM_CONFIG_DONE:
973 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800974 break;
975
Sooraj Sasindran37444802020-08-11 10:40:43 -0700976 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
979 request);
980 Phone phone = getPhoneFromRequest(request);
981 if (phone != null) {
982 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
983 } else {
984 loge("isNRDualConnectivityEnabled: No phone object");
985 request.result = false;
986 notifyRequester(request);
987 }
988 break;
989 }
990
991 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 if (ar.exception == null && ar.result != null) {
995 request.result = ar.result;
996 } else {
997 // request.result must be set to something non-null
998 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700999 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001000 request.result = ar.result;
1001 } else {
1002 request.result = false;
1003 }
1004 if (ar.result == null) {
1005 loge("isNRDualConnectivityEnabled: Empty response");
1006 } else if (ar.exception instanceof CommandException) {
1007 loge("isNRDualConnectivityEnabled: CommandException: "
1008 + ar.exception);
1009 } else {
1010 loge("isNRDualConnectivityEnabled: Unknown exception");
1011 }
1012 }
1013 notifyRequester(request);
1014 break;
1015
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001016 case CMD_IS_VONR_ENABLED: {
1017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1019 request);
1020 Phone phone = getPhoneFromRequest(request);
1021 if (phone != null) {
1022 phone.isVoNrEnabled(onCompleted, request.workSource);
1023 } else {
1024 loge("isVoNrEnabled: No phone object");
1025 request.result = false;
1026 notifyRequester(request);
1027 }
1028 break;
1029 }
1030
1031 case EVENT_IS_VONR_ENABLED_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 if (ar.exception == null && ar.result != null) {
1035 request.result = ar.result;
1036 } else {
1037 // request.result must be set to something non-null
1038 // for the calling thread to unblock
1039 if (ar.result != null) {
1040 request.result = ar.result;
1041 } else {
1042 request.result = false;
1043 }
1044 if (ar.result == null) {
1045 loge("isVoNrEnabled: Empty response");
1046 } else if (ar.exception instanceof CommandException) {
1047 loge("isVoNrEnabled: CommandException: "
1048 + ar.exception);
1049 } else {
1050 loge("isVoNrEnabled: Unknown exception");
1051 }
1052 }
1053 notifyRequester(request);
1054 break;
1055
Sooraj Sasindran37444802020-08-11 10:40:43 -07001056 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1057 request = (MainThreadRequest) msg.obj;
1058 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1059 Phone phone = getPhoneFromRequest(request);
1060 if (phone != null) {
1061 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1062 request.workSource);
1063 } else {
1064 loge("enableNrDualConnectivity: No phone object");
1065 request.result =
1066 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1067 notifyRequester(request);
1068 }
1069 break;
1070 }
1071
1072 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null) {
1076 request.result =
1077 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1078 } else {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1082 if (ar.exception instanceof CommandException) {
1083 CommandException.Error error =
1084 ((CommandException) (ar.exception)).getCommandError();
1085 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1086 request.result =
1087 TelephonyManager
1088 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001089 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1090 request.result =
1091 TelephonyManager
1092 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001093 }
1094 loge("enableNrDualConnectivity" + ": CommandException: "
1095 + ar.exception);
1096 } else {
1097 loge("enableNrDualConnectivity" + ": Unknown exception");
1098 }
1099 }
1100 notifyRequester(request);
1101 break;
1102 }
1103
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001104 case CMD_ENABLE_VONR: {
1105 request = (MainThreadRequest) msg.obj;
1106 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1107 Phone phone = getPhoneFromRequest(request);
1108 if (phone != null) {
1109 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1110 request.workSource);
1111 } else {
1112 loge("setVoNrEnabled: No phone object");
1113 request.result =
1114 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1115 notifyRequester(request);
1116 }
1117 break;
1118 }
1119
1120 case EVENT_ENABLE_VONR_DONE: {
1121 ar = (AsyncResult) msg.obj;
1122 request = (MainThreadRequest) ar.userObj;
1123 if (ar.exception == null) {
1124 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1125 } else {
1126 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1131 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1132 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1133 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1134 } else {
1135 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1136 }
1137 loge("setVoNrEnabled" + ": CommandException: "
1138 + ar.exception);
1139 } else {
1140 loge("setVoNrEnabled" + ": Unknown exception");
1141 }
1142 }
1143 notifyRequester(request);
1144 break;
1145 }
1146
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001149 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1150 request);
1151 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 break;
1153
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
1157 if (ar.exception == null && ar.result != null) {
1158 request.result = ar.result; // Integer
1159 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301160 // request.result must be set to something non-null
1161 // for the calling thread to unblock
1162 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001165 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001166 loge("getAllowedNetworkTypesBitmask: CommandException: "
1167 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001170 }
1171 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001172 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001173 break;
1174
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001176 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001177 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1178 request);
1179 Pair<Integer, Long> reasonWithNetworkTypes =
1180 (Pair<Integer, Long>) request.argument;
1181 getPhoneFromRequest(request).setAllowedNetworkTypes(
1182 reasonWithNetworkTypes.first,
1183 reasonWithNetworkTypes.second,
1184 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001185 break;
1186
SongFerngWang3ef3e072020-12-21 16:41:52 +08001187 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1188 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001189 break;
1190
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001191 case CMD_SET_VOICEMAIL_NUMBER:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1194 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001195 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1196 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001197 break;
1198
1199 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1200 handleNullReturnEvent(msg, "setVoicemailNumber");
1201 break;
1202
Stuart Scott54788802015-03-30 13:18:01 -07001203 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1206 request);
1207 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1208 break;
1209
1210 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1211 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1212 break;
1213
Shishir Agrawal302c8692015-06-19 13:49:39 -07001214 case CMD_PERFORM_NETWORK_SCAN:
1215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1217 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1218 break;
1219
Hall Liu27d24262020-09-18 19:04:59 -07001220 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001221 request = (MainThreadRequest) msg.obj;
1222 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001223 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1224 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1225 request.argument;
1226 int callForwardingReason = args.first;
1227 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
1230 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001231 ar = (AsyncResult) msg.obj;
1232 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001233 TelephonyManager.CallForwardingInfoCallback callback =
1234 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1235 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001236 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001237 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001238 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1239 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1240 // Service Class is a bit mask per 3gpp 27.007. Search for
1241 // any service for voice call.
1242 if ((callForwardInfo.serviceClass
1243 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001244 callForwardingInfo = new CallForwardingInfo(
1245 callForwardInfo.status
1246 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001247 callForwardInfo.reason,
1248 callForwardInfo.number,
1249 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 break;
1251 }
1252 }
1253 // Didn't find a call forward info for voice call.
1254 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001255 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1256 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
Hall Liu27d24262020-09-18 19:04:59 -07001258 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 } else {
1260 if (ar.result == null) {
1261 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1262 }
1263 if (ar.exception != null) {
1264 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1265 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 int errorCode = TelephonyManager
1267 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 if (ar.exception instanceof CommandException) {
1269 CommandException.Error error =
1270 ((CommandException) (ar.exception)).getCommandError();
1271 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001272 errorCode = TelephonyManager
1273 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001274 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 errorCode = TelephonyManager
1276 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
1278 }
Hall Liu27d24262020-09-18 19:04:59 -07001279 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shuo Qian4a594052020-01-23 11:59:30 -08001283
Hall Liu27d24262020-09-18 19:04:59 -07001284 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001285 request = (MainThreadRequest) msg.obj;
1286 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001287 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001288 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001289 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1290 request.argument).first;
1291 request.phone.setCallForwardingOption(
1292 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001293 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001294 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001295 callForwardingInfoToSet.getReason(),
1296 callForwardingInfoToSet.getNumber(),
1297 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1298 break;
Hall Liu27d24262020-09-18 19:04:59 -07001299 }
Shuo Qian4a594052020-01-23 11:59:30 -08001300
Hall Liu27d24262020-09-18 19:04:59 -07001301 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001304 Consumer<Integer> callback =
1305 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1306 request.argument).second;
1307 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001309 int errorCode = TelephonyManager.CallForwardingInfoCallback
1310 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001311 if (ar.exception instanceof CommandException) {
1312 CommandException.Error error =
1313 ((CommandException) (ar.exception)).getCommandError();
1314 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001315 errorCode = TelephonyManager.CallForwardingInfoCallback
1316 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001317 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001318 errorCode = TelephonyManager.CallForwardingInfoCallback
1319 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001320 }
1321 }
1322 callback.accept(errorCode);
1323 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001324 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001325 }
Shuo Qian4a594052020-01-23 11:59:30 -08001326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 request = (MainThreadRequest) msg.obj;
1331 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1332 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shuo Qian4a594052020-01-23 11:59:30 -08001335
Hall Liu27d24262020-09-18 19:04:59 -07001336 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001339 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001342 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001343 // Service Class is a bit mask per 3gpp 27.007.
1344 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001345 if (callForwardResults.length > 1
1346 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001347 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001348 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001349 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1350 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001351 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001352 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001353 }
1354 } else {
1355 if (ar.result == null) {
1356 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1357 }
1358 if (ar.exception != null) {
1359 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1360 }
1361 if (ar.exception instanceof CommandException) {
1362 CommandException.Error error =
1363 ((CommandException) (ar.exception)).getCommandError();
1364 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001365 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001366 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001367 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1368 callWaitingStatus =
1369 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001370 }
1371 }
1372 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001373 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001374 break;
Hall Liu27d24262020-09-18 19:04:59 -07001375 }
Shuo Qian4a594052020-01-23 11:59:30 -08001376
Hall Liu27d24262020-09-18 19:04:59 -07001377 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001378 request = (MainThreadRequest) msg.obj;
1379 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001380 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1381 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001382 break;
Hall Liu27d24262020-09-18 19:04:59 -07001383 }
Shuo Qian4a594052020-01-23 11:59:30 -08001384
Hall Liu27d24262020-09-18 19:04:59 -07001385 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001388 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1389 Consumer<Integer> callback =
1390 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1391 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001392 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001393 if (ar.exception instanceof CommandException) {
1394 CommandException.Error error =
1395 ((CommandException) (ar.exception)).getCommandError();
1396 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1397 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001398 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1399 callback.accept(
1400 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001401 } else {
1402 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1403 }
1404 } else {
1405 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1406 }
1407 } else {
1408 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1409 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001410 }
Shuo Qian4a594052020-01-23 11:59:30 -08001411 break;
Hall Liu27d24262020-09-18 19:04:59 -07001412 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001413 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
1416 CellNetworkScanResult cellScanResult;
1417 if (ar.exception == null && ar.result != null) {
1418 cellScanResult = new CellNetworkScanResult(
1419 CellNetworkScanResult.STATUS_SUCCESS,
1420 (List<OperatorInfo>) ar.result);
1421 } else {
1422 if (ar.result == null) {
1423 loge("getCellNetworkScanResults: Empty response");
1424 }
1425 if (ar.exception != null) {
1426 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1427 }
1428 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1429 if (ar.exception instanceof CommandException) {
1430 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001431 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1433 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1434 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1435 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1436 }
1437 }
1438 cellScanResult = new CellNetworkScanResult(errorCode, null);
1439 }
1440 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001441 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001442 break;
1443
1444 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1445 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001446 ManualNetworkSelectionArgument selArg =
1447 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001448 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1449 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001450 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1451 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001452 break;
1453
1454 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
1457 if (ar.exception == null) {
1458 request.result = true;
1459 } else {
1460 request.result = false;
1461 loge("setNetworkSelectionModeManual " + ar.exception);
1462 }
1463 notifyRequester(request);
1464 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001465 break;
1466
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 case CMD_GET_MODEM_ACTIVITY_INFO:
1468 request = (MainThreadRequest) msg.obj;
1469 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001470 if (defaultPhone != null) {
1471 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 } else {
1473 ResultReceiver result = (ResultReceiver) request.argument;
1474 Bundle bundle = new Bundle();
1475 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001476 new ModemActivityInfo(0, 0, 0,
1477 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001479 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 break;
1481
Hall Liud0f208c2020-10-14 16:54:44 -07001482 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 ar = (AsyncResult) msg.obj;
1484 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001485 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001486 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001487 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001488 if (mLastModemActivityInfo == null) {
1489 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1490 mLastModemActivitySpecificInfo[0] =
1491 new ActivityStatsTechSpecificInfo(
1492 0,
1493 0,
1494 new int[ModemActivityInfo.getNumTxPowerLevels()],
1495 0);
1496 mLastModemActivityInfo =
1497 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1498 }
1499
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001500 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001501 // Update the last modem activity info and the result of the request.
1502 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1503 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001504 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001505 } else {
1506 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001507 }
Kai Shi917fdc62022-11-28 14:01:02 -08001508 // This is needed to decouple ret from mLastModemActivityInfo
1509 // We don't want to return mLastModemActivityInfo which is updated
1510 // inside mergeModemActivityInfo()
1511 ret = new ModemActivityInfo(
1512 mLastModemActivityInfo.getTimestampMillis(),
1513 mLastModemActivityInfo.getSleepTimeMillis(),
1514 mLastModemActivityInfo.getIdleTimeMillis(),
1515 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001516
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 } else {
1518 if (ar.result == null) {
1519 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001520 error = TelephonyManager.ModemActivityInfoException
1521 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001523 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001524 error = TelephonyManager.ModemActivityInfoException
1525 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001526 } else {
1527 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001528 error = TelephonyManager.ModemActivityInfoException
1529 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001530 }
1531 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001532 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001533 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001534 bundle.putParcelable(
1535 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001536 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001537 } else {
1538 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1539 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001540 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001541 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001542 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001543 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001544
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001545 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001547 CarrierRestrictionRules argument =
1548 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001550 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001552 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001553
1554 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 if (ar.exception == null && ar.result != null) {
1558 request.result = ar.result;
1559 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001560 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1561 if (ar.exception instanceof CommandException) {
1562 loge("setAllowedCarriers: CommandException: " + ar.exception);
1563 CommandException.Error error =
1564 ((CommandException) (ar.exception)).getCommandError();
1565 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1566 request.result =
1567 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1568 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001569 } else {
1570 loge("setAllowedCarriers: Unknown exception");
1571 }
1572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001574 break;
1575
1576 case CMD_GET_ALLOWED_CARRIERS:
1577 request = (MainThreadRequest) msg.obj;
1578 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001579 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001580 break;
1581
1582 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1583 ar = (AsyncResult) msg.obj;
1584 request = (MainThreadRequest) ar.userObj;
1585 if (ar.exception == null && ar.result != null) {
1586 request.result = ar.result;
1587 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001588 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001589 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001590 if (ar.result == null) {
1591 loge("getAllowedCarriers: Empty response");
1592 } else if (ar.exception instanceof CommandException) {
1593 loge("getAllowedCarriers: CommandException: " +
1594 ar.exception);
1595 } else {
1596 loge("getAllowedCarriers: Unknown exception");
1597 }
1598 }
arunvoddud7401012022-12-15 16:08:12 +00001599 if (request.argument != null) {
1600 // This is for the implementation of carrierRestrictionStatus.
1601 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1602 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001603 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001604 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1605 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1606 CarrierRestrictionRules carrierRestrictionRules =
1607 (CarrierRestrictionRules) ar.result;
1608 int carrierId = -1;
1609 try {
1610 CarrierIdentifier carrierIdentifier =
1611 carrierRestrictionRules.getAllowedCarriers().get(0);
1612 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1613 carrierIdentifier);
1614 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1615 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1616 }
1617 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001618 int restrictedStatus =
1619 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1620 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1621 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001622 lockStatus = TelephonyManager
1623 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001624 }
1625 } else {
1626 Rlog.e(LOG_TAG,
1627 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1628 }
1629 callback.accept(lockStatus);
1630 } else {
1631 // This is for the implementation of getAllowedCarriers.
1632 notifyRequester(request);
1633 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001634 break;
1635
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception == null && ar.result != null) {
1640 request.result = ar.result;
1641 } else {
1642 request.result = new IllegalArgumentException(
1643 "Failed to retrieve Forbidden Plmns");
1644 if (ar.result == null) {
1645 loge("getForbiddenPlmns: Empty response");
1646 } else {
1647 loge("getForbiddenPlmns: Unknown exception");
1648 }
1649 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001650 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 break;
1652
1653 case CMD_GET_FORBIDDEN_PLMNS:
1654 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001655 uiccPort = getUiccPortFromRequest(request);
1656 if (uiccPort == null) {
1657 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001659 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001660 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001661 break;
1662 }
1663 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001664 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001665 if (uiccApp == null) {
1666 loge("getForbiddenPlmns() no app with specified type -- "
1667 + appType);
1668 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001670 break;
1671 } else {
1672 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1673 + " specified type -- " + appType);
1674 }
1675 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1676 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001677 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001678 break;
1679
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 case CMD_SWITCH_SLOTS:
1681 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001682 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001683 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001684 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001685 break;
1686
1687 case EVENT_SWITCH_SLOTS_DONE:
1688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001691 notifyRequester(request);
1692 break;
1693 case CMD_GET_NETWORK_SELECTION_MODE:
1694 request = (MainThreadRequest) msg.obj;
1695 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1696 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1697 break;
1698
1699 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1700 ar = (AsyncResult) msg.obj;
1701 request = (MainThreadRequest) ar.userObj;
1702 if (ar.exception != null) {
1703 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1704 } else {
1705 int mode = ((int[]) ar.result)[0];
1706 if (mode == 0) {
1707 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1708 } else {
1709 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1710 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001712 notifyRequester(request);
1713 break;
1714 case CMD_GET_CDMA_ROAMING_MODE:
1715 request = (MainThreadRequest) msg.obj;
1716 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1717 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1718 break;
1719 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 if (ar.exception != null) {
1723 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1724 } else {
1725 request.result = ((int[]) ar.result)[0];
1726 }
1727 notifyRequester(request);
1728 break;
1729 case CMD_SET_CDMA_ROAMING_MODE:
1730 request = (MainThreadRequest) msg.obj;
1731 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1732 int mode = (int) request.argument;
1733 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1734 break;
1735 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 request.result = ar.exception == null;
1739 notifyRequester(request);
1740 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001741 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1744 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1745 break;
1746 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1747 ar = (AsyncResult) msg.obj;
1748 request = (MainThreadRequest) ar.userObj;
1749 if (ar.exception != null) {
1750 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1751 } else {
1752 request.result = ((int[]) ar.result)[0];
1753 }
1754 notifyRequester(request);
1755 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001756 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1757 request = (MainThreadRequest) msg.obj;
1758 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1759 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001760 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1761 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001762 break;
1763 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 request.result = ar.exception == null;
1767 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001768 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 case CMD_GET_ALL_CELL_INFO:
1770 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001771 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001772 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001773 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001774 case EVENT_GET_ALL_CELL_INFO_DONE:
1775 ar = (AsyncResult) msg.obj;
1776 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001777 // If a timeout occurs, the response will be null
1778 request.result = (ar.exception == null && ar.result != null)
1779 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001780 synchronized (request) {
1781 request.notifyAll();
1782 }
1783 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001784 case CMD_REQUEST_CELL_INFO_UPDATE:
1785 request = (MainThreadRequest) msg.obj;
1786 request.phone.requestCellInfoUpdate(request.workSource,
1787 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1788 break;
1789 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1790 ar = (AsyncResult) msg.obj;
1791 request = (MainThreadRequest) ar.userObj;
1792 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1793 try {
1794 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001795 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001796 cb.onError(
1797 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1798 ar.exception.getClass().getName(),
1799 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001800 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001801 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001802 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001803 } else {
1804 // use the result as returned
1805 cb.onCellInfo((List<CellInfo>) ar.result);
1806 }
1807 } catch (RemoteException re) {
1808 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1809 }
1810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 request = (MainThreadRequest) msg.obj;
1813 WorkSource ws = (WorkSource) request.argument;
1814 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001815 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001816 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001817 }
1818 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
1821 if (ar.exception == null) {
1822 request.result = ar.result;
1823 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001824 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001825 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001826 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001827 }
1828
1829 synchronized (request) {
1830 request.notifyAll();
1831 }
1832 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001833 }
chen xu6dac5ab2018-10-26 17:39:23 -07001834 case CMD_MODEM_REBOOT:
1835 request = (MainThreadRequest) msg.obj;
1836 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001837 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001838 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001839 case EVENT_CMD_MODEM_REBOOT_DONE:
1840 handleNullReturnEvent(msg, "rebootModem");
1841 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001842 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001843 request = (MainThreadRequest) msg.obj;
1844 boolean enable = (boolean) request.argument;
1845 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001846 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001847 PhoneConfigurationManager.getInstance()
1848 .enablePhone(request.phone, enable, onCompleted);
1849 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001850 }
Michele Berionne5e411512020-11-13 02:36:59 +00001851 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001855 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001856 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001857 if ((boolean) request.result) {
1858 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1859 updateModemStateMetrics();
1860 } else {
1861 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1862 + ar.exception);
1863 }
1864 notifyRequester(request);
1865 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001866 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001867 case CMD_GET_MODEM_STATUS:
1868 request = (MainThreadRequest) msg.obj;
1869 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1870 PhoneConfigurationManager.getInstance()
1871 .getPhoneStatusFromModem(request.phone, onCompleted);
1872 break;
1873 case EVENT_GET_MODEM_STATUS_DONE:
1874 ar = (AsyncResult) msg.obj;
1875 request = (MainThreadRequest) ar.userObj;
1876 int id = request.phone.getPhoneId();
1877 if (ar.exception == null && ar.result != null) {
1878 request.result = ar.result;
1879 //update the cache as modem status has changed
1880 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1881 (boolean) request.result);
1882 } else {
1883 // Return true if modem status cannot be retrieved. For most cases,
1884 // modem status is on. And for older version modems, GET_MODEM_STATUS
1885 // and disable modem are not supported. Modem is always on.
1886 // TODO: this should be fixed in R to support a third
1887 // status UNKNOWN b/131631629
1888 request.result = true;
1889 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1890 + ar.exception);
1891 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001892 notifyRequester(request);
1893 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001894 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1897 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1898 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1899 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1900 break;
1901 }
1902 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1903 ar = (AsyncResult) msg.obj;
1904 request = (MainThreadRequest) ar.userObj;
1905 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1906 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1907 args.second.accept(ar.exception == null);
1908 notifyRequester(request);
1909 break;
1910 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001911 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1914 Phone phone = getPhoneFromRequest(request);
1915 if (phone != null) {
1916 phone.getSystemSelectionChannels(onCompleted);
1917 } else {
1918 loge("getSystemSelectionChannels: No phone object");
1919 request.result = new ArrayList<RadioAccessSpecifier>();
1920 notifyRequester(request);
1921 }
1922 break;
1923 }
1924 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1925 ar = (AsyncResult) msg.obj;
1926 request = (MainThreadRequest) ar.userObj;
1927 if (ar.exception == null && ar.result != null) {
1928 request.result = ar.result;
1929 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001930 request.result = new IllegalStateException(
1931 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001932 if (ar.result == null) {
1933 loge("getSystemSelectionChannels: Empty response");
1934 } else {
1935 loge("getSystemSelectionChannels: Unknown exception");
1936 }
1937 }
1938 notifyRequester(request);
1939 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001940 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception == null && ar.result != null) {
1944 request.result = ar.result;
1945 } else {
1946 request.result = -1;
1947 loge("Failed to set Forbidden Plmns");
1948 if (ar.result == null) {
1949 loge("setForbidenPlmns: Empty response");
1950 } else if (ar.exception != null) {
1951 loge("setForbiddenPlmns: Exception: " + ar.exception);
1952 request.result = -1;
1953 } else {
1954 loge("setForbiddenPlmns: Unknown exception");
1955 }
1956 }
1957 notifyRequester(request);
1958 break;
1959 case CMD_SET_FORBIDDEN_PLMNS:
1960 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001961 uiccPort = getUiccPortFromRequest(request);
1962 if (uiccPort == null) {
1963 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001964 request.result = -1;
1965 notifyRequester(request);
1966 break;
1967 }
1968 Pair<Integer, List<String>> setFplmnsArgs =
1969 (Pair<Integer, List<String>>) request.argument;
1970 appType = setFplmnsArgs.first;
1971 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001972 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001973 if (uiccApp == null) {
1974 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1975 request.result = -1;
1976 loge("Failed to get UICC App");
1977 notifyRequester(request);
1978 } else {
1979 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1980 ((SIMRecords) uiccApp.getIccRecords())
1981 .setForbiddenPlmns(onCompleted, fplmns);
1982 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001983 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001984 case CMD_ERASE_MODEM_CONFIG:
1985 request = (MainThreadRequest) msg.obj;
1986 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1987 defaultPhone.eraseModemConfig(onCompleted);
1988 break;
1989 case EVENT_ERASE_MODEM_CONFIG_DONE:
1990 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001991 break;
zoey chene02881a2019-12-30 16:11:23 +08001992
Kai Shif70f46f2021-03-03 13:59:46 -08001993 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1994 request = (MainThreadRequest) msg.obj;
1995 request.result = defaultPhone.eraseDataInSharedPreferences();
1996 notifyRequester(request);
1997 break;
1998
zoey chene02881a2019-12-30 16:11:23 +08001999 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2000 request = (MainThreadRequest) msg.obj;
2001 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2002 Pair<String, String> changed = (Pair<String, String>) request.argument;
2003 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2004 changed.first, changed.second, onCompleted);
2005 break;
2006 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 if (ar.exception == null) {
2010 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002011 // If the operation is successful, update the PIN storage
2012 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2013 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002014 UiccController.getInstance().getPinStorage()
2015 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002016 } else {
2017 request.result = msg.arg1;
2018 }
2019 notifyRequester(request);
2020 break;
2021
Michele Berionne5e411512020-11-13 02:36:59 +00002022 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002023 request = (MainThreadRequest) msg.obj;
2024 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2025 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2026 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2027 enabled.first, enabled.second, onCompleted);
2028 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002029 }
zoey chene02881a2019-12-30 16:11:23 +08002030 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2031 ar = (AsyncResult) msg.obj;
2032 request = (MainThreadRequest) ar.userObj;
2033 if (ar.exception == null) {
2034 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002035 // If the operation is successful, update the PIN storage
2036 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2037 int phoneId = getPhoneFromRequest(request).getPhoneId();
2038 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002039 UiccController.getInstance().getPinStorage()
2040 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002041 } else {
2042 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2043 }
zoey chene02881a2019-12-30 16:11:23 +08002044 } else {
2045 request.result = msg.arg1;
2046 }
Michele Berionne5e411512020-11-13 02:36:59 +00002047
2048
zoey chene02881a2019-12-30 16:11:23 +08002049 notifyRequester(request);
2050 break;
2051
Peter Wangdafb9ac2020-01-15 14:13:38 -08002052 case MSG_NOTIFY_USER_ACTIVITY:
2053 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002054 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002055 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2056 getDefaultPhone().getContext().sendBroadcastAsUser(
2057 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2058 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002059
2060 case CMD_SET_DATA_THROTTLING: {
2061 request = (MainThreadRequest) msg.obj;
2062 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2063 DataThrottlingRequest dataThrottlingRequest =
2064 (DataThrottlingRequest) request.argument;
2065 Phone phone = getPhoneFromRequest(request);
2066 if (phone != null) {
2067 phone.setDataThrottling(onCompleted,
2068 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2069 dataThrottlingRequest.getCompletionDurationMillis());
2070 } else {
2071 loge("setDataThrottling: No phone object");
2072 request.result =
2073 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2074 notifyRequester(request);
2075 }
2076
2077 break;
2078 }
2079 case EVENT_SET_DATA_THROTTLING_DONE:
2080 ar = (AsyncResult) msg.obj;
2081 request = (MainThreadRequest) ar.userObj;
2082
2083 if (ar.exception == null) {
2084 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2085 } else if (ar.exception instanceof CommandException) {
2086 loge("setDataThrottling: CommandException: " + ar.exception);
2087 CommandException.Error error =
2088 ((CommandException) (ar.exception)).getCommandError();
2089
2090 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2091 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002092 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002093 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2094 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002095 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2096 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002097 } else {
2098 request.result =
2099 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2100 }
2101 } else {
2102 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2103 }
2104 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2105 notifyRequester(request);
2106 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002107
2108 case CMD_SET_SIM_POWER: {
2109 request = (MainThreadRequest) msg.obj;
2110 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2111 request = (MainThreadRequest) msg.obj;
2112 int stateToSet =
2113 ((Pair<Integer, IIntegerConsumer>)
2114 request.argument).first;
2115 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2116 break;
2117 }
2118 case EVENT_SET_SIM_POWER_DONE: {
2119 ar = (AsyncResult) msg.obj;
2120 request = (MainThreadRequest) ar.userObj;
2121 IIntegerConsumer callback =
2122 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2123 if (ar.exception != null) {
2124 loge("setSimPower exception: " + ar.exception);
2125 int errorCode = TelephonyManager.CallForwardingInfoCallback
2126 .RESULT_ERROR_UNKNOWN;
2127 if (ar.exception instanceof CommandException) {
2128 CommandException.Error error =
2129 ((CommandException) (ar.exception)).getCommandError();
2130 if (error == CommandException.Error.SIM_ERR) {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2132 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2133 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2134 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2135 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2136 } else {
2137 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2138 }
2139 }
2140 try {
2141 callback.accept(errorCode);
2142 } catch (RemoteException e) {
2143 // Ignore if the remote process is no longer available to call back.
2144 Log.w(LOG_TAG, "setSimPower: callback not available.");
2145 }
2146 } else {
2147 try {
2148 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2149 } catch (RemoteException e) {
2150 // Ignore if the remote process is no longer available to call back.
2151 Log.w(LOG_TAG, "setSimPower: callback not available.");
2152 }
2153 }
2154 break;
2155 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002156 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2157 request = (MainThreadRequest) msg.obj;
2158
2159 final Phone phone = getPhoneFromRequest(request);
2160 if (phone == null || phone.getServiceStateTracker() == null) {
2161 request.result = new IllegalStateException("Phone or SST is null");
2162 notifyRequester(request);
2163 break;
2164 }
2165
2166 Pair<Integer, SignalStrengthUpdateRequest> pair =
2167 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2168 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2169 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002170 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002171 request.subId, pair.first /*callingUid*/,
2172 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002173 break;
2174 }
2175 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2176 ar = (AsyncResult) msg.obj;
2177 request = (MainThreadRequest) ar.userObj;
2178 // request.result will be the exception of ar if present, true otherwise.
2179 // Be cautious not to leave result null which will wait() forever
2180 request.result = ar.exception != null ? ar.exception : true;
2181 notifyRequester(request);
2182 break;
2183 }
2184 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2185 request = (MainThreadRequest) msg.obj;
2186
2187 Phone phone = getPhoneFromRequest(request);
2188 if (phone == null || phone.getServiceStateTracker() == null) {
2189 request.result = new IllegalStateException("Phone or SST is null");
2190 notifyRequester(request);
2191 break;
2192 }
2193
2194 Pair<Integer, SignalStrengthUpdateRequest> pair =
2195 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2196 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2197 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002198 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002199 request.subId, pair.first /*callingUid*/,
2200 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002201 break;
2202 }
2203 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2204 ar = (AsyncResult) msg.obj;
2205 request = (MainThreadRequest) ar.userObj;
2206 request.result = ar.exception != null ? ar.exception : true;
2207 notifyRequester(request);
2208 break;
2209 }
Jordan Liu109698e2020-11-24 14:50:34 -08002210
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002211 case CMD_GET_SLICING_CONFIG: {
2212 request = (MainThreadRequest) msg.obj;
2213 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2214 request.phone.getSlicingConfig(onCompleted);
2215 break;
2216 }
2217 case EVENT_GET_SLICING_CONFIG_DONE: {
2218 ar = (AsyncResult) msg.obj;
2219 request = (MainThreadRequest) ar.userObj;
2220 ResultReceiver result = (ResultReceiver) request.argument;
2221
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002223 Bundle bundle = new Bundle();
2224 int resultCode = 0;
2225 if (ar.exception != null) {
2226 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2227 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002228 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 } else if (ar.result == null) {
2230 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002231 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002232 } else {
2233 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002234 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2235 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002236 }
2237
2238 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002239 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002240 }
2241 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2242 result.send(resultCode, bundle);
2243 notifyRequester(request);
2244 break;
2245 }
2246
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 request = (MainThreadRequest) msg.obj;
2249 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 PurchasePremiumCapabilityArgument arg =
2251 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002252 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2253 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 ar = (AsyncResult) msg.obj;
2259 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 PurchasePremiumCapabilityArgument arg =
2261 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002262 try {
2263 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002266 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002267 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002268 + TelephonyManager.convertPurchaseResultToString(result));
2269 } catch (RemoteException e) {
2270 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002271 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002272 + " failed: " + e;
2273 if (DBG) log(logStr);
2274 AnomalyReporter.reportAnomaly(
2275 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2276 }
2277 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002278 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002279
Michele Berionne5e411512020-11-13 02:36:59 +00002280 case CMD_PREPARE_UNATTENDED_REBOOT:
2281 request = (MainThreadRequest) msg.obj;
2282 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002283 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002284 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002285 notifyRequester(request);
2286 break;
2287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 default:
2289 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2290 break;
2291 }
2292 }
Jake Hambye994d462014-02-03 13:10:13 -08002293
Pengquan Menga1bb6272018-09-06 09:59:22 -07002294 private void notifyRequester(MainThreadRequest request) {
2295 synchronized (request) {
2296 request.notifyAll();
2297 }
2298 }
2299
Jake Hambye994d462014-02-03 13:10:13 -08002300 private void handleNullReturnEvent(Message msg, String command) {
2301 AsyncResult ar = (AsyncResult) msg.obj;
2302 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2303 if (ar.exception == null) {
2304 request.result = true;
2305 } else {
2306 request.result = false;
2307 if (ar.exception instanceof CommandException) {
2308 loge(command + ": CommandException: " + ar.exception);
2309 } else {
2310 loge(command + ": Unknown exception");
2311 }
2312 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002313 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 }
2316
2317 /**
2318 * Posts the specified command to be executed on the main thread,
2319 * waits for the request to complete, and returns the result.
2320 * @see #sendRequestAsync
2321 */
2322 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002323 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2324 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002325 }
2326
2327 /**
2328 * Posts the specified command to be executed on the main thread,
2329 * waits for the request to complete, and returns the result.
2330 * @see #sendRequestAsync
2331 */
2332 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2333 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002334 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
2337 /**
2338 * Posts the specified command to be executed on the main thread,
2339 * waits for the request to complete, and returns the result.
2340 * @see #sendRequestAsync
2341 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002342 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002343 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2344 }
2345
2346 /**
2347 * Posts the specified command to be executed on the main thread,
2348 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2349 * if not timeout or null otherwise.
2350 * @see #sendRequestAsync
2351 */
2352 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2353 long timeoutInMs) {
2354 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002355 }
2356
2357 /**
2358 * Posts the specified command to be executed on the main thread,
2359 * waits for the request to complete, and returns the result.
2360 * @see #sendRequestAsync
2361 */
Nathan Harold92bed182018-10-12 18:16:49 -07002362 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002363 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002364 }
2365
2366 /**
2367 * Posts the specified command to be executed on the main thread,
2368 * waits for the request to complete, and returns the result.
2369 * @see #sendRequestAsync
2370 */
2371 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002372 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2373 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002374 }
2375
2376 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002377 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2378 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2379 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002380 * @see #sendRequestAsync
2381 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002382 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2383 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2385 throw new RuntimeException("This method will deadlock if called from the main thread.");
2386 }
2387
Nathan Harold92bed182018-10-12 18:16:49 -07002388 MainThreadRequest request = null;
2389 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2390 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2391 } else if (phone != null) {
2392 request = new MainThreadRequest(argument, phone, workSource);
2393 } else {
2394 request = new MainThreadRequest(argument, subId, workSource);
2395 }
2396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 Message msg = mMainThreadHandler.obtainMessage(command, request);
2398 msg.sendToTarget();
2399
Rambo Wang0f050d82021-02-12 11:43:36 -08002400
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002402 if (timeoutInMs >= 0) {
2403 // Wait for at least timeoutInMs before returning null request result
2404 long now = SystemClock.elapsedRealtime();
2405 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002406 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002407 try {
2408 request.wait(deadline - now);
2409 } catch (InterruptedException e) {
2410 // Do nothing, go back and check if request is completed or timeout
2411 } finally {
2412 now = SystemClock.elapsedRealtime();
2413 }
2414 }
2415 } else {
2416 // Wait for the request to complete
2417 while (request.result == null) {
2418 try {
2419 request.wait();
2420 } catch (InterruptedException e) {
2421 // Do nothing, go back and wait until the request is complete
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424 }
2425 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002426 if (request.result == null) {
2427 Log.wtf(LOG_TAG,
2428 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 return request.result;
2431 }
2432
2433 /**
2434 * Asynchronous ("fire and forget") version of sendRequest():
2435 * Posts the specified command to be executed on the main thread, and
2436 * returns immediately.
2437 * @see #sendRequest
2438 */
2439 private void sendRequestAsync(int command) {
2440 mMainThreadHandler.sendEmptyMessage(command);
2441 }
2442
2443 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002444 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002445 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002446 */
2447 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002448 sendRequestAsync(command, argument, null, null);
2449 }
2450
2451 /**
2452 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2453 * @see {@link #sendRequest(int,Object)}
2454 */
2455 private void sendRequestAsync(
2456 int command, Object argument, Phone phone, WorkSource workSource) {
2457 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002458 Message msg = mMainThreadHandler.obtainMessage(command, request);
2459 msg.sendToTarget();
2460 }
2461
2462 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 * Initialize the singleton PhoneInterfaceManager instance.
2464 * This is only done once, at startup, from PhoneApp.onCreate().
2465 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002466 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 synchronized (PhoneInterfaceManager.class) {
2468 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002469 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 } else {
2471 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2472 }
2473 return sInstance;
2474 }
2475 }
2476
2477 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002478 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002480 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002481 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002483 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002484 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002485 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2487 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002488 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002489 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002490 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002491 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002492 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002493 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002494 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2495 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002496 mVendorApiLevel = SystemProperties.getInt(
2497 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2498
Tyler Gunn64144d92022-03-17 14:16:41 -07002499 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 publish();
arunvoddud7401012022-12-15 16:08:12 +00002501 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002502
2503 // Create the SatelliteEntitlementController singleton, for using the get the
2504 // entitlementStatus for satellite service.
2505 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002508 @VisibleForTesting
2509 public SharedPreferences getSharedPreferences() {
2510 return mTelephonySharedPreferences;
2511 }
2512
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002513 /**
2514 * Get the default phone for this device.
2515 */
2516 @VisibleForTesting
2517 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002518 Phone thePhone = getPhone(getDefaultSubscription());
2519 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2520 }
2521
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 private void publish() {
2523 if (DBG) log("publish: " + this);
2524
Peter Wangc035ce42020-01-08 21:00:22 -08002525 TelephonyFrameworkInitializer
2526 .getTelephonyServiceManager()
2527 .getTelephonyServiceRegisterer()
2528 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
2530
Stuart Scott584921c2015-01-15 17:10:34 -08002531 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002532 if (request.phone != null) {
2533 return request.phone;
2534 } else {
2535 return getPhoneFromSubId(request.subId);
2536 }
2537 }
2538
2539 private Phone getPhoneFromSubId(int subId) {
2540 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2541 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002542 }
2543
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002544 /**
2545 * Get phone object associated with a subscription.
2546 * Return default phone if phone object associated with subscription is null
2547 * @param subId - subscriptionId
2548 * @return phone object associated with a subscription or default phone if null.
2549 */
Ling Mac28f0212023-03-24 16:07:15 -07002550 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002551 Phone phone = getPhoneFromSubId(subId);
2552 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002553 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002554 phone = getDefaultPhone();
2555 }
2556 return phone;
2557 }
2558
Rambo Wange53e07d2022-05-10 13:01:13 -07002559 @Nullable
2560 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002561 Phone phone = getPhoneFromRequest(request);
2562 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002563 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002564 }
2565
Ling Mac28f0212023-03-24 16:07:15 -07002566 /**
2567 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2568 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2569 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2570 * @return The Phone associated the sub Id
2571 */
2572 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002573 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575
Kai Shif70f46f2021-03-03 13:59:46 -08002576 private void sendEraseModemConfig(@NonNull Phone phone) {
2577 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2578 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2579 }
2580
2581 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2582 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2583 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002584 }
2585
Peter Wang44b186e2020-01-13 23:33:09 -08002586 private boolean isImsAvailableOnDevice() {
2587 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2588 if (pm == null) {
2589 // For some reason package manger is not available.. This will fail internally anyway,
2590 // so do not throw error and allow.
2591 return true;
2592 }
2593 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2594 }
2595
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002597 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2598 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2599
Wink Savilleadd7cc52014-09-08 14:23:09 -07002600 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002601 }
2602
Wink Savilleb564aae2014-10-23 10:18:09 -07002603 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 if (DBG) log("dial: " + number);
2605 // No permission check needed here: This is just a wrapper around the
2606 // ACTION_DIAL intent, which is available to any app since it puts up
2607 // the UI before it does anything.
2608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 String url = createTelUrl(number);
2612 if (url == null) {
2613 return;
2614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 // PENDING: should we just silently fail if phone is offhook or ringing?
2617 PhoneConstants.State state = mCM.getState(subId);
2618 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2619 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2620 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002621 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626 }
2627
2628 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002629 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002630 }
2631
Wink Savilleb564aae2014-10-23 10:18:09 -07002632 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 if (DBG) log("call: " + number);
2634
2635 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002636 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 // from the context of the phone app.
2638 enforceCallPermission();
2639
Jordan Liu1617b712019-07-10 15:06:26 -07002640 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 != AppOpsManager.MODE_ALLOWED) {
2642 return;
2643 }
2644
joonhunshin4ac60942023-11-15 15:23:39 +00002645 enforceTelephonyFeatureWithException(callingPackage,
2646 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 String url = createTelUrl(number);
2651 if (url == null) {
2652 return;
2653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 boolean isValid = false;
2656 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2657 if (slist != null) {
2658 for (SubscriptionInfo subInfoRecord : slist) {
2659 if (subInfoRecord.getSubscriptionId() == subId) {
2660 isValid = true;
2661 break;
2662 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002663 }
Wink Saville08874612014-08-31 19:19:58 -07002664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 if (!isValid) {
2666 return;
2667 }
Wink Saville08874612014-08-31 19:19:58 -07002668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2670 intent.putExtra(SUBSCRIPTION_KEY, subId);
2671 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002672 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 int [] resultArray = supplyPinReportResultForSubscriber(subId, 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 boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002684 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002685 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2686 }
2687
Wink Savilleb564aae2014-10-23 10:18:09 -07002688 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
joonhunshin4ac60942023-11-15 15:23:39 +00002691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2692 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2693 "supplyPinReportResultForSubscriber");
2694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 final long identity = Binder.clearCallingIdentity();
2696 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002697 Phone phone = getPhone(subId);
2698 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 checkSimPin.start();
2700 return checkSimPin.unlockSim(null, pin);
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
2705
Wink Savilleb564aae2014-10-23 10:18:09 -07002706 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
joonhunshin4ac60942023-11-15 15:23:39 +00002709 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2710 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 final long identity = Binder.clearCallingIdentity();
2713 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002714 Phone phone = getPhone(subId);
2715 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 checkSimPuk.start();
2717 return checkSimPuk.unlockSim(puk, pin);
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 }
2722
2723 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002724 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 * a synchronous one.
2726 */
2727 private static class UnlockSim extends Thread {
2728
2729 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002730 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731
2732 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002733 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2734 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735
2736 // For replies from SimCard interface
2737 private Handler mHandler;
2738
2739 // For async handler to identify request type
2740 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002741 private static final int SUPPLY_PIN_DELAYED = 101;
2742 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2743 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2744 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745
Michele Berionne5e411512020-11-13 02:36:59 +00002746 UnlockSim(int phoneId, IccCard simCard) {
2747 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 mSimCard = simCard;
2749 }
2750
2751 @Override
2752 public void run() {
2753 Looper.prepare();
2754 synchronized (UnlockSim.this) {
2755 mHandler = new Handler() {
2756 @Override
2757 public void handleMessage(Message msg) {
2758 AsyncResult ar = (AsyncResult) msg.obj;
2759 switch (msg.what) {
2760 case SUPPLY_PIN_COMPLETE:
2761 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2762 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002763 mRetryCount = msg.arg1;
2764 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002765 CommandException.Error error = null;
2766 if (ar.exception instanceof CommandException) {
2767 error = ((CommandException) (ar.exception))
2768 .getCommandError();
2769 }
2770 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002771 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002772 } else if (error == CommandException.Error.ABORTED) {
2773 /* When UiccCardApp dispose, handle message and return
2774 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002775 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002776 } else {
2777 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2778 }
2779 } else {
2780 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002783 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 UnlockSim.this.notifyAll();
2785 }
2786 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002787 case SUPPLY_PIN_DELAYED:
2788 if(!mDone) {
2789 String logStr = "Delay in receiving SIM PIN response ";
2790 if (DBG) log(logStr);
2791 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2792 }
2793 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795 }
2796 };
2797 UnlockSim.this.notifyAll();
2798 }
2799 Looper.loop();
2800 }
2801
2802 /*
2803 * Use PIN or PUK to unlock SIM card
2804 *
2805 * If PUK is null, unlock SIM card with PIN
2806 *
2807 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302808 *
2809 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2810 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 */
Wink Saville9de0f752013-10-22 19:04:03 -07002812 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813
2814 while (mHandler == null) {
2815 try {
2816 wait();
2817 } catch (InterruptedException e) {
2818 Thread.currentThread().interrupt();
2819 }
2820 }
2821 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2822
2823 if (puk == null) {
2824 mSimCard.supplyPin(pin, callback);
2825 } else {
2826 mSimCard.supplyPuk(puk, pin, callback);
2827 }
2828
2829 while (!mDone) {
2830 try {
2831 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002832 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2833 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 wait();
2835 } catch (InterruptedException e) {
2836 // Restore the interrupted status
2837 Thread.currentThread().interrupt();
2838 }
2839 }
2840 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002841 int[] resultArray = new int[2];
2842 resultArray[0] = mResult;
2843 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002844
2845 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002846 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002847 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302848 // This instance is no longer reused, so quit its thread's looper.
2849 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002850
Wink Saville9de0f752013-10-22 19:04:03 -07002851 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 }
2853 }
2854
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002855 /**
2856 * This method has been removed due to privacy and stability concerns.
2857 */
2858 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002860 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2861 return;
Wink Saville36469e72014-06-11 15:17:00 -07002862 }
2863
Nathan Harold1f889d82020-06-04 17:05:26 -07002864 @Override
2865 public void updateServiceLocationWithPackageName(String callingPackage) {
2866 mApp.getSystemService(AppOpsManager.class)
2867 .checkPackage(Binder.getCallingUid(), callingPackage);
2868
Nathan Haroldf096d982020-11-18 17:18:06 -08002869 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002870 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2871 // Callers targeting S have no business invoking this method.
2872 return;
2873 }
2874
2875 LocationAccessPolicy.LocationPermissionResult locationResult =
2876 LocationAccessPolicy.checkLocationPermission(mApp,
2877 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2878 .setCallingPackage(callingPackage)
2879 .setCallingFeatureId(null)
2880 .setCallingPid(Binder.getCallingPid())
2881 .setCallingUid(Binder.getCallingUid())
2882 .setMethod("updateServiceLocation")
2883 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2884 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2885 .build());
2886 // Apps that lack location permission have no business calling this method;
2887 // however, because no permission was declared in the public API, denials must
2888 // all be "soft".
2889 switch (locationResult) {
2890 case DENIED_HARD: /* fall through */
2891 case DENIED_SOFT:
2892 return;
2893 }
2894
2895 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896 final long identity = Binder.clearCallingIdentity();
2897 try {
Ling Mac28f0212023-03-24 16:07:15 -07002898 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002904 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002905 @Override
2906 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002907 return isRadioOnWithFeature(callingPackage, null);
2908 }
2909
2910
2911 @Override
2912 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2913 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2914 callingFeatureId);
2915 }
2916
2917 @Deprecated
2918 @Override
2919 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2920 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002921 }
2922
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002924 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2925 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002927 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002928 return false;
2929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
joonhunshin4ac60942023-11-15 15:23:39 +00002931 enforceTelephonyFeatureWithException(callingPackage,
2932 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 return isRadioOnForSubscriber(subId);
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002940 }
2941
2942 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 final Phone phone = getPhone(subId);
2946 if (phone != null) {
2947 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2948 } else {
2949 return false;
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
2956 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002957 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002958 }
Wink Saville36469e72014-06-11 15:17:00 -07002959
Wink Savilleb564aae2014-10-23 10:18:09 -07002960 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962
joonhunshin4ac60942023-11-15 15:23:39 +00002963 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2964 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 final Phone phone = getPhone(subId);
2969 if (phone != null) {
2970 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002974 }
Wink Saville36469e72014-06-11 15:17:00 -07002975 }
2976
2977 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002978 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002979 }
2980
Wink Savilleb564aae2014-10-23 10:18:09 -07002981 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 final Phone phone = getPhone(subId);
2987 if (phone == null) {
2988 return false;
2989 }
2990 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2991 toggleRadioOnOffForSubscriber(subId);
2992 }
2993 return true;
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
Wink Saville36469e72014-06-11 15:17:00 -07002998
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003000 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00003001
Tomasz Wasilczykef763582024-09-17 13:50:32 -07003002 if (!mApp.getResources().getBoolean(
3003 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3005 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3006 }
joonhunshin4ac60942023-11-15 15:23:39 +00003007
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003008 /*
3009 * If any of the Radios are available, it will need to be
3010 * shutdown. So return true if any Radio is available.
3011 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3015 Phone phone = PhoneFactory.getPhone(i);
3016 if (phone != null && phone.isRadioAvailable()) return true;
3017 }
3018 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3019 return false;
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003022 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003023 }
3024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003026 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 enforceModifyPermission();
3028
joonhunshin4ac60942023-11-15 15:23:39 +00003029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3030 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3035 logv("Shutting down Phone " + i);
3036 shutdownRadioUsingPhoneId(i);
3037 }
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003040 }
3041 }
3042
3043 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003044 Phone phone = PhoneFactory.getPhone(phoneId);
3045 if (phone != null && phone.isRadioAvailable()) {
3046 phone.shutdownRadio();
3047 }
3048 }
3049
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003051 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052
Ling Ma83dc5ea2023-01-12 15:06:04 -08003053 if (!turnOn) {
3054 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3055 }
3056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3060 if (defaultPhone != null) {
3061 defaultPhone.setRadioPower(turnOn);
3062 return true;
3063 } else {
3064 loge("There's no default phone.");
3065 return false;
3066 }
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003069 }
Wink Saville36469e72014-06-11 15:17:00 -07003070 }
3071
Wink Savilleb564aae2014-10-23 10:18:09 -07003072 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
Ling Ma83dc5ea2023-01-12 15:06:04 -08003075 if (!turnOn) {
3076 log("setRadioPowerForSubscriber off: subId=" + subId
3077 + ",callingPackage=" + getCurrentPackageName());
3078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 final Phone phone = getPhone(subId);
3082 if (phone != null) {
3083 phone.setRadioPower(turnOn);
3084 return true;
3085 } else {
3086 return false;
3087 }
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 }
3092
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003093 /**
3094 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3095 * no reason to power it off. When any of the voters want to power it off, it will be turned
3096 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3097 * powering it off, and these radio off votes will be cleared.
3098 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3099 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3100 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3101 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3102 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3103 * check its vote.
3104 *
3105 * @param subId The subscription ID.
3106 * @param reason The reason for powering off radio.
3107 * @return true on success and false on failure.
3108 */
3109 public boolean requestRadioPowerOffForReason(int subId,
3110 @TelephonyManager.RadioPowerReason int reason) {
3111 enforceModifyPermission();
3112
joonhunshin4ac60942023-11-15 15:23:39 +00003113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3114 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3115
Ling Ma83dc5ea2023-01-12 15:06:04 -08003116 log("requestRadioPowerOffForReason: subId=" + subId
3117 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003118 final long identity = Binder.clearCallingIdentity();
3119 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003120 boolean result = false;
3121 for (Phone phone : PhoneFactory.getPhones()) {
3122 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003124 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003125 if (!result) {
3126 loge("requestRadioPowerOffForReason: no phone exists");
3127 }
3128 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 /**
3135 * Remove the vote on powering off the radio for a reason, as requested by
3136 * {@link requestRadioPowerOffForReason}.
3137 *
3138 * @param subId The subscription ID.
3139 * @param reason The reason for powering off radio.
3140 * @return true on success and false on failure.
3141 */
3142 public boolean clearRadioPowerOffForReason(int subId,
3143 @TelephonyManager.RadioPowerReason int reason) {
3144 enforceModifyPermission();
3145
joonhunshin4ac60942023-11-15 15:23:39 +00003146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3147 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3148
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003149 final long identity = Binder.clearCallingIdentity();
3150 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003151 boolean result = false;
3152 for (Phone phone : PhoneFactory.getPhones()) {
3153 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003154 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003155 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003156 if (!result) {
3157 loge("clearRadioPowerOffForReason: no phone exists");
3158 }
3159 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
3163 }
3164
3165 /**
3166 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3167 *
3168 * @param subId The subscription ID.
3169 * @param callingPackage The package making the call.
3170 * @param callingFeatureId The feature in the package.
3171 * @return List of reasons for powering off radio.
3172 */
3173 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3174 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3175
joonhunshin4ac60942023-11-15 15:23:39 +00003176 enforceTelephonyFeatureWithException(callingPackage,
3177 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3178
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003179 final long identity = Binder.clearCallingIdentity();
3180 List result = new ArrayList();
3181 try {
3182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3183 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3184 return result;
3185 }
3186
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003187 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003188 if (phone != null) {
3189 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003190 } else {
3191 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
3196 return result;
3197 }
3198
Wink Saville36469e72014-06-11 15:17:00 -07003199 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003200 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003201 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203
joonhunshin4ac60942023-11-15 15:23:39 +00003204 enforceTelephonyFeatureWithException(callingPackage,
3205 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
Jack Yu285100e2022-12-02 22:48:35 -08003209 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003211 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003212 phone.getDataSettingsManager().setDataEnabled(
3213 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 return true;
3215 } else {
3216 return false;
3217 }
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Wink Saville36469e72014-06-11 15:17:00 -07003223 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003224 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003225 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003226 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
joonhunshin4ac60942023-11-15 15:23:39 +00003228 enforceTelephonyFeatureWithException(callingPackage,
3229 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 final long identity = Binder.clearCallingIdentity();
3232 try {
Jack Yu285100e2022-12-02 22:48:35 -08003233 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003235 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003236 phone.getDataSettingsManager().setDataEnabled(
3237 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 return true;
3239 } else {
3240 return false;
3241 }
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 }
3246
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003248 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3250 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 final Phone phone = getPhone(subId);
3255 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003256 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 } else {
3258 return false;
3259 }
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
3265 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003266 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003267 }
3268
pkanwarae03a6b2016-11-06 20:37:09 -08003269 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 enforceCallPermission();
3271
joonhunshin4ac60942023-11-15 15:23:39 +00003272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3273 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3278 return;
3279 }
3280 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3281 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
pkanwar32d516d2016-10-14 19:37:38 -07003285 };
3286
Wink Savilleb564aae2014-10-23 10:18:09 -07003287 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003288 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289
joonhunshin4ac60942023-11-15 15:23:39 +00003290 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3291 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3296 return false;
3297 }
3298 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 }
3303
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003304 /**
3305 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3306 * tag on getCallState Binder call.
3307 */
3308 @Deprecated
3309 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003311 if (CompatChanges.isChangeEnabled(
3312 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3313 Binder.getCallingUid())) {
3314 // Do not allow this API to be called on API version 31+, it should only be
3315 // called on old apps using this Binder call directly.
3316 throw new SecurityException("This method can only be used for applications "
3317 + "targeting API version 30 or less.");
3318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 final long identity = Binder.clearCallingIdentity();
3320 try {
Ling Mac28f0212023-03-24 16:07:15 -07003321 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3322 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003323 } finally {
3324 Binder.restoreCallingIdentity(identity);
3325 }
3326 }
3327
3328 @Override
3329 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3330 if (CompatChanges.isChangeEnabled(
3331 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3332 Binder.getCallingUid())) {
3333 // Check READ_PHONE_STATE for API version 31+
3334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3335 featureId, "getCallStateForSubscription")) {
3336 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3337 + "targeting API level 31+.");
3338 }
3339 }
joonhunshin4ac60942023-11-15 15:23:39 +00003340
3341 enforceTelephonyFeatureWithException(callingPackage,
3342 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3343
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3348 PhoneConstantConversions.convertCallState(phone.getState());
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003355 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003356 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003357 }
3358
3359 @Override
3360 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3362 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003368 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369 } else {
3370 return PhoneConstantConversions.convertDataState(
3371 PhoneConstants.DataState.DISCONNECTED);
3372 }
3373 } finally {
3374 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003376 }
3377
Sanket Padawe356d7632015-06-22 14:03:32 -07003378 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003379 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003380 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003381 }
3382
3383 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003384 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003385 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3386 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388 final long identity = Binder.clearCallingIdentity();
3389 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003390 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003392 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 } else {
3394 return TelephonyManager.DATA_ACTIVITY_NONE;
3395 }
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
3400
3401 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003402 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003404 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003405
3406 LocationAccessPolicy.LocationPermissionResult locationResult =
3407 LocationAccessPolicy.checkLocationPermission(mApp,
3408 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3409 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003410 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003411 .setCallingPid(Binder.getCallingPid())
3412 .setCallingUid(Binder.getCallingUid())
3413 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003414 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003415 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3416 .build());
3417 switch (locationResult) {
3418 case DENIED_HARD:
3419 throw new SecurityException("Not allowed to access cell location");
3420 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003421 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3422 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 }
3424
joonhunshin4ac60942023-11-15 15:23:39 +00003425 enforceTelephonyFeatureWithException(callingPackage,
3426 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3427
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003428 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003432 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003433 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
Svetoslav64fad262015-04-14 14:35:21 -07003437 }
3438
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003440 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003441 if (!mApp.getResources().getBoolean(
3442 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3443 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3444 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3445 }
joonhunshin4ac60942023-11-15 15:23:39 +00003446
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003447 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3448 // registered cell info, so return a NULL country instead.
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003451 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3452 // Get default phone in this case.
3453 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3454 }
Jack Yu285100e2022-12-02 22:48:35 -08003455 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003457 if (phone == null) return "";
3458 ServiceStateTracker sst = phone.getServiceStateTracker();
3459 if (sst == null) return "";
3460 LocaleTracker lt = sst.getLocaleTracker();
3461 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003462 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003466 }
3467
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003468 /**
3469 * This method was removed due to potential issues caused by performing partial
3470 * updates of service state, and lack of a credible use case.
3471 *
3472 * This has the ability to break the telephony implementation by disabling notification of
3473 * changes in device connectivity. DO NOT USE THIS!
3474 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003475 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 public void enableLocationUpdates() {
3477 mApp.enforceCallingOrSelfPermission(
3478 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 }
3480
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003481 /**
3482 * This method was removed due to potential issues caused by performing partial
3483 * updates of service state, and lack of a credible use case.
3484 *
3485 * This has the ability to break the telephony implementation by disabling notification of
3486 * changes in device connectivity. DO NOT USE THIS!
3487 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 @Override
3489 public void disableLocationUpdates() {
3490 mApp.enforceCallingOrSelfPermission(
3491 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003492 }
3493
3494 @Override
3495 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003496 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3497 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003498 try {
3499 mApp.getSystemService(AppOpsManager.class)
3500 .checkPackage(Binder.getCallingUid(), callingPackage);
3501 } catch (SecurityException e) {
3502 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3503 throw e;
3504 }
3505
Nathan Haroldf096d982020-11-18 17:18:06 -08003506 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003507 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3508 throw new SecurityException(
3509 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3510 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003511
Jordan Liu1617b712019-07-10 15:06:26 -07003512 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3514 return null;
3515 }
Svetoslav64fad262015-04-14 14:35:21 -07003516
joonhunshin4ac60942023-11-15 15:23:39 +00003517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3518 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3519
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003520 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003522 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003523 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524
Nathan Haroldf180aac2018-06-01 18:43:55 -07003525 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3526 for (CellInfo ci : info) {
3527 if (ci instanceof CellInfoGsm) {
3528 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3529 } else if (ci instanceof CellInfoWcdma) {
3530 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003533 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534 }
3535
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003536 private List<CellInfo> getCachedCellInfo() {
3537 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3538 for (Phone phone : PhoneFactory.getPhones()) {
3539 List<CellInfo> info = phone.getAllCellInfo();
3540 if (info != null) cellInfos.addAll(info);
3541 }
3542 return cellInfos;
3543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544
3545 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003546 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003547 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003548 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003549
3550 LocationAccessPolicy.LocationPermissionResult locationResult =
3551 LocationAccessPolicy.checkLocationPermission(mApp,
3552 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3553 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003554 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003555 .setCallingPid(Binder.getCallingPid())
3556 .setCallingUid(Binder.getCallingUid())
3557 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003558 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003559 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3560 .build());
3561 switch (locationResult) {
3562 case DENIED_HARD:
3563 throw new SecurityException("Not allowed to access cell info");
3564 case DENIED_SOFT:
3565 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003566 }
3567
Nathan Haroldf096d982020-11-18 17:18:06 -08003568 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003569 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3570 return getCachedCellInfo();
3571 }
3572
joonhunshin4ac60942023-11-15 15:23:39 +00003573 enforceTelephonyFeatureWithException(callingPackage,
3574 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3575
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003576 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3581 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003582 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003583 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584 if (info != null) cellInfos.addAll(info);
3585 }
3586 return cellInfos;
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 }
3590 }
3591
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003592 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003593 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3594 String callingFeatureId) {
3595 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3596 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003597 }
3598
3599 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003600 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3601 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003602 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003603 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003604 }
3605
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003606 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3607 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003608 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003609 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003610
3611 LocationAccessPolicy.LocationPermissionResult locationResult =
3612 LocationAccessPolicy.checkLocationPermission(mApp,
3613 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3614 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003615 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003616 .setCallingPid(Binder.getCallingPid())
3617 .setCallingUid(Binder.getCallingUid())
3618 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003619 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3620 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003621 .build());
3622 switch (locationResult) {
3623 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003624 if (TelephonyPermissions
3625 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003626 // Safetynet logging for b/154934934
3627 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3628 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003629 throw new SecurityException("Not allowed to access cell info");
3630 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003631 if (TelephonyPermissions
3632 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003633 // Safetynet logging for b/154934934
3634 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3635 }
Nathan Harold5320c422019-05-09 10:26:08 -07003636 try {
3637 cb.onCellInfo(new ArrayList<CellInfo>());
3638 } catch (RemoteException re) {
3639 // Drop without consequences
3640 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003641 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003642 }
3643
joonhunshin4ac60942023-11-15 15:23:39 +00003644 enforceTelephonyFeatureWithException(callingPackage,
3645 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003646
3647 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003648 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3649
3650 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3651 }
3652
3653 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003654 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003655 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003656 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003660 Phone phone = getPhone(subId);
3661 if (phone == null) {
3662 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3663 } else {
3664 phone.setCellInfoListRate(rateInMillis, workSource);
3665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003669 }
3670
Shishir Agrawala9f32182016-04-12 12:00:16 -07003671 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003672 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003673 Phone phone = PhoneFactory.getPhone(slotIndex);
3674 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003675 return null;
3676 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003677 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003678 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003679 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003680 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003681 return null;
3682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 return phone.getImei();
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003690 }
3691
3692 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003693 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3694 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3695 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3696 callingFeatureId, "getPrimaryImei")) {
3697 throw new SecurityException("Caller does not have permission");
3698 }
joonhunshin4ac60942023-11-15 15:23:39 +00003699
arunvoddud5c6ce02022-12-11 06:03:12 +00003700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 for (Phone phone : PhoneFactory.getPhones()) {
3703 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3704 return phone.getImei();
3705 }
3706 }
3707 throw new UnsupportedOperationException("Operation not supported");
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
3713 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003714 public String getTypeAllocationCodeForSlot(int slotIndex) {
3715 Phone phone = PhoneFactory.getPhone(slotIndex);
3716 String tac = null;
3717 if (phone != null) {
3718 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003719 try {
3720 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3721 } catch (IndexOutOfBoundsException e) {
3722 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3723 return null;
3724 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003725 }
3726 return tac;
3727 }
3728
3729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003730 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003731 try {
3732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3733 } catch (SecurityException se) {
3734 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3735 throw new SecurityException("Package " + callingPackage + " does not belong to "
3736 + Binder.getCallingUid());
3737 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003738 Phone phone = PhoneFactory.getPhone(slotIndex);
3739 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003740 return null;
3741 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742
Jeff Davidson913390f2018-02-23 17:11:49 -08003743 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003744 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003745 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003746 return null;
3747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
joonhunshin4ac60942023-11-15 15:23:39 +00003749 enforceTelephonyFeatureWithException(callingPackage,
3750 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 return phone.getMeid();
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Jack Yu2af8d712017-03-15 17:14:14 -07003758 }
3759
3760 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003761 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3763 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3764
David Kelly5e06a7f2018-03-12 14:10:59 +00003765 Phone phone = PhoneFactory.getPhone(slotIndex);
3766 String manufacturerCode = null;
3767 if (phone != null) {
3768 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003769 try {
3770 manufacturerCode =
3771 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3772 } catch (IndexOutOfBoundsException e) {
3773 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3774 return null;
3775 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003776 }
3777 return manufacturerCode;
3778 }
3779
3780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003781 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3782 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 Phone phone = PhoneFactory.getPhone(slotIndex);
3784 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 return null;
3786 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 int subId = phone.getSubId();
3788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003789 mApp, subId, callingPackage, callingFeatureId,
3790 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003791 return null;
3792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
joonhunshin4ac60942023-11-15 15:23:39 +00003794 enforceTelephonyFeatureWithException(callingPackage,
3795 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 return phone.getDeviceSvn();
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003803 }
3804
fionaxu43304da2017-11-27 22:51:16 -08003805 @Override
3806 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003807 if (!mApp.getResources().getBoolean(
3808 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3810 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3811 }
joonhunshin4ac60942023-11-15 15:23:39 +00003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
fionaxu43304da2017-11-27 22:51:16 -08003820 }
3821
3822 @Override
3823 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003824 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3825 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 return phone == null ? null : phone.getCarrierName();
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
fionaxu43304da2017-11-27 22:51:16 -08003834 }
3835
calvinpanffe225e2018-11-01 19:43:06 +08003836 @Override
chen xu0026ca62019-03-06 15:28:50 -08003837 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3840
chen xu25637222018-11-04 17:17:00 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 final Phone phone = getPhone(subId);
3844 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003845 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003846 } finally {
3847 Binder.restoreCallingIdentity(identity);
3848 }
3849 }
3850
3851 @Override
chen xu0026ca62019-03-06 15:28:50 -08003852 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3855 "getSubscriptionSpecificCarrierName");
3856
chen xu25637222018-11-04 17:17:00 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003860 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
chen xu651eec72018-11-11 19:03:44 -08003866 @Override
chen xu864e11c2018-12-06 22:10:03 -08003867 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3868 if (!isSubscriptionMccMnc) {
3869 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3870 }
chen xu651eec72018-11-11 19:03:44 -08003871 final Phone phone = PhoneFactory.getPhone(slotIndex);
3872 if (phone == null) {
3873 return TelephonyManager.UNKNOWN_CARRIER_ID;
3874 }
joonhunshin4ac60942023-11-15 15:23:39 +00003875
3876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3877 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3878
chen xu651eec72018-11-11 19:03:44 -08003879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
3885 }
3886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 //
3888 // Internal helper methods.
3889 //
3890
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003891 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003892 * Make sure the caller is the calling package itself
3893 *
3894 * @throws SecurityException if the caller is not the calling package
3895 */
3896 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3897 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003898 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3899 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003900 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003901 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003902 } catch (PackageManager.NameNotFoundException e) {
3903 // packageUid is -1
3904 }
3905 if (packageUid != callingUid) {
3906 throw new SecurityException(message + ": Package " + callingPackage
3907 + " does not belong to " + callingUid);
3908 }
3909 }
3910
3911 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3913 *
3914 * @throws SecurityException if the caller does not have the required permission
3915 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003916 @VisibleForTesting
3917 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3919 }
3920
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003921 /**
arunvoddud7401012022-12-15 16:08:12 +00003922 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003923 *
3924 * @throws SecurityException if the caller does not have the required permission
3925 */
3926 @VisibleForTesting
3927 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003928 enforceReadPermission(null);
3929 }
3930
3931 /**
3932 * Make sure the caller has the READ_PHONE_STATE permissions.
3933 *
3934 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3935 */
3936 @VisibleForTesting
3937 public void enforceReadPermission(String msg) {
3938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003939 }
3940
Shuo Qian3b6ee772019-11-13 17:43:31 -08003941 private void enforceActiveEmergencySessionPermission() {
3942 mApp.enforceCallingOrSelfPermission(
3943 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3944 }
3945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 /**
3947 * Make sure the caller has the CALL_PHONE permission.
3948 *
3949 * @throws SecurityException if the caller does not have the required permission
3950 */
3951 private void enforceCallPermission() {
3952 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3953 }
3954
paulhu5a773602019-08-23 19:17:33 +08003955 private void enforceSettingsPermission() {
3956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003957 }
3958
Michele Berionne5e411512020-11-13 02:36:59 +00003959 private void enforceRebootPermission() {
3960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3961 }
3962
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003963 /**
3964 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3965 * @param message - log message to print.
3966 * @throws SecurityException if the caller does not have the required permission
3967 */
3968 private void enforceSatelliteCommunicationPermission(String message) {
3969 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3970 }
3971
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003972 /**
3973 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3974 * @param message - log message to print.
3975 * @throws SecurityException if the caller does not have the required permission
3976 */
3977 private void enforcePackageUsageStatsPermission(String message) {
3978 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3979 }
3980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003981 private String createTelUrl(String number) {
3982 if (TextUtils.isEmpty(number)) {
3983 return null;
3984 }
3985
Jake Hambye994d462014-02-03 13:10:13 -08003986 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987 }
3988
Ihab Awadf9e92732013-12-05 18:02:52 -08003989 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003990 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003991 }
3992
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003993 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003994 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003995 }
3996
Ihab Awadf9e92732013-12-05 18:02:52 -08003997 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003998 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003999 }
4000
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004001 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004002 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004003 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004004 }
4005
Sanket Padawe356d7632015-06-22 14:03:32 -07004006 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004007 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004008 if (!mApp.getResources().getBoolean(
4009 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4011 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4012 }
joonhunshin4ac60942023-11-15 15:23:39 +00004013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 final Phone phone = PhoneFactory.getPhone(slotIndex);
4017 if (phone == null) {
4018 return PhoneConstants.PHONE_TYPE_NONE;
4019 } else {
4020 return phone.getPhoneType();
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004025 }
4026
4027 /**
4028 * Returns the CDMA ERI icon index to display
4029 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4032 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4033 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004034 }
4035
Sanket Padawe356d7632015-06-22 14:03:32 -07004036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004040 mApp, subId, callingPackage, callingFeatureId,
4041 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004042 return -1;
4043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044
joonhunshin4ac60942023-11-15 15:23:39 +00004045 enforceTelephonyFeatureWithException(callingPackage,
4046 PackageManager.FEATURE_TELEPHONY_CDMA,
4047 "getCdmaEriIconIndexForSubscriber");
4048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 final Phone phone = getPhone(subId);
4052 if (phone != null) {
4053 return phone.getCdmaEriIconIndex();
4054 } else {
4055 return -1;
4056 }
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004060 }
4061
4062 /**
4063 * Returns the CDMA ERI icon mode,
4064 * 0 - ON
4065 * 1 - FLASHING
4066 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4069 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4070 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004071 }
4072
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4075 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 mApp, subId, callingPackage, callingFeatureId,
4078 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004079 return -1;
4080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 final Phone phone = getPhone(subId);
4085 if (phone != null) {
4086 return phone.getCdmaEriIconMode();
4087 } else {
4088 return -1;
4089 }
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004093 }
4094
4095 /**
4096 * Returns the CDMA ERI text,
4097 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004099 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4100 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4101 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004102 }
4103
Sanket Padawe356d7632015-06-22 14:03:32 -07004104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004105 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4106 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004108 mApp, subId, callingPackage, callingFeatureId,
4109 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004110 return null;
4111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 final Phone phone = getPhone(subId);
4116 if (phone != null) {
4117 return phone.getCdmaEriText();
4118 } else {
4119 return null;
4120 }
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004124 }
4125
4126 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004127 * Returns the CDMA MDN.
4128 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004129 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004130 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4132 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133
joonhunshin4ac60942023-11-15 15:23:39 +00004134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4135 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 return phone.getLine1Number();
4142 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 return null;
4145 }
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004148 }
4149 }
4150
4151 /**
4152 * Returns the CDMA MIN.
4153 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004154 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004155 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
joonhunshin4ac60942023-11-15 15:23:39 +00004159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4160 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 final Phone phone = getPhone(subId);
4165 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4166 return phone.getCdmaMin();
4167 } else {
4168 return null;
4169 }
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004172 }
4173 }
4174
Hall Liud892bec2018-11-30 14:51:45 -08004175 @Override
4176 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4177 INumberVerificationCallback callback, String callingPackage) {
4178 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4179 != PERMISSION_GRANTED) {
4180 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4181 }
4182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4183
4184 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4185 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004186 throw new SecurityException("Calling package must be configured in the device config: "
4187 + "calling package: " + callingPackage
4188 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004189 }
4190
joonhunshin4ac60942023-11-15 15:23:39 +00004191 enforceTelephonyFeatureWithException(callingPackage,
4192 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4193
Hall Liud892bec2018-11-30 14:51:45 -08004194 if (range == null) {
4195 throw new NullPointerException("Range must be non-null");
4196 }
4197
4198 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004199 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004200
4201 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4202 }
4203
Junda Liuca05d5d2014-08-14 22:36:34 -07004204 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004205 * Returns true if CDMA provisioning needs to run.
4206 */
4207 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4209 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004213 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004217 }
4218
4219 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004220 * Sets the voice mail number of a given subId.
4221 */
4222 @Override
4223 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004224 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4225 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226
joonhunshin4ac60942023-11-15 15:23:39 +00004227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4228 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004232 Boolean success = (Boolean) sendRequest(
4233 CMD_SET_VOICEMAIL_NUMBER,
4234 new Pair<String, String>(alphaTag, number),
4235 new Integer(subId),
4236 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4237 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 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.
Brad Ebinger555ddec2024-11-04 13:46:31 -08006645 * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL}
6646 * if there is no preference.
Brad Ebinger24c29992019-12-05 13:03:21 -08006647 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006648 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 * @param featureTypes An integer array of feature types associated with a packageName.
6650 * @param packageName The name of the package that the current configuration will be replaced
6651 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006652 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006653 */
Brad Ebinger555ddec2024-11-04 13:46:31 -08006654 public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService,
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006658 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 final long identity = Binder.clearCallingIdentity();
6661 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006663 // may happen if the device does not support IMS.
6664 return false;
6665 }
Brad Ebinger555ddec2024-11-04 13:46:31 -08006666 return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId,
6667 isCarrierService, featureTypes);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006671 }
6672
6673 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006674 * Clears any carrier ImsService overrides for the slot index specified that were previously
6675 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6676 *
6677 * This should only be used for testing.
6678 *
6679 * @param slotIndex the slot ID that the ImsService should bind for.
6680 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6681 */
6682 @Override
6683 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6685 "clearCarrierImsServiceOverride");
6686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006687 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006688
6689 final long identity = Binder.clearCallingIdentity();
6690 try {
6691 if (mImsResolver == null) {
6692 // may happen if the device does not support IMS.
6693 return false;
6694 }
6695 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6696 } finally {
6697 Binder.restoreCallingIdentity(identity);
6698 }
6699 }
6700
6701 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006702 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006703 *
6704 * @param slotId The slot that the ImsService is associated with.
6705 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6706 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006707 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006708 * @return the package name of the ImsService configuration.
6709 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006710 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6711 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006712 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006713 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6714 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006719 // may happen if the device does not support IMS.
6720 return "";
6721 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006722 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006723 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6724 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006728 }
6729
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006730 /**
6731 * Get the MmTelFeature state associated with the requested subscription id.
6732 * @param subId The subscription that the MmTelFeature is associated with.
6733 * @param callback A callback with an integer containing the
6734 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6735 */
6736 @Override
6737 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6738 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006739 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6741 "IMS not available on device.");
6742 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006743 final long token = Binder.clearCallingIdentity();
6744 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006745 int slotId = getSlotIndex(subId);
6746 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6747 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6748 + subId + "'");
6749 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6750 }
6751 verifyImsMmTelConfiguredOrThrow(slotId);
6752 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6753 try {
6754 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6755 } catch (RemoteException e) {
6756 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6757 + "Ignore");
6758 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006759 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006760 } catch (ImsException e) {
6761 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006762 } finally {
6763 Binder.restoreCallingIdentity(token);
6764 }
6765 }
6766
Daniel Brightbb5840b2021-01-12 15:48:18 -08006767 /**
6768 * Sets the ims registration state on all valid {@link Phone}s.
6769 */
6770 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006771 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006775 // NOTE: Before S, this method only set the default phone.
6776 for (final Phone phone : PhoneFactory.getPhones()) {
6777 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6778 phone.setImsRegistrationState(registered);
6779 }
6780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
Wink Saville36469e72014-06-11 15:17:00 -07006784 }
6785
6786 /**
Stuart Scott54788802015-03-30 13:18:01 -07006787 * Set the network selection mode to automatic.
6788 *
6789 */
6790 @Override
6791 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6793 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794
joonhunshin4ac60942023-11-15 15:23:39 +00006795 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6796 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 final long identity = Binder.clearCallingIdentity();
6799 try {
shilufc958392020-01-20 11:36:01 -08006800 if (!isActiveSubscription(subId)) {
6801 return;
6802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006804 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006805 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
Stuart Scott54788802015-03-30 13:18:01 -07006809 }
6810
Jack Yud10cdd42020-09-28 20:28:01 -07006811 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006812 * Ask the radio to connect to the input network and change selection mode to manual.
6813 *
6814 * @param subId the id of the subscription.
6815 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6816 * the operator to attach to.
6817 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6818 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6819 * normal network selection next time.
6820 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006821 */
6822 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006823 public boolean setNetworkSelectionModeManual(
6824 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6826 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006827
joonhunshin4ac60942023-11-15 15:23:39 +00006828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6829 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6830
Jack Yu285100e2022-12-02 22:48:35 -08006831 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006832 if (!isActiveSubscription(subId)) {
6833 return false;
6834 }
6835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006837 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006839 if (DBG) {
6840 log("setNetworkSelectionModeManual: subId: " + subId
6841 + " operator: " + operatorInfo);
6842 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006843 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6844 } finally {
6845 Binder.restoreCallingIdentity(identity);
6846 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006847 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006848 /**
shilu84f6e8b2019-12-19 13:58:01 -08006849 * Get the manual network selection
6850 *
6851 * @param subId the id of the subscription.
6852 *
6853 * @return the previously saved user selected PLMN
6854 */
6855 @Override
6856 public String getManualNetworkSelectionPlmn(int subId) {
6857 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006858 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6859 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006860
joonhunshin4ac60942023-11-15 15:23:39 +00006861 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6862 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6863
shilu84f6e8b2019-12-19 13:58:01 -08006864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006867 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006868 }
6869
6870 final Phone phone = getPhone(subId);
6871 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006872 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006873 }
6874 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6875 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006876 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006881
6882 /**
6883 * Scans for available networks.
6884 */
6885 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006886 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6887 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6889 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006890 LocationAccessPolicy.LocationPermissionResult locationResult =
6891 LocationAccessPolicy.checkLocationPermission(mApp,
6892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6893 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006895 .setCallingPid(Binder.getCallingPid())
6896 .setCallingUid(Binder.getCallingUid())
6897 .setMethod("getCellNetworkScanResults")
6898 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006899 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6900 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006901 .build());
6902 switch (locationResult) {
6903 case DENIED_HARD:
6904 throw new SecurityException("Not allowed to access scan results -- location");
6905 case DENIED_SOFT:
6906 return null;
6907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908
Pengquan Menga1bb6272018-09-06 09:59:22 -07006909 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 try {
6911 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006912 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006917 }
6918
6919 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006920 * Get the call forwarding info, given the call forwarding reason.
6921 */
6922 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006923 public void getCallForwarding(int subId, int callForwardingReason,
6924 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006925 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006926
6927 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6928 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6929
Shuo Qian4a594052020-01-23 11:59:30 -08006930 long identity = Binder.clearCallingIdentity();
6931 try {
6932 if (DBG) {
6933 log("getCallForwarding: subId " + subId
6934 + " callForwardingReason" + callForwardingReason);
6935 }
Hall Liu27d24262020-09-18 19:04:59 -07006936
6937 Phone phone = getPhone(subId);
6938 if (phone == null) {
6939 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006940 callback.onError(
6941 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006942 } catch (RemoteException e) {
6943 // ignore
6944 }
6945 return;
6946 }
6947
6948 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6949 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6950 @Override
6951 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6952 try {
6953 callback.onCallForwardingInfoAvailable(info);
6954 } catch (RemoteException e) {
6955 // ignore
6956 }
6957 }
6958
6959 @Override
6960 public void onError(int error) {
6961 try {
6962 callback.onError(error);
6963 } catch (RemoteException e) {
6964 // ignore
6965 }
6966 }
6967 });
6968 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
6972 }
6973
6974 /**
6975 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6976 * reason, the number to forward, and the timeout before the forwarding is attempted.
6977 */
6978 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006979 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6980 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006981 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006982
6983 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6984 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6985
Shuo Qian4a594052020-01-23 11:59:30 -08006986 long identity = Binder.clearCallingIdentity();
6987 try {
6988 if (DBG) {
6989 log("setCallForwarding: subId " + subId
6990 + " callForwardingInfo" + callForwardingInfo);
6991 }
Hall Liu27d24262020-09-18 19:04:59 -07006992
6993 Phone phone = getPhone(subId);
6994 if (phone == null) {
6995 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006996 callback.accept(
6997 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006998 } catch (RemoteException e) {
6999 // ignore
7000 }
7001 return;
7002 }
7003
7004 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7005 FunctionalUtils.ignoreRemoteException(callback::accept));
7006
7007 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
7012
7013 /**
Hall Liu27d24262020-09-18 19:04:59 -07007014 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007015 */
7016 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007017 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007018 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007019
7020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7021 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7022
Shuo Qian4a594052020-01-23 11:59:30 -08007023 long identity = Binder.clearCallingIdentity();
7024 try {
Hall Liu27d24262020-09-18 19:04:59 -07007025 Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 try {
7028 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7029 } catch (RemoteException e) {
7030 // ignore
7031 }
7032 return;
7033 }
SongFerngWang0e767992021-03-31 22:08:45 +08007034 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7035 PersistableBundle c = configManager.getConfigForSubId(subId);
7036 boolean requireUssd = c.getBoolean(
7037 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007038
Shuo Qian4a594052020-01-23 11:59:30 -08007039 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007040 if (requireUssd) {
7041 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7042 getSubscriptionCarrierId(subId));
7043 String newUssdCommand = "";
7044 try {
7045 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007046 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007047 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7048 } catch (NullPointerException e) {
7049 loge("Failed to generate USSD number" + e);
7050 }
7051 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7052 mMainThreadHandler, callback, carrierXmlParser,
7053 CarrierXmlParser.SsEntry.SSAction.QUERY);
7054 final String ussdCommand = newUssdCommand;
7055 Executors.newSingleThreadExecutor().execute(() -> {
7056 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7057 });
7058 } else {
7059 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7060 callback::accept);
7061 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7062 }
Shuo Qian4a594052020-01-23 11:59:30 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
7067
7068 /**
Hall Liu27d24262020-09-18 19:04:59 -07007069 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007070 */
7071 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007072 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007073 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007074
7075 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7076 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7077
Shuo Qian4a594052020-01-23 11:59:30 -08007078 long identity = Binder.clearCallingIdentity();
7079 try {
Hall Liu27d24262020-09-18 19:04:59 -07007080 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7081
7082 Phone phone = getPhone(subId);
7083 if (phone == null) {
7084 try {
7085 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7086 } catch (RemoteException e) {
7087 // ignore
7088 }
7089 return;
7090 }
7091
SongFerngWang0e767992021-03-31 22:08:45 +08007092 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7093 PersistableBundle c = configManager.getConfigForSubId(subId);
7094 boolean requireUssd = c.getBoolean(
7095 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007096
SongFerngWang0e767992021-03-31 22:08:45 +08007097 if (DBG) log("getCallWaitingStatus: subId " + subId);
7098 if (requireUssd) {
7099 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7100 getSubscriptionCarrierId(subId));
7101 CarrierXmlParser.SsEntry.SSAction ssAction =
7102 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7103 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7104 String newUssdCommand = "";
7105 try {
7106 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007107 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007108 .makeCommand(ssAction, null);
7109 } catch (NullPointerException e) {
7110 loge("Failed to generate USSD number" + e);
7111 }
7112 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7113 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7114 final String ussdCommand = newUssdCommand;
7115 Executors.newSingleThreadExecutor().execute(() -> {
7116 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7117 });
7118 } else {
7119 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7120 FunctionalUtils.ignoreRemoteException(callback::accept));
7121
7122 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7123 }
Shuo Qian4a594052020-01-23 11:59:30 -08007124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
7127 }
7128
7129 /**
yinxub1bed742017-04-17 11:45:04 -07007130 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007131 *
yinxub1bed742017-04-17 11:45:04 -07007132 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007133 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7134 * location related information which will be sent if the caller already possess
7135 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007136 * @param request contains the radio access networks with bands/channels to scan
7137 * @param messenger callback messenger for scan results or errors
7138 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007139 * @return the id of the requested scan which can be used to stop the scan.
7140 */
7141 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007142 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7143 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007144 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7146 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007147 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007148 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7149 if (!renounceFineLocationAccess) {
7150 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7152 .setCallingPackage(callingPackage)
7153 .setCallingFeatureId(callingFeatureId)
7154 .setCallingPid(Binder.getCallingPid())
7155 .setCallingUid(Binder.getCallingUid())
7156 .setMethod("requestNetworkScan")
7157 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7159 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7160 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007161 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007162 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007163 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7164 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007165 if (e != null) {
7166 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7167 throw e;
7168 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007169 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007170 return TelephonyScanManager.INVALID_SCAN_ID;
7171 }
7172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 }
joonhunshin4ac60942023-11-15 15:23:39 +00007174
7175 enforceTelephonyFeatureWithException(callingPackage,
7176 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7177
Hall Liu912dfd32019-04-25 14:02:26 -07007178 int callingUid = Binder.getCallingUid();
7179 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007183 renounceFineLocationAccess, request, messenger, binder,
7184 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007185 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
yinxu504e1392017-04-12 16:03:22 -07007189 }
7190
Hall Liub2ac8ef2019-02-28 15:56:23 -08007191 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007192 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007193 boolean hasCarrierPriv;
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7197 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
Hall Liu558027f2019-05-15 19:14:05 -07007201 boolean hasNetworkScanPermission =
7202 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007203 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007204
7205 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7206 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7207 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007208 }
7209
7210 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7211 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007212 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7213 return new SecurityException("Specific channels must not be"
7214 + " scanned without location access.");
7215 }
7216 }
7217 }
7218
Hall Liub2ac8ef2019-02-28 15:56:23 -08007219 return null;
7220 }
7221
yinxu504e1392017-04-12 16:03:22 -07007222 /**
7223 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007224 *
7225 * @param subId id of the subscription
7226 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007227 */
7228 @Override
7229 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7231 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232
Hall Liu912dfd32019-04-25 14:02:26 -07007233 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 final long identity = Binder.clearCallingIdentity();
7235 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007236 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 } finally {
7238 Binder.restoreCallingIdentity(identity);
7239 }
yinxu504e1392017-04-12 16:03:22 -07007240 }
7241
7242 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007243 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007244 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007245 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007246 */
7247 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007248 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007249 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007250 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007251 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252
joonhunshin4ac60942023-11-15 15:23:39 +00007253 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7254 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007258 if (DBG) log("getAllowedNetworkTypesBitmask");
7259 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7260 int networkTypesBitmask = (result != null ? result[0] : -1);
7261 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7262 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 } finally {
7264 Binder.restoreCallingIdentity(identity);
7265 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007266 }
7267
7268 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007269 * Get the allowed network types for certain reason.
7270 *
7271 * @param subId the id of the subscription.
7272 * @param reason the reason the allowed network type change is taking place
7273 * @return the allowed network types.
7274 */
7275 @Override
7276 public long getAllowedNetworkTypesForReason(int subId,
7277 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007279 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007280
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007281 if (!mApp.getResources().getBoolean(
7282 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7284 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7285 "getAllowedNetworkTypesForReason");
7286 }
joonhunshin4ac60942023-11-15 15:23:39 +00007287
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007288 final long identity = Binder.clearCallingIdentity();
7289 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007290 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295
7296 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007297 * Enable/Disable E-UTRA-NR Dual Connectivity
7298 * @param subId subscription id of the sim card
7299 * @param nrDualConnectivityState expected NR dual connectivity state
7300 * This can be passed following states
7301 * <ol>
7302 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7303 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7304 * <li>Disable NR dual connectivity and force secondary cell to be released
7305 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7306 * </ol>
7307 * @return operation result.
7308 */
7309 @Override
7310 public int setNrDualConnectivityState(int subId,
7311 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7313 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007314 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007315 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7316 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7317 }
7318
Sooraj Sasindran37444802020-08-11 10:40:43 -07007319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7323 nrDualConnectivityState, subId,
7324 workSource);
7325 if (DBG) log("enableNRDualConnectivity result: " + result);
7326 return result;
7327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
7331
7332 /**
7333 * Is E-UTRA-NR Dual Connectivity enabled
7334 * @return true if dual connectivity is enabled else false
7335 */
7336 @Override
7337 public boolean isNrDualConnectivityEnabled(int subId) {
7338 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007339 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007340 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007341 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007342 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7343 return false;
7344 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007345 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7349 null, subId, workSource);
7350 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7351 return isEnabled;
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
7355 }
7356
7357 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007358 * Set the allowed network types of the device and
7359 * provide the reason triggering the allowed network change.
7360 *
7361 * @param subId the id of the subscription.
7362 * @param reason the reason the allowed network type change is taking place
7363 * @param allowedNetworkTypes the allowed network types.
7364 * @return true on success; false on any failure.
7365 */
7366 @Override
7367 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007368 @TelephonyManager.AllowedNetworkTypesReason int reason,
7369 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7371 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007372 // If the caller only has carrier privileges, then they should not be able to override
7373 // any network types which were set for security reasons.
7374 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7375 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007376 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007377 throw new SecurityException(
7378 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007379 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007380 }
joonhunshin4ac60942023-11-15 15:23:39 +00007381
7382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7383 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7384
SongFerngWang3ef3e072020-12-21 16:41:52 +08007385 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007386 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007387 return false;
7388 }
7389 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7390 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007391 return false;
7392 }
7393
Jack Yu5b494332023-01-23 18:18:04 +00007394 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7395 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007396
Jack Yue37dd262022-12-16 11:53:37 -08007397 Phone phone = getPhone(subId);
7398 if (phone == null) {
7399 return false;
7400 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007401
Jack Yue37dd262022-12-16 11:53:37 -08007402 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007403 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007404 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007405 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007406
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007407 final long identity = Binder.clearCallingIdentity();
7408 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007409 Boolean success = (Boolean) sendRequest(
7410 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7411 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7412
7413 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7414 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 }
7419
7420 /**
Miaoa84611c2019-03-15 09:21:10 +08007421 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007422 *
Miaoa84611c2019-03-15 09:21:10 +08007423 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007424 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007425 * @hide
7426 */
7427 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007428 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007429 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007430
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007431 if (!mApp.getResources().getBoolean(
7432 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7434 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7435 }
joonhunshin4ac60942023-11-15 15:23:39 +00007436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 try {
Miaoa84611c2019-03-15 09:21:10 +08007440 if (phone != null) {
7441 return phone.hasMatchedTetherApnSetting();
7442 } else {
7443 return false;
7444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 } finally {
7446 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007447 }
Junda Liu475951f2014-11-07 16:45:03 -08007448 }
7449
7450 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007451 * Get the user enabled state of Mobile Data.
7452 *
7453 * TODO: remove and use isUserDataEnabled.
7454 * This can't be removed now because some vendor codes
7455 * calls through ITelephony directly while they should
7456 * use TelephonyManager.
7457 *
7458 * @return true on enabled
7459 */
7460 @Override
7461 public boolean getDataEnabled(int subId) {
7462 return isUserDataEnabled(subId);
7463 }
7464
7465 /**
7466 * Get whether mobile data is enabled per user setting.
7467 *
7468 * There are other factors deciding whether mobile data is actually enabled, but they are
7469 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007470 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7472 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007473 *
7474 * @return {@code true} if data is enabled else {@code false}
7475 */
7476 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007477 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007478 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007479 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007480 try {
7481 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7482 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007483 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007484 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7485 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007486 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007488 mApp, subId, functionName);
7489
Robert Greenwalt646120a2014-05-23 11:54:03 -07007490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
Jack Yu285100e2022-12-02 22:48:35 -08007494 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7496 Phone phone = PhoneFactory.getPhone(phoneId);
7497 if (phone != null) {
7498 boolean retVal = phone.isUserDataEnabled();
7499 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7500 return retVal;
7501 } else {
7502 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7503 return false;
7504 }
7505 } finally {
7506 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007507 }
7508 }
7509
7510 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007511 * Checks if the device is capable of mobile data by considering whether whether the
7512 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7513 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007514 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007515 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007516 */
7517 @Override
7518 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007519 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007520 try {
7521 try {
7522 mApp.enforceCallingOrSelfPermission(
7523 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007524 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007525 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 try {
7527 mApp.enforceCallingOrSelfPermission(
7528 android.Manifest.permission.READ_PHONE_STATE,
7529 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007530 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007531 mApp.enforceCallingOrSelfPermission(
7532 permission.READ_BASIC_PHONE_STATE, functionName);
7533 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007534 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007535 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007536 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538
joonhunshin4ac60942023-11-15 15:23:39 +00007539 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7540 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 final long identity = Binder.clearCallingIdentity();
7543 try {
Jack Yu285100e2022-12-02 22:48:35 -08007544 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007546 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007547 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007548 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 return retVal;
7550 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007551 if (DBG) {
7552 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7553 + subId + " retVal=false");
7554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 return false;
7556 }
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007559 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007560 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007561
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007562 /**
7563 * Check if data is enabled for a specific reason
7564 * @param subId Subscription index
7565 * @param reason the reason the data enable change is taking place
7566 * @return {@code true} if the overall data is enabled; {@code false} if not.
7567 */
7568 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007569 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007570 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007571 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007572 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007573 try {
7574 mApp.enforceCallingOrSelfPermission(
7575 android.Manifest.permission.ACCESS_NETWORK_STATE,
7576 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007577 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007578 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7579 functionName);
7580 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007581 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007582 try {
7583 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007584 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007585 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007587 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007588 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007589 }
7590
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007591 if (!mApp.getResources().getBoolean(
7592 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7593 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7594 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7595 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007596
7597 final long identity = Binder.clearCallingIdentity();
7598 try {
Jack Yu285100e2022-12-02 22:48:35 -08007599 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007601 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 + " reason=" + reason);
7603 }
7604 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007605 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007606 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007607 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007608 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007609 return retVal;
7610 } else {
7611 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007612 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007613 + subId + " retVal=false");
7614 }
7615 return false;
7616 }
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007622 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007623 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7626
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007627 // No permission needed; this only lets the caller inspect their own status.
7628 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007629 }
Junda Liu29340342014-07-10 15:23:27 -07007630
7631 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007632 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007633 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007634
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007635 if (!mApp.getResources().getBoolean(
7636 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7637 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7638 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7639 "getCarrierPrivilegeStatusForUid");
7640 }
joonhunshin4ac60942023-11-15 15:23:39 +00007641
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007642 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7643 }
7644
7645 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7646 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007647 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007648 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007649 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7650 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007651 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7652 if (cpt == null) {
7653 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007654 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7655 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007656 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007657 }
7658
7659 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007660 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007661 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007662
7663 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7664 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7665
chen xuf7e9fe82019-05-09 19:31:02 -07007666 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007668 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007669 Phone phone = getPhone(subId);
7670 if (phone == null) {
7671 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7672 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7673 }
7674 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7675 if (cpt == null) {
7676 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007677 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7678 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007679 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007680 }
7681
7682 @Override
7683 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007684 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007685
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007686 if (!mApp.getResources().getBoolean(
7687 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7689 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7690 "checkCarrierPrivilegesForPackageAnyPhone");
7691 }
joonhunshin4ac60942023-11-15 15:23:39 +00007692
Rambo Wange7209ce2022-02-23 13:41:02 -08007693 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7694 }
7695
7696 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007697 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007699 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007700 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7702 Phone phone = PhoneFactory.getPhone(phoneId);
7703 if (phone == null) {
7704 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007705 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007706 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7707 if (cpt == null) {
7708 continue;
7709 }
7710 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007711 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7712 break;
7713 }
7714 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007715 return result;
Junda Liu29340342014-07-10 15:23:27 -07007716 }
Derek Tan89e89d42014-07-08 17:00:10 -07007717
7718 @Override
Junda Liue64de782015-04-16 17:19:16 -07007719 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007720 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007721
7722 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7723 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7724 "getCarrierPackageNamesForIntentAndPhone");
7725
Rambo Wang8a247eb2022-02-08 21:11:18 +00007726 Phone phone = PhoneFactory.getPhone(phoneId);
7727 if (phone == null) {
7728 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007729 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007730 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7731 if (cpt == null) {
7732 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007733 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007734 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007735 }
7736
Amith Yamasani6e118872016-02-19 12:53:51 -08007737 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007738 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007739 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007740
7741 enforceTelephonyFeatureWithException(
7742 getCurrentPackageName(),
7743 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7744 "getPackagesWithCarrierPrivileges");
7745
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007746 Phone phone = PhoneFactory.getPhone(phoneId);
7747 if (phone == null) {
7748 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007749 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007750 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7751 if (cpt == null) {
7752 return Collections.emptyList();
7753 }
7754 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007755 }
7756
chen xuf7e9fe82019-05-09 19:31:02 -07007757 @Override
7758 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007759 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007760
7761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7762 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7763 "getPackagesWithCarrierPrivilegesForAllPhones");
7764
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007765 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007766 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007767 try {
7768 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7769 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7770 }
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007773 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007774 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007775 }
7776
Rambo Wang6812ffb2022-03-15 16:54:17 -07007777 @Override
7778 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7779 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7780
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007781 if (!mApp.getResources().getBoolean(
7782 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7784 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7785 "getCarrierServicePackageNameForLogicalSlot");
7786 }
joonhunshin4ac60942023-11-15 15:23:39 +00007787
Rambo Wang6812ffb2022-03-15 16:54:17 -07007788 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7789 if (phone == null) {
7790 return null;
7791 }
7792 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7793 if (cpt == null) {
7794 return null;
7795 }
7796 return cpt.getCarrierServicePackageName();
7797 }
7798
Wink Savilleb564aae2014-10-23 10:18:09 -07007799 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007800 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007801 UiccPort port = phone == null ? null : phone.getUiccPort();
7802 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007803 return null;
7804 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007805 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007806 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007807 return null;
7808 }
7809 return iccId;
7810 }
7811
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007812 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007813 public void setCallComposerStatus(int subId, int status) {
7814 enforceModifyPermission();
7815
joonhunshin4ac60942023-11-15 15:23:39 +00007816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7817 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7818
Shuo Qiane4e11672020-12-15 22:15:33 -08007819 final long identity = Binder.clearCallingIdentity();
7820 try {
7821 Phone phone = getPhone(subId);
7822 if (phone != null) {
7823 Phone defaultPhone = phone.getImsPhone();
7824 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7825 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7826 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007827 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7828 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007829 }
7830 }
Shuo Qian284ae752020-12-22 19:10:14 -08007831 } catch (ImsException e) {
7832 throw new ServiceSpecificException(e.getCode());
7833 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007834 Binder.restoreCallingIdentity(identity);
7835 }
7836 }
7837
7838 @Override
7839 public int getCallComposerStatus(int subId) {
7840 enforceReadPrivilegedPermission("getCallComposerStatus");
7841
joonhunshin4ac60942023-11-15 15:23:39 +00007842 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7843 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7844
Shuo Qiane4e11672020-12-15 22:15:33 -08007845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 Phone phone = getPhone(subId);
7848 if (phone != null) {
7849 Phone defaultPhone = phone.getImsPhone();
7850 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7851 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7852 return imsPhone.getCallComposerStatus();
7853 }
7854 }
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
7857 }
7858 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7859 }
7860
7861 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007862 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7863 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007864 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007865 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007866
joonhunshin4ac60942023-11-15 15:23:39 +00007867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7868 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7869 "setLine1NumberForDisplayForSubscriber");
7870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 final String iccId = getIccId(subId);
7874 final Phone phone = getPhone(subId);
7875 if (phone == null) {
7876 return false;
7877 }
arunvoddub1365e62024-07-31 09:42:31 +00007878 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7879 Rlog.e(LOG_TAG, "Number is too long");
7880 return false;
7881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final String subscriberId = phone.getSubscriberId();
7883
7884 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007885 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 + subscriberId + " to " + number);
7887 }
7888
7889 if (TextUtils.isEmpty(iccId)) {
7890 return false;
7891 }
7892
7893 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7894
7895 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7896 if (alphaTag == null) {
7897 editor.remove(alphaTagPrefKey);
7898 } else {
7899 editor.putString(alphaTagPrefKey, alphaTag);
7900 }
7901
7902 // Record both the line number and IMSI for this ICCID, since we need to
7903 // track all merged IMSIs based on line number
7904 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7905 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7906 if (number == null) {
7907 editor.remove(numberPrefKey);
7908 editor.remove(subscriberPrefKey);
7909 } else {
7910 editor.putString(numberPrefKey, number);
7911 editor.putString(subscriberPrefKey, subscriberId);
7912 }
7913
7914 editor.commit();
7915 return true;
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007918 }
Derek Tan7226c842014-07-02 17:42:23 -07007919 }
7920
7921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 public String getLine1NumberForDisplay(int subId, String callingPackage,
7923 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007924 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007926 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007927 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007928 return null;
7929 }
Derek Tan97ebb422014-09-05 16:55:38 -07007930
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007931 if (!mApp.getResources().getBoolean(
7932 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7933 enforceTelephonyFeatureWithException(callingPackage,
7934 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7935 }
joonhunshin4ac60942023-11-15 15:23:39 +00007936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 final long identity = Binder.clearCallingIdentity();
7938 try {
7939 String iccId = getIccId(subId);
7940 if (iccId != null) {
7941 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7942 if (DBG_MERGE) {
7943 log("getLine1NumberForDisplay returning "
7944 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7945 }
7946 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7949 return null;
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007952 }
Derek Tan7226c842014-07-02 17:42:23 -07007953 }
7954
7955 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007956 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7957 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007959 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007960 return null;
7961 }
Derek Tan97ebb422014-09-05 16:55:38 -07007962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 String iccId = getIccId(subId);
7966 if (iccId != null) {
7967 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7968 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7969 }
7970 return null;
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007973 }
Derek Tan7226c842014-07-02 17:42:23 -07007974 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007975
7976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007977 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7978 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007979 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7980 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007982 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007983 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007984 return null;
7985 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007986
Jordan Liub49b04b2019-05-06 14:45:15 -07007987 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7988 // the process, where TelephonyManager was instantiated.
7989 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007990 final long identity = Binder.clearCallingIdentity();
7991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 final TelephonyManager tele = TelephonyManager.from(context);
7994 final SubscriptionManager sub = SubscriptionManager.from(context);
7995
7996 // Figure out what subscribers are currently active
7997 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998
Jordan Liub49b04b2019-05-06 14:45:15 -07007999 // Only consider subs which match the current subId
8000 // This logic can be simplified. See b/131189269 for progress.
8001 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008002 activeSubscriberIds.add(tele.getSubscriberId(subId));
8003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004
8005 // First pass, find a number override for an active subscriber
8006 String mergeNumber = null;
8007 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8008 for (String key : prefs.keySet()) {
8009 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8010 final String subscriberId = (String) prefs.get(key);
8011 if (activeSubscriberIds.contains(subscriberId)) {
8012 final String iccId = key.substring(
8013 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8014 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8015 mergeNumber = (String) prefs.get(numberKey);
8016 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008017 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 + " for active subscriber " + subscriberId);
8019 }
8020 if (!TextUtils.isEmpty(mergeNumber)) {
8021 break;
8022 }
8023 }
8024 }
8025 }
8026
8027 // Shortcut when no active merged subscribers
8028 if (TextUtils.isEmpty(mergeNumber)) {
8029 return null;
8030 }
8031
8032 // Second pass, find all subscribers under that line override
8033 final ArraySet<String> result = new ArraySet<>();
8034 for (String key : prefs.keySet()) {
8035 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8036 final String number = (String) prefs.get(key);
8037 if (mergeNumber.equals(number)) {
8038 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8039 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8040 final String subscriberId = (String) prefs.get(subscriberKey);
8041 if (!TextUtils.isEmpty(subscriberId)) {
8042 result.add(subscriberId);
8043 }
8044 }
8045 }
8046 }
8047
8048 final String[] resultArray = result.toArray(new String[result.size()]);
8049 Arrays.sort(resultArray);
8050 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008051 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8053 }
8054 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008055 } finally {
8056 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008057 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008058 }
8059
8060 @Override
zoey chen38003472019-12-13 17:16:31 +08008061 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8062 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008063
joonhunshin4ac60942023-11-15 15:23:39 +00008064 enforceTelephonyFeatureWithException(callingPackage,
8065 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8066
Malcolm Chen6ca97372019-07-01 16:28:21 -07008067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 final TelephonyManager telephonyManager = mApp.getSystemService(
8070 TelephonyManager.class);
8071 String subscriberId = telephonyManager.getSubscriberId(subId);
8072 if (subscriberId == null) {
8073 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008074 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008075 + subId);
8076 }
8077 return null;
8078 }
8079
Jack Yu3beaf9d2023-04-14 09:17:27 -07008080 final SubscriptionInfo info = getSubscriptionManagerService()
8081 .getSubscriptionInfo(subId);
8082 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008083 // If it doesn't belong to any group, return just subscriberId of itself.
8084 if (groupUuid == null) {
8085 return new String[]{subscriberId};
8086 }
8087
8088 // Get all subscriberIds from the group.
8089 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008090 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8091 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8092 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008093 for (SubscriptionInfo subInfo : groupInfos) {
8094 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8095 if (subscriberId != null) {
8096 mergedSubscriberIds.add(subscriberId);
8097 }
8098 }
8099
8100 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103
8104 }
8105 }
8106
8107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008108 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008109 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008110 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111
joonhunshin4ac60942023-11-15 15:23:39 +00008112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8113 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 final long identity = Binder.clearCallingIdentity();
8116 try {
8117 final Phone phone = getPhone(subId);
8118 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
8121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008122 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008123
8124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008125 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008126 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8127 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8129 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 final Phone phone = getPhone(subId);
8134 if (phone == null) {
8135 return false;
8136 }
8137 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8138 cdmaNonRoamingList);
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008141 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008142 }
8143
8144 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008145 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008146 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008147 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008148 if (phone == null) {
8149 return raf;
8150 }
8151
Shuo Qiandee53402020-05-29 14:08:15 -07008152 try {
8153 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008154 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008155 mApp, phone.getSubId(), "getRadioAccessFamily");
8156 } catch (SecurityException e) {
8157 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8158 throw e;
8159 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008160
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008161 if (!mApp.getResources().getBoolean(
8162 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8163 enforceTelephonyFeatureWithException(callingPackage,
8164 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8165 }
joonhunshin4ac60942023-11-15 15:23:39 +00008166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 final long identity = Binder.clearCallingIdentity();
8168 try {
chen xub97461a2018-10-26 14:17:57 -07008169 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 } finally {
8171 Binder.restoreCallingIdentity(identity);
8172 }
chen xub97461a2018-10-26 14:17:57 -07008173 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008174 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008175
8176 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008177 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008178 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008179 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8180 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008181 enforceTelephonyFeatureWithException(callingPackage,
8182 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8183
Hall Liu82694d52020-12-11 18:22:04 -08008184 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008185 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008186 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8187 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008188 if (!dialerRoleHolders.contains(callingPackage)) {
8189 throw new SecurityException("App must be the dialer role holder to"
8190 + " upload a call composer pic");
8191 }
8192
8193 Executors.newSingleThreadExecutor().execute(() -> {
8194 ByteArrayOutputStream output = new ByteArrayOutputStream(
8195 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8196 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8197 boolean readUntilEnd = false;
8198 int totalBytesRead = 0;
8199 byte[] buffer = new byte[16 * 1024];
8200 while (true) {
8201 int numRead;
8202 try {
8203 numRead = input.read(buffer);
8204 } catch (IOException e) {
8205 try {
8206 fd.checkError();
8207 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8208 null);
8209 } catch (IOException e1) {
8210 // This means that the other side closed explicitly with an error. If this
8211 // happens, log and ignore.
8212 loge("Remote end of call composer picture pipe closed: " + e1);
8213 }
8214 break;
8215 }
8216 if (numRead == -1) {
8217 readUntilEnd = true;
8218 break;
8219 }
8220 totalBytesRead += numRead;
8221 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8222 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8223 try {
8224 input.close();
8225 } catch (IOException e) {
8226 // ignore
8227 }
8228 break;
8229 }
8230 output.write(buffer, 0, numRead);
8231 }
8232 // Generally, the remote end will close the file descriptors. The only case where we
8233 // close is above, where the picture size is too big.
8234
8235 try {
8236 fd.checkError();
8237 } catch (IOException e) {
8238 loge("Remote end for call composer closed with an error: " + e);
8239 return;
8240 }
8241
Hall Liuaa4211e2021-01-20 15:43:39 -08008242 if (!readUntilEnd) {
8243 loge("Did not finish reading entire image; aborting");
8244 return;
8245 }
Hall Liu82694d52020-12-11 18:22:04 -08008246
Hall Liuaa4211e2021-01-20 15:43:39 -08008247 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8248 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8249 new CallComposerPictureTransfer.Factory() {},
8250 imageData,
8251 (result) -> {
8252 if (result.first != null) {
8253 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8254 Bundle outputResult = new Bundle();
8255 outputResult.putParcelable(
8256 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8257 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8258 outputResult);
8259 } else {
8260 callback.send(result.second, null);
8261 }
8262 }
8263 );
Hall Liu82694d52020-12-11 18:22:04 -08008264 });
8265 }
8266
8267 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008268 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008270 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271
joonhunshin4ac60942023-11-15 15:23:39 +00008272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8273 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 final long identity = Binder.clearCallingIdentity();
8276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 ImsManager.getInstance(defaultPhone.getContext(),
8278 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008282 }
8283
8284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008286 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8288 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008289 return false;
8290 }
Svet Ganovb320e182015-04-16 12:30:10 -07008291
joonhunshin4ac60942023-11-15 15:23:39 +00008292 enforceTelephonyFeatureWithException(callingPackage,
8293 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 // Check the user preference and the system-level IMS setting. Even if the user has
8298 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8299 // In the long run, we may instead need to check if there exists a connection service
8300 // which can support video calling.
8301 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008302 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 return imsManager.isVtEnabledByPlatform()
8304 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8305 && imsManager.isVtEnabledByUser();
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008309 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008310
Andrew Leea1239f22015-03-02 17:44:07 -08008311 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008312 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8313 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008315 mApp, subId, callingPackage, callingFeatureId,
8316 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 return false;
8318 }
8319
joonhunshin4ac60942023-11-15 15:23:39 +00008320 enforceTelephonyFeatureWithException(callingPackage,
8321 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 CarrierConfigManager configManager =
8326 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008327 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
Andrew Leea1239f22015-03-02 17:44:07 -08008332 }
8333
8334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008335 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008337 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 return false;
8339 }
8340
joonhunshin4ac60942023-11-15 15:23:39 +00008341 enforceTelephonyFeatureWithException(callingPackage,
8342 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 CarrierConfigManager configManager =
8347 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008348 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
Andrew Leea1239f22015-03-02 17:44:07 -08008353 }
8354
Andrew Lee9431b832015-03-09 18:46:45 -07008355 @Override
8356 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008357 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008358 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008359 }
8360
8361 @Override
8362 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008363 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8364 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 final long identity = Binder.clearCallingIdentity();
8367 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008368 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
Andrew Lee9431b832015-03-09 18:46:45 -07008372 }
8373
Hall Liuf6668912018-10-31 17:05:23 -07008374 /**
8375 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8376 * support for the feature and device firmware support.
8377 *
8378 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8379 */
8380 @Override
8381 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8383 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008386 final Phone phone = getPhone(subscriptionId);
8387 if (phone == null) {
8388 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8389 return false;
8390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008392 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008394 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8395 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8396 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397 return isCarrierSupported && isDeviceSupported;
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
8400 }
Hall Liu98187582018-01-22 19:15:32 -08008401 }
8402
Hall Liuf6668912018-10-31 17:05:23 -07008403 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008404 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8405 * RTT setting, will return true if the device and carrier both support RTT.
8406 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008407 */
8408 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409 final long identity = Binder.clearCallingIdentity();
8410 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008411 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8412 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8413 return false;
8414 }
8415 }
8416
Hall Liu5bab75c2019-12-11 23:58:20 +00008417 boolean isRttSupported = isRttSupported(subscriptionId);
8418 boolean isUserRttSettingOn = Settings.Secure.getInt(
8419 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8420 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8421 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8422 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008426 }
8427
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008428 @Deprecated
8429 @Override
8430 public String getDeviceId(String callingPackage) {
8431 return getDeviceIdWithFeature(callingPackage, null);
8432 }
8433
Sanket Padawe7310cc72015-01-14 09:53:20 -08008434 /**
8435 * Returns the unique device ID of phone, for example, the IMEI for
8436 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8437 *
8438 * <p>Requires Permission:
8439 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8440 */
8441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008443 try {
8444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8445 } catch (SecurityException se) {
8446 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8447 throw new SecurityException("Package " + callingPackage + " does not belong to "
8448 + Binder.getCallingUid());
8449 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008450 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008451 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008452 return null;
8453 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008454 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008455 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008457 return null;
8458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459
8460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 return phone.getDeviceId();
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008466 }
8467
Ping Sunc67b7c22016-03-02 19:16:45 +08008468 /**
8469 * {@hide}
8470 * Returns the IMS Registration Status on a particular subid
8471 *
8472 * @param subId
8473 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008474 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008475 Phone phone = getPhone(subId);
8476 if (phone != null) {
8477 return phone.isImsRegistered();
8478 } else {
8479 return false;
8480 }
8481 }
8482
Santos Cordon7a1885b2015-02-03 11:15:19 -08008483 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008484 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008485 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008487 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008488 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8489 }
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
8496 }
8497
8498 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008499 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008502 mApp,
8503 subscriptionId,
8504 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8505 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008506
8507 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8508 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8509
Tyler Gunnf70ed162019-04-03 15:28:53 -07008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 Phone phone = getPhone(subscriptionId);
8513 if (phone == null) {
8514 return null;
8515 }
8516 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008522 /**
8523 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008524 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008525 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 Phone phone = getPhone(subId);
8529 if (phone != null) {
8530 return phone.isWifiCallingEnabled();
8531 } else {
8532 return false;
8533 }
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008536 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008537 }
8538
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008540 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008541 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008542 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 Phone phone = getPhone(subId);
8546 if (phone != null) {
8547 return phone.isVideoEnabled();
8548 } else {
8549 return false;
8550 }
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008553 }
8554 }
8555
8556 /**
8557 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8558 * defined in {@link ImsRegistrationImplBase}.
8559 */
8560 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 Phone phone = getPhone(subId);
8564 if (phone != null) {
8565 return phone.getImsRegistrationTech();
8566 } else {
8567 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8568 }
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008571 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008572 }
8573
Stuart Scott8eef64f2015-04-08 15:13:54 -07008574 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008575 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008576 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008577
8578 enforceTelephonyFeatureWithException(callingPackage,
8579 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8580
Stuart Scott981d8582015-04-21 14:09:50 -07008581 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8582 return;
8583 }
Kai Shif70f46f2021-03-03 13:59:46 -08008584 Phone defaultPhone = getDefaultPhone();
8585 if (defaultPhone != null) {
8586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8587 mApp, getDefaultPhone().getSubId(), "factoryReset");
8588 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008589 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008590
Svet Ganovcc087f82015-05-12 20:35:54 -07008591 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008592 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8593 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008594 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008595 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008596 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008597 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008598 cleanUpAllowedNetworkTypes(phone, subId);
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008599
Rambo Wang71f6aa62024-02-23 20:16:22 +00008600 setDataRoamingEnabled(subId, phone == null ? false
8601 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008602 getPhone(subId).resetCarrierKeysForImsiEncryption(true);
Svet Ganovcc087f82015-05-12 20:35:54 -07008603 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008604 // There has been issues when Sms raw table somehow stores orphan
8605 // fragments. They lead to garbled message when new fragments come
8606 // in and combined with those stale ones. In case this happens again,
8607 // user can reset all network settings which will clean up this table.
8608 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008609 // Clean up IMS settings as well here.
8610 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008611 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008612 ImsManager.getInstance(mApp, slotId).factoryReset();
8613 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008614
Kai Shif70f46f2021-03-03 13:59:46 -08008615 if (defaultPhone == null) {
8616 return;
8617 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008618 // Erase modem config if erase modem on network setting is enabled.
8619 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8620 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8621 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008622 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008623 }
Kai Shif70f46f2021-03-03 13:59:46 -08008624
8625 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008626 } finally {
8627 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008628 }
8629 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008630
SongFerngWangfd89b102021-05-27 22:44:54 +08008631 @VisibleForTesting
8632 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8633 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8634 return;
8635 }
8636 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8637 RILConstants.PREFERRED_NETWORK_MODE);
8638 SubscriptionManager.setSubscriptionProperty(subId,
8639 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8640 "user=" + defaultNetworkType);
8641 phone.loadAllowedNetworksFromSubscriptionDatabase();
8642 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8643 defaultNetworkType, null);
8644 }
8645
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008646 private void cleanUpSmsRawTable(Context context) {
8647 ContentResolver resolver = context.getContentResolver();
8648 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8649 resolver.delete(uri, null, null);
8650 }
8651
Narayan Kamath1c496c22015-04-16 14:40:19 +01008652 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008653 public String getSimLocaleForSubscriber(int subId) {
8654 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008655
8656 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8657 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8658
chen xu5d3637b2019-01-21 23:31:38 -08008659 final Phone phone = getPhone(subId);
8660 if (phone == null) {
8661 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008662 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 final long identity = Binder.clearCallingIdentity();
8665 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008666 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8667 phone.getContext().getOpPackageName(),
8668 phone.getContext().getAttributionTag());
8669 if (info == null) {
8670 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8671 return null;
chen xu6291c472019-02-04 12:55:53 -08008672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673 // Try and fetch the locale from the carrier properties or from the SIM language
8674 // preferences (EF-PL and EF-LI)...
8675 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008676 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008677 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8678 if (localeFromDefaultSim != null) {
8679 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8680 if (DBG) log("Using locale from subId: " + subId + " locale: "
8681 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008682 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008683 } else {
8684 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008685 }
8686 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008688 // The SIM language preferences only store a language (e.g. fr = French), not an
8689 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8690 // the SIM and carrier preferences does not include a country we add the country
8691 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008692 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008693 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008694 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008695 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008696 }
8697
8698 if (DBG) log("No locale found - returning null");
8699 return null;
8700 } finally {
8701 Binder.restoreCallingIdentity(identity);
8702 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008703 }
8704
tom hsu0b59d292022-09-29 23:49:21 +08008705 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008706 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008707 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008708 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008709 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008710 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8711 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008712 Locale.forLanguageTag(localeTag).getCountry())) {
8713 return localeTag;
8714 }
8715 }
8716 return inputLocale.toLanguageTag();
8717 }
8718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008719 /**
8720 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8721 */
8722 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008723 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008724 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008725 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008726
Gary Jian3aa9a762022-01-24 16:41:19 +08008727 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8728 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008729
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008730 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008731 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8732 * representing the state of the modem.
8733 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008734 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8735 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008736 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008737 */
8738 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008739 public void requestModemActivityInfo(ResultReceiver result) {
8740 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008741
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008742 if (!mApp.getResources().getBoolean(
8743 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8745 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8746 }
joonhunshin4ac60942023-11-15 15:23:39 +00008747
vagdeviaf9a5b92018-08-15 16:01:53 -07008748 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008749
8750 final long identity = Binder.clearCallingIdentity();
8751 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008752 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008753 } finally {
8754 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008755 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008756 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008757
Gary Jian76280a42022-12-07 16:18:33 +08008758 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008759 // less than total activity duration.
8760 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8761 if (info == null) {
8762 return false;
8763 }
8764 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008765 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008766 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8767
Hall Liu49656c02020-10-09 19:00:11 -07008768 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8769
Siddharth Rayb8114062018-06-17 15:02:38 -07008770 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 && (info.getSleepTimeMillis() <= activityDurationMs)
8772 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008773 }
8774
Gary Jian3aa9a762022-01-24 16:41:19 +08008775 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8776 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8777 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8778 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8779
8780 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8781 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8782 }
8783
8784 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8785 mLastModemActivityInfo.setReceiveTimeMillis(
8786 rat,
8787 freq,
8788 info.getReceiveTimeMillis(rat, freq)
8789 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8790 }
8791
8792 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8793 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8794 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8795 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8796
8797 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8798 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8799 }
8800 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8801 mLastModemActivityInfo.setReceiveTimeMillis(
8802 rat,
8803 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8804 }
8805
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008806 /**
8807 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8808 * @param info recent ModemActivityInfo
8809 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008810 private void mergeModemActivityInfo(ModemActivityInfo info) {
8811 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008812 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008813 boolean matched;
8814 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8815 matched = false;
8816 int rat = info.getSpecificInfoRat(i);
8817 int freq = info.getSpecificInfoFrequencyRange(i);
8818 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8819 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8820 //if it already exists
8821 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8822 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8823 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8824 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8825 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8826 updateLastModemActivityInfo(info, rat, freq);
8827 matched = true;
8828 }
8829 } else {
8830 updateLastModemActivityInfo(info, rat);
8831 matched = true;
8832 }
8833 }
8834 }
8835
8836 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008837 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008838 new ActivityStatsTechSpecificInfo(
8839 rat,
8840 freq,
8841 info.getTransmitTimeMillis(rat, freq),
8842 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008843 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008844 }
8845 }
8846 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8847 mLastModemActivitySpecificInfo =
8848 new ActivityStatsTechSpecificInfo[merged.size()];
8849 merged.toArray(mLastModemActivitySpecificInfo);
8850
8851 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8852 mLastModemActivityInfo.setSleepTimeMillis(
8853 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008854 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008855 mLastModemActivityInfo.setIdleTimeMillis(
8856 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008857 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008858
8859 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008860 new ModemActivityInfo(
8861 mLastModemActivityInfo.getTimestampMillis(),
8862 mLastModemActivityInfo.getSleepTimeMillis(),
8863 mLastModemActivityInfo.getIdleTimeMillis(),
8864 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008865 }
8866
8867 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8868 ActivityStatsTechSpecificInfo[] info) {
8869 int infoSize = info.length;
8870 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8871 for (int i = 0; i < infoSize; i++) {
8872 ret[i] = new ActivityStatsTechSpecificInfo(
8873 info[i].getRat(), info[i].getFrequencyRange(),
8874 info[i].getTransmitTimeMillis(),
8875 (int) info[i].getReceiveTimeMillis());
8876 }
8877 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008878 }
8879
Jack Yu85bd38a2015-11-09 11:34:32 -08008880 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008881 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008882 */
8883 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008884 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8885 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8886 Phone phone = PhoneFactory.getPhone(slotIndex);
8887 if (phone == null) {
8888 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8889 return null;
8890 }
8891
8892 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008894 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008895 return null;
8896 }
8897
joonhunshin4ac60942023-11-15 15:23:39 +00008898 enforceTelephonyFeatureWithException(callingPackage,
8899 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8900
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008901 boolean hasFinePermission = false;
8902 boolean hasCoarsePermission = false;
8903 if (!renounceFineLocationAccess) {
8904 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8905 LocationAccessPolicy.checkLocationPermission(mApp,
8906 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8907 .setCallingPackage(callingPackage)
8908 .setCallingFeatureId(callingFeatureId)
8909 .setCallingPid(Binder.getCallingPid())
8910 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008911 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008912 .setLogAsInfo(true)
8913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8914 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8915 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8916 .build());
8917 hasFinePermission =
8918 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8919 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008920
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008921 if (!renounceCoarseLocationAccess) {
8922 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8923 LocationAccessPolicy.checkLocationPermission(mApp,
8924 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8925 .setCallingPackage(callingPackage)
8926 .setCallingFeatureId(callingFeatureId)
8927 .setCallingPid(Binder.getCallingPid())
8928 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008929 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008930 .setLogAsInfo(true)
8931 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8932 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8933 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8934 .build());
8935 hasCoarsePermission =
8936 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8937 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008938
Jordan Liu0f2bc442020-11-18 16:47:37 -08008939 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008941 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8942 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008943 if (subInfo != null && !subInfo.isActive()) {
8944 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008945 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008946 }
8947
Hall Liuf19c44f2018-11-27 14:38:17 -08008948 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008949 boolean isCallingPackageDataService = phone.getDataServicePackages()
8950 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008951
8952 // Scrub out the location info in ServiceState depending on what level of access
8953 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008954 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008955 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8956 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 } finally {
8958 Binder.restoreCallingIdentity(identity);
8959 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008961
8962 /**
8963 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8964 *
8965 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8966 * voicemail ringtone.
8967 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8968 * PhoneAccount.
8969 */
8970 @Override
8971 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008972 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8973 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 final long identity = Binder.clearCallingIdentity();
8976 try {
8977 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8978 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008979 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008986 }
8987
8988 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008989 * Sets the per-account voicemail ringtone.
8990 *
8991 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8992 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8993 *
8994 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8995 * voicemail ringtone.
8996 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8997 * PhoneAccount.
8998 */
8999 @Override
9000 public void setVoicemailRingtoneUri(String callingPackage,
9001 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009002 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009004 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9005 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9007 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9008 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009010
joonhunshin4ac60942023-11-15 15:23:39 +00009011 enforceTelephonyFeatureWithException(callingPackage,
9012 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9017 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009018 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 }
9020 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009023 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009024 }
9025
9026 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009027 * Returns whether vibration is set for voicemail notification in Phone settings.
9028 *
9029 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9030 * voicemail vibration setting.
9031 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9032 */
9033 @Override
9034 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9036 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9041 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009042 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9046 } finally {
9047 Binder.restoreCallingIdentity(identity);
9048 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009049 }
9050
Youhan Wange64578a2016-05-02 15:32:42 -07009051 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009052 * Sets the per-account voicemail vibration.
9053 *
9054 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9055 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9056 *
9057 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9058 * voicemail vibration setting.
9059 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9060 * specific PhoneAccount.
9061 */
9062 @Override
9063 public void setVoicemailVibrationEnabled(String callingPackage,
9064 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009065 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009067 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9068 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9070 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9071 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009072 }
9073
joonhunshin4ac60942023-11-15 15:23:39 +00009074 enforceTelephonyFeatureWithException(callingPackage,
9075 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077 final long identity = Binder.clearCallingIdentity();
9078 try {
9079 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9080 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009081 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009082 }
9083 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009086 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009087 }
9088
9089 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009090 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9091 *
9092 * @throws SecurityException if the caller does not have the required permission
9093 */
arunvoddud7401012022-12-15 16:08:12 +00009094 @VisibleForTesting
9095 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009097 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009098 }
9099
9100 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009101 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9102 * permission.
9103 *
9104 * @throws SecurityException if the caller does not have the required permission
9105 */
9106 private void enforceSendSmsPermission() {
9107 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9108 }
9109
9110 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009111 * Make sure either called from same process as self (phone) or IPC caller has interact across
9112 * users permission.
9113 *
9114 * @throws SecurityException if the caller does not have the required permission
9115 */
9116 private void enforceInteractAcrossUsersPermission(String message) {
9117 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9118 }
9119
9120 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009121 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009122 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009123 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009124 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009125 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009126 final long identity = Binder.clearCallingIdentity();
9127 try {
9128 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009129 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009130 if (componentName == null) {
9131 throw new SecurityException(
9132 "Caller not current active visual voicemail package[null]");
9133 }
9134 String vvmPackage = componentName.getPackageName();
9135 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009136 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009137 }
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009140 }
9141 }
9142
9143 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009144 * Return the application ID for the app type.
9145 *
9146 * @param subId the subscription ID that this request applies to.
9147 * @param appType the uicc app type.
9148 * @return Application ID for specificied app type, or null if no uicc.
9149 */
9150 @Override
9151 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009152 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009153
9154 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9155 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9156
Youhan Wange64578a2016-05-02 15:32:42 -07009157 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009158
9159 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009160 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161 if (phone == null) {
9162 return null;
9163 }
9164 String aid = null;
9165 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009166 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009167 .getApplicationByType(appType).getAid();
9168 } catch (Exception e) {
9169 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9170 }
9171 return aid;
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009174 }
Youhan Wange64578a2016-05-02 15:32:42 -07009175 }
9176
Youhan Wang4001d252016-05-11 10:29:41 -07009177 /**
9178 * Return the Electronic Serial Number.
9179 *
9180 * @param subId the subscription ID that this request applies to.
9181 * @return ESN or null if error.
9182 */
9183 @Override
9184 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009185 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009186 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187
9188 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009189 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009190 if (phone == null) {
9191 return null;
9192 }
9193 String esn = null;
9194 try {
9195 esn = phone.getEsn();
9196 } catch (Exception e) {
9197 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9198 }
9199 return esn;
9200 } finally {
9201 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009202 }
Youhan Wang4001d252016-05-11 10:29:41 -07009203 }
9204
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009205 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009206 * Return the Preferred Roaming List Version.
9207 *
9208 * @param subId the subscription ID that this request applies to.
9209 * @return PRLVersion or null if error.
9210 */
9211 @Override
9212 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009213 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009214
9215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9216 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9217
Youhan Wang66ad5d72016-07-18 17:56:58 -07009218 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009219
9220 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009221 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009222 if (phone == null) {
9223 return null;
9224 }
9225 String cdmaPrlVersion = null;
9226 try {
9227 cdmaPrlVersion = phone.getCdmaPrlVersion();
9228 } catch (Exception e) {
9229 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9230 }
9231 return cdmaPrlVersion;
9232 } finally {
9233 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009234 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009235 }
9236
9237 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009238 * Get snapshot of Telephony histograms
9239 * @return List of Telephony histograms
9240 * @hide
9241 */
9242 @Override
9243 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9245 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009246
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 return RIL.getTelephonyRILTimingHistograms();
9250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009253 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009254
9255 /**
9256 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009257 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9258 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009259 * Require system privileges. In the future we may add this to carrier APIs.
9260 *
Michele Berionne482f8202018-11-27 18:57:59 -08009261 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009262 */
9263 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009264 @TelephonyManager.SetCarrierRestrictionResult
9265 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009266 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009267
9268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9269 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9270
vagdeviaf9a5b92018-08-15 16:01:53 -07009271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009272
Michele Berionne482f8202018-11-27 18:57:59 -08009273 if (carrierRestrictionRules == null) {
9274 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009275 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009277 final long identity = Binder.clearCallingIdentity();
9278 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009279 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009280 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009284 }
9285
9286 /**
9287 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009288 * Get the allowed carrier list and the excluded carrier list, including the priority between
9289 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009290 * Require system privileges. In the future we may add this to carrier APIs.
9291 *
Michele Berionne482f8202018-11-27 18:57:59 -08009292 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009293 */
9294 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009295 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009296 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009297
9298 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9299 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9300
vagdeviaf9a5b92018-08-15 16:01:53 -07009301 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009302
9303 final long identity = Binder.clearCallingIdentity();
9304 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009305 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9306 if (response instanceof CarrierRestrictionRules) {
9307 return (CarrierRestrictionRules) response;
9308 }
9309 // Response is an Exception of some kind,
9310 // which is signalled to the user as a NULL retval
9311 return null;
9312 } catch (Exception e) {
9313 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9314 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009318 }
9319
fionaxu59545b42016-05-25 15:53:37 -07009320 /**
arunvoddud7401012022-12-15 16:08:12 +00009321 * Fetches the carrier restriction status of the device and sends the status to the caller
9322 * through the callback.
9323 *
9324 * @param callback The callback that will be used to send the result.
9325 * @throws SecurityException if the caller does not have the required permission/privileges or
9326 * the caller is not allowlisted.
9327 */
9328 @Override
9329 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009330 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009331 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009332 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9333 try {
9334 mApp.enforceCallingOrSelfPermission(
9335 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9336 functionName);
9337 } catch (SecurityException e) {
9338 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9339 functionName);
9340 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009341 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9342 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009343 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9344 throw new SecurityException("Not an authorized caller");
9345 }
9346 final long identity = Binder.clearCallingIdentity();
9347 try {
9348 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009349 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009350 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
arunvoddu567f2b42023-04-25 17:22:00 +00009356 @Override
9357 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9358 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9359 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9360 return allowListInfo.getShaIdList(pkgName, carrierId);
9361 }
9362
arunvoddud7401012022-12-15 16:08:12 +00009363 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009364 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009365 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009366 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009367 }
9368
9369 /**
fionaxu59545b42016-05-25 15:53:37 -07009370 * Action set from carrier signalling broadcast receivers to enable/disable radio
9371 * @param subId the subscription ID that this action applies to.
9372 * @param enabled control enable or disable radio.
9373 * {@hide}
9374 */
9375 @Override
9376 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9377 enforceModifyPermission();
9378 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009379
9380 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009381 if (phone == null) {
9382 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9383 return;
9384 }
9385 try {
9386 phone.carrierActionSetRadioEnabled(enabled);
9387 } catch (Exception e) {
9388 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009389 } finally {
9390 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009391 }
9392 }
9393
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009394 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009395 * Enable or disable Voice over NR (VoNR)
9396 * @param subId the subscription ID that this action applies to.
9397 * @param enabled enable or disable VoNR.
9398 * @return operation result.
9399 */
9400 @Override
9401 public int setVoNrEnabled(int subId, boolean enabled) {
9402 enforceModifyPermission();
9403 final Phone phone = getPhone(subId);
9404
9405 final long identity = Binder.clearCallingIdentity();
9406 if (phone == null) {
9407 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9408 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9409 }
9410
9411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9412 try {
9413 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9414 workSource);
9415 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009416
9417 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9418 if (DBG) {
9419 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9420 }
9421 SubscriptionManager.setSubscriptionProperty(
9422 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9423 (enabled ? "1" : "0"));
9424 }
9425
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009426 return result;
9427 } finally {
9428 Binder.restoreCallingIdentity(identity);
9429 }
9430 }
9431
9432 /**
9433 * Is voice over NR enabled
9434 * @return true if VoNR is enabled else false
9435 */
9436 @Override
9437 public boolean isVoNrEnabled(int subId) {
9438 enforceReadPrivilegedPermission("isVoNrEnabled");
9439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9440 final long identity = Binder.clearCallingIdentity();
9441 try {
9442 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9443 null, subId, workSource);
9444 if (DBG) log("isVoNrEnabled: " + isEnabled);
9445 return isEnabled;
9446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
9450
9451 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009452 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9453 * network status based on which carrier apps could apply actions accordingly,
9454 * enable/disable default url handler for example.
9455 *
9456 * @param subId the subscription ID that this action applies to.
9457 * @param report control start/stop reporting the default network status.
9458 * {@hide}
9459 */
9460 @Override
9461 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9462 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009463
9464 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9465 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9466 "carrierActionReportDefaultNetworkStatus");
9467
fionaxu8da9cb12017-05-23 15:02:46 -07009468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009469
9470 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009471 if (phone == null) {
9472 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9473 return;
9474 }
9475 try {
9476 phone.carrierActionReportDefaultNetworkStatus(report);
9477 } catch (Exception e) {
9478 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009479 } finally {
9480 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009481 }
9482 }
9483
9484 /**
fionaxud9622282017-07-17 17:51:30 -07009485 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9486 * @param subId the subscription ID that this action applies to.
9487 * {@hide}
9488 */
9489 @Override
9490 public void carrierActionResetAll(int subId) {
9491 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009492
9493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9494 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9495
fionaxud9622282017-07-17 17:51:30 -07009496 final Phone phone = getPhone(subId);
9497 if (phone == null) {
9498 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9499 return;
9500 }
9501 try {
9502 phone.carrierActionResetAll();
9503 } catch (Exception e) {
9504 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9505 }
9506 }
9507
9508 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009509 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9510 * bug report is being generated.
9511 */
9512 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009513 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009514 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9515 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009516 writer.println("Permission Denial: can't dump Phone from pid="
9517 + Binder.getCallingPid()
9518 + ", uid=" + Binder.getCallingUid()
9519 + "without permission "
9520 + android.Manifest.permission.DUMP);
9521 return;
9522 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009523 try {
9524 DumpsysHandler.dump(mApp, fd, writer, args);
9525 } catch (Exception e) {
9526 writer.println("Failed to dump phone information: " + e);
9527 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009528 }
Jack Yueb89b242016-06-22 13:27:47 -07009529
Brad Ebingerdac2f002018-04-03 15:17:52 -07009530 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009531 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9532 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9533 @NonNull String[] args) {
9534 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9535 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009536 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009537 }
9538
Jack Yueb89b242016-06-22 13:27:47 -07009539 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009540 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009541 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009542 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009543 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009544 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009545 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009546 */
9547 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009548 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009549 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009550 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9551 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9552 try {
9553 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009554 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009555 } catch (SecurityException se) {
9556 enforceModifyPermission();
9557 }
9558 } else {
9559 enforceModifyPermission();
9560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009561
joonhunshin4ac60942023-11-15 15:23:39 +00009562 enforceTelephonyFeatureWithException(callingPackage,
9563 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9564
Nate Myren116695d2024-02-09 09:36:01 -08009565 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009566 final long identity = Binder.clearCallingIdentity();
9567 try {
Nate Myren116695d2024-02-09 09:36:01 -08009568 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9569 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009570 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009571 callingUid, callingPackage, null, null);
9572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009573 Phone phone = getPhone(subId);
9574 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009575 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9576 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009577 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009578 phone.getDataSettingsManager().setDataEnabled(
9579 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009581 }
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009584 }
9585 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009586
9587 /**
9588 * Get Client request stats
9589 * @return List of Client Request Stats
9590 * @hide
9591 */
9592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009593 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9594 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009596 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009597 return null;
9598 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009599 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 if (phone != null) {
9604 return phone.getClientRequestStats();
9605 }
9606
9607 return null;
9608 } finally {
9609 Binder.restoreCallingIdentity(identity);
9610 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009611 }
9612
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009613 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009614 PackageManager pm;
9615 if (mFeatureFlags.hsumPackageManager()) {
9616 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9617 .getPackageManager();
9618 } else {
9619 pm = mApp.getPackageManager();
9620 }
9621
9622 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009623 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009624 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9625 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9626 // exception. ROOT_UID seems not to have a valid package name returned by
9627 // PackageManager, so just fake it here to avoid issues when running telephony shell
9628 // commands that plumb through the RIL as root, like so:
9629 // $ adb root
9630 // $ adb shell cmd phone ...
9631 packageName = "root";
9632 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009633 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009634 }
Jack Yueb4124c2017-02-16 15:32:43 -08009635
9636 /**
Grace Chen70990072017-03-24 17:21:30 -07009637 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009638 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009639 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009640 * @param state State of SIM (power down, power up, pass through)
9641 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9642 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9643 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009644 *
9645 **/
9646 @Override
Grace Chen70990072017-03-24 17:21:30 -07009647 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009648 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009649
9650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9651 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9652
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009653 Phone phone = PhoneFactory.getPhone(slotIndex);
9654
vagdeviaf9a5b92018-08-15 16:01:53 -07009655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009657 final long identity = Binder.clearCallingIdentity();
9658 try {
9659 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009660 phone.setSimPowerState(state, null, workSource);
9661 }
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 /**
9668 * Set SIM card power state.
9669 *
9670 * @param slotIndex SIM slot id.
9671 * @param state State of SIM (power down, power up, pass through)
9672 * @param callback callback to trigger after success or failure
9673 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9674 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9675 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9676 *
9677 **/
9678 @Override
9679 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9680 IIntegerConsumer callback) {
9681 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009682
9683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9684 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9685 "setSimPowerStateForSlotWithCallback");
9686
Jordan Liu109698e2020-11-24 14:50:34 -08009687 Phone phone = PhoneFactory.getPhone(slotIndex);
9688
9689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9690
9691 final long identity = Binder.clearCallingIdentity();
9692 try {
9693 if (phone != null) {
9694 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9695 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009696 }
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009699 }
9700 }
Shuo Qiandd210312017-04-12 22:11:33 +00009701
Tyler Gunn65d45c22017-06-05 11:22:26 -07009702 private boolean isUssdApiAllowed(int subId) {
9703 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009704 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009705 if (configManager == null) {
9706 return false;
9707 }
9708 PersistableBundle pb = configManager.getConfigForSubId(subId);
9709 if (pb == null) {
9710 return false;
9711 }
9712 return pb.getBoolean(
9713 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9714 }
9715
Shuo Qiandd210312017-04-12 22:11:33 +00009716 /**
Ling Mac28f0212023-03-24 16:07:15 -07009717 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009718 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009719 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009720 */
goneil9c5f4872017-12-05 14:07:56 -08009721 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009722 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009723 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009724
9725 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9726 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009728 final long identity = Binder.clearCallingIdentity();
9729 try {
Ling Mac28f0212023-03-24 16:07:15 -07009730 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009731 } finally {
9732 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009733 }
9734 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009735
9736 /**
9737 * Get the current signal strength information for the given subscription.
9738 * Because this information is not updated when the device is in a low power state
9739 * it should not be relied-upon to be current.
9740 * @param subId Subscription index
9741 * @return the most recent cached signal strength info from the modem
9742 */
9743 @Override
9744 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009745 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9746 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 Phone p = getPhone(subId);
9751 if (p == null) {
9752 return null;
9753 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009755 return p.getSignalStrength();
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009759 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009760
Pengquan Meng77b7f132018-08-22 14:49:57 -07009761 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009762 * Get the current modem radio state for the given slot.
9763 * @param slotIndex slot index.
9764 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009765 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009766 * @return the current radio power state from the modem
9767 */
9768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009769 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009770 Phone phone = PhoneFactory.getPhone(slotIndex);
9771 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9773 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009774 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9775 }
9776
joonhunshin4ac60942023-11-15 15:23:39 +00009777 enforceTelephonyFeatureWithException(callingPackage,
9778 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9779
Chen Xuf792fd62018-10-17 17:54:36 +00009780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 return phone.getRadioPowerState();
9783 } finally {
9784 Binder.restoreCallingIdentity(identity);
9785 }
9786 }
9787 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9788 }
9789
9790 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009791 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9792 *
9793 * <p>Requires one of the following permissions:
9794 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009795 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009796 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9797 * privileges.
9798 *
9799 * @param subId subscription id
9800 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9801 * {@code false}.
9802 */
9803 @Override
9804 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009805 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009806 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009807 try {
9808 mApp.enforceCallingOrSelfPermission(
9809 android.Manifest.permission.ACCESS_NETWORK_STATE,
9810 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009811 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009812 mApp.enforceCallingOrSelfPermission(
9813 permission.READ_BASIC_PHONE_STATE, functionName);
9814 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009815 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009816 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009817 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009818 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009819
joonhunshin4ac60942023-11-15 15:23:39 +00009820 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9821 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9822
Pengquan Menga1bb6272018-09-06 09:59:22 -07009823 boolean isEnabled = false;
9824 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009825 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009826 Phone phone = getPhone(subId);
9827 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009828 } finally {
9829 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009830 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009831 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009832 }
9833
9834
9835 /**
9836 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9837 *
9838 * <p> Requires permission:
9839 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9840 * privileges.
9841 *
9842 * @param subId subscription id
9843 * @param isEnabled {@code true} means enable, {@code false} means disable.
9844 */
9845 @Override
9846 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9848 mApp, subId, "setDataRoamingEnabled");
9849
joonhunshin4ac60942023-11-15 15:23:39 +00009850 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9851 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9852
Pengquan Menga1bb6272018-09-06 09:59:22 -07009853 final long identity = Binder.clearCallingIdentity();
9854 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009855 Phone phone = getPhone(subId);
9856 if (phone != null) {
9857 phone.setDataRoamingEnabled(isEnabled);
9858 }
9859 } finally {
9860 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009861 }
9862 }
9863
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009864 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009865 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009866 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009867 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009868 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009869
joonhunshin4ac60942023-11-15 15:23:39 +00009870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9871 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9872
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009873 boolean isAllowed = true;
9874 final long identity = Binder.clearCallingIdentity();
9875 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009876 Phone phone = getPhone(subId);
9877 if (phone != null) {
9878 isAllowed = phone.isCspPlmnEnabled();
9879 }
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 return isAllowed;
9884 }
9885
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009886 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9887 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009888 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009889 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009890 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009891 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9892 if (phone == null) {
9893 return false;
9894 }
9895 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9896 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9897 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009898 }
9899
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009900 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009901 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009902 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009903 mApp.getSystemService(AppOpsManager.class)
9904 .checkPackage(Binder.getCallingUid(), callingPackage);
9905
Jordan Liu1e142fc2019-04-22 15:10:43 -07009906 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009907 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009908 try {
9909 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009910 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009911 } catch (SecurityException e) {
9912 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9913 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009914 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009915 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009916 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009917 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009918 }
joonhunshin4ac60942023-11-15 15:23:39 +00009919
9920 enforceTelephonyFeatureWithException(callingPackage,
9921 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9922
sandeepjsb6c87872021-09-27 15:34:44 +00009923 // checking compatibility, if calling app's target SDK is T and beyond.
9924 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9925 Binder.getCallingUid())) {
9926 isIccIdAccessRestricted = true;
9927 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009928 final long identity = Binder.clearCallingIdentity();
9929 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009930 UiccController uiccController = UiccController.getInstance();
9931 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009932 if (hasReadPermission) {
9933 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009934 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009935
9936 // Remove private info if the caller doesn't have access
9937 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9938 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009939 //setting the value after compatibility check
9940 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009941 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9942 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009943 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009944 if (card == null) {
9945 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009946 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009947 continue;
9948 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009949 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9950 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009951 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009952 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009953 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009954 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9955 for (UiccPortInfo portInfo : portInfos) {
9956 UiccPort port = uiccController.getUiccPortForSlot(
9957 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9958 if (port == null) {
9959 // assume no access if port is null
9960 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9961 continue;
9962 }
9963 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9964 uiccPortInfos.add(portInfo);
9965 } else {
9966 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9967 }
9968 }
9969 filteredInfos.add(new UiccCardInfo(
9970 cardInfo.isEuicc(),
9971 cardInfo.getCardId(),
9972 null,
9973 cardInfo.getPhysicalSlotIndex(),
9974 cardInfo.isRemovable(),
9975 cardInfo.isMultipleEnabledProfilesSupported(),
9976 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009977 }
9978 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009979 } finally {
9980 Binder.restoreCallingIdentity(identity);
9981 }
9982 }
9983
sandeepjsb6c87872021-09-27 15:34:44 +00009984 /**
9985 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9986 * generally private and require carrier privileges to view.
9987 *
9988 * @hide
9989 */
9990 @NonNull
9991 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9992 List<UiccPortInfo> portinfo = new ArrayList<>();
9993 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9994 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9995 }
9996 return new UiccCardInfo(
9997 cardInfo.isEuicc(),
9998 cardInfo.getCardId(),
9999 null,
10000 cardInfo.getPhysicalSlotIndex(),
10001 cardInfo.isRemovable(),
10002 cardInfo.isMultipleEnabledProfilesSupported(),
10003 portinfo
10004 );
10005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010006
sandeepjsb6c87872021-09-27 15:34:44 +000010007 /**
10008 * @hide
10009 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10010 * These values are generally private and require carrier privileges to view.
10011 */
10012 @NonNull
10013 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10014 return new UiccPortInfo(
10015 UiccPortInfo.ICCID_REDACTED,
10016 portInfo.getPortIndex(),
10017 portInfo.getLogicalSlotIndex(),
10018 portInfo.isActive()
10019 );
10020 }
10021 @Override
10022 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010023 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010024 mApp.getSystemService(AppOpsManager.class)
10025 .checkPackage(Binder.getCallingUid(), callingPackage);
10026
sandeepjsb6c87872021-09-27 15:34:44 +000010027 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010028
Aman Guptaf3c90b32022-03-17 04:54:16 +000010029 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10030 // we are reading iccId which is PII data.
10031 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010032
joonhunshin4ac60942023-11-15 15:23:39 +000010033 enforceTelephonyFeatureWithException(callingPackage,
10034 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10035
sandeepjsb6c87872021-09-27 15:34:44 +000010036 // checking compatibility, if calling app's target SDK is T and beyond.
10037 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10038 Binder.getCallingUid())) {
10039 isLogicalSlotAccessRestricted = true;
10040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010041 final long identity = Binder.clearCallingIdentity();
10042 try {
10043 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010044 if (slots == null || slots.length == 0) {
10045 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010046 return null;
10047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010048 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10049 for (int i = 0; i < slots.length; i++) {
10050 UiccSlot slot = slots[i];
10051 if (slot == null) {
10052 continue;
10053 }
10054
Jordan Liu7be7e652019-05-06 18:55:02 +000010055 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010056 UiccCard card = slot.getUiccCard();
10057 if (card != null) {
10058 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010059 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010060 cardId = slot.getEid();
10061 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010062 // If cardId is null, use iccId of default port as cardId.
10063 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010065 }
10066
Jordan Liu857451f2019-05-09 16:35:35 -070010067 if (cardId != null) {
10068 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10069 // if cardId is an EID, it's all digits so this is fine
10070 cardId = IccUtils.stripTrailingFs(cardId);
10071 }
10072
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010073 int cardState = 0;
10074 switch (slot.getCardState()) {
10075 case CARDSTATE_ABSENT:
10076 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10077 break;
10078 case CARDSTATE_PRESENT:
10079 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10080 break;
10081 case CARDSTATE_ERROR:
10082 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10083 break;
10084 case CARDSTATE_RESTRICTED:
10085 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10086 break;
10087 default:
10088 break;
10089
10090 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010091 List<UiccPortInfo> portInfos = new ArrayList<>();
10092 int[] portIndexes = slot.getPortList();
10093 for (int portIdx : portIndexes) {
10094 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010095 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010096 portInfos.add(new UiccPortInfo(iccId, portIdx,
10097 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010099 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010100 slot.isEuicc(),
10101 cardId,
10102 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010103 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010104 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010105 //setting the value after compatibility check
10106 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010107 }
10108 return infos;
10109 } finally {
10110 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010111 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010112 }
10113
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010114 /* Returns null if doesn't have read permission or carrier privilege access. */
10115 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10116 boolean hasReadPermission) {
10117 String iccId = slot.getIccId(portIndex);
10118 if (hasReadPermission) { // if has read permission
10119 return iccId;
10120 } else {
10121 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10122 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10123 // if no read permission, checking carrier privilege access
10124 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10125 return iccId;
10126 }
10127 }
10128 }
10129 // No read permission or carrier privilege access.
10130 return UiccPortInfo.ICCID_REDACTED;
10131 }
10132
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010133 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010134 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010135 public boolean switchSlots(int[] physicalSlots) {
10136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010137
joonhunshin4ac60942023-11-15 15:23:39 +000010138 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10139 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10140
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010141 final long identity = Binder.clearCallingIdentity();
10142 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010143 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10144 for (int i = 0; i < physicalSlots.length; i++) {
10145 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10146 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10147 physicalSlots[i], i));
10148 }
10149 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010150 } finally {
10151 Binder.restoreCallingIdentity(identity);
10152 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010153 }
Jack Yu4c988042018-02-27 15:30:01 -080010154
10155 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010156 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10157 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10158 enforceModifyPermission();
10159
joonhunshin4ac60942023-11-15 15:23:39 +000010160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10161 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10162
sandeepjsb6c87872021-09-27 15:34:44 +000010163 final long identity = Binder.clearCallingIdentity();
10164 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010165 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010172 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010173 enforceTelephonyFeatureWithException(callingPackage,
10174 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10175
Jordan Liu7de49fa2018-12-06 14:48:49 -080010176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 return UiccController.getInstance().getCardIdForDefaultEuicc();
10179 } finally {
10180 Binder.restoreCallingIdentity(identity);
10181 }
10182 }
10183
Pengquan Meng85728fb2018-03-12 16:31:21 -070010184 /**
goneil47ffb6e2018-04-06 15:40:58 -070010185 * A test API to reload the UICC profile.
10186 *
10187 * <p>Requires that the calling app has permission
10188 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10189 * @hide
10190 */
10191 @Override
10192 public void refreshUiccProfile(int subId) {
10193 enforceModifyPermission();
10194
10195 final long identity = Binder.clearCallingIdentity();
10196 try {
10197 Phone phone = getPhone(subId);
10198 if (phone == null) {
10199 return;
10200 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010201 UiccPort uiccPort = phone.getUiccPort();
10202 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010203 return;
10204 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010205 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010206 if (uiccProfile == null) {
10207 return;
10208 }
10209 uiccProfile.refresh();
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
10214
10215 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010216 * Returns false if the mobile data is disabled by default, otherwise return true.
10217 */
10218 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010219 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010220 }
10221
10222 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010223 * Returns the default network type for the given {@code subId}, if the default network type is
10224 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10225 */
10226 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010227 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010228 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010229 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10230 return list.get(phoneId);
10231 }
10232 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010233 }
fionaxua13278b2018-03-21 00:08:13 -070010234
10235 @Override
10236 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010237 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010239
10240 final long identity = Binder.clearCallingIdentity();
10241 try {
10242 final Phone phone = getPhone(subId);
10243 if (phone == null) {
10244 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10245 return;
10246 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010247 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10248 if (cpt != null) {
10249 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10250 }
10251 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010252 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10253 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010254 if (carrierPrivilegeRules == null) {
10255 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10256 } else {
10257 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010259 } finally {
10260 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010261 }
fionaxua13278b2018-03-21 00:08:13 -070010262 }
10263
10264 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010265 public void setCarrierServicePackageOverride(
10266 int subId, String carrierServicePackage, String callingPackage) {
10267 TelephonyPermissions.enforceShellOnly(
10268 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10269
Benedict Wong66477622023-02-03 23:30:57 +000010270 final long identity = Binder.clearCallingIdentity();
10271 try {
10272 final Phone phone = getPhone(subId);
10273 if (phone == null || phone.getSubId() != subId) {
10274 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10275 throw new IllegalArgumentException("No phone for subid");
10276 }
10277 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10278 if (cpt == null) {
10279 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10280 throw new IllegalStateException("No CPT for phone");
10281 }
10282 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
10287
10288 @Override
fionaxua13278b2018-03-21 00:08:13 -070010289 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010290 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010291
10292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 final Phone phone = getPhone(subId);
10295 if (phone == null) {
10296 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10297 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10298 }
10299 return phone.getCarrierIdListVersion();
10300 } finally {
10301 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010302 }
fionaxua13278b2018-03-21 00:08:13 -070010303 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010304
10305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010306 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10307 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010309 mApp, subId, callingPackage, callingFeatureId,
10310 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010311 return -1;
10312 }
10313
10314 final long identity = Binder.clearCallingIdentity();
10315 try {
10316 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
10319 }
10320 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010321
10322 @Override
10323 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010324 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010325 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010326 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010327
joonhunshin4ac60942023-11-15 15:23:39 +000010328 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10329 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10330
Pengquan Menga1bb6272018-09-06 09:59:22 -070010331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
10338
10339 @Override
10340 public boolean setCdmaRoamingMode(int subId, int mode) {
10341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10342 mApp, subId, "setCdmaRoamingMode");
10343
joonhunshin4ac60942023-11-15 15:23:39 +000010344 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10345 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10346
Pengquan Menga1bb6272018-09-06 09:59:22 -070010347 final long identity = Binder.clearCallingIdentity();
10348 try {
10349 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10350 } finally {
10351 Binder.restoreCallingIdentity(identity);
10352 }
10353 }
10354
10355 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010356 public int getCdmaSubscriptionMode(int subId) {
10357 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010358 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010359 mApp, subId, "getCdmaSubscriptionMode");
10360
joonhunshin4ac60942023-11-15 15:23:39 +000010361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10362 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10363
Sarah Chinbaab1432020-10-28 13:46:24 -070010364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
10371
10372 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010373 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10375 mApp, subId, "setCdmaSubscriptionMode");
10376
joonhunshin4ac60942023-11-15 15:23:39 +000010377 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10378 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10379
Pengquan Menga1bb6272018-09-06 09:59:22 -070010380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010387
sqianc5eccab2018-10-19 18:46:41 -070010388 @Override
sqian8c685422019-02-22 15:55:18 -080010389 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010390 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010392 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10393 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010394 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10395 }
joonhunshin4ac60942023-11-15 15:23:39 +000010396
10397 enforceTelephonyFeatureWithException(callingPackage,
10398 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10399
sqian11b7a0e2018-12-05 18:48:28 -080010400 final long identity = Binder.clearCallingIdentity();
10401 try {
sqian854d44b2018-12-12 16:48:18 -080010402 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10403 for (Phone phone: PhoneFactory.getPhones()) {
10404 if (phone.getEmergencyNumberTracker() != null
10405 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10406 emergencyNumberListInternal.put(
10407 phone.getSubId(),
10408 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10409 }
sqian11b7a0e2018-12-05 18:48:28 -080010410 }
sqian854d44b2018-12-12 16:48:18 -080010411 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
sqianc5eccab2018-10-19 18:46:41 -070010415 }
10416
10417 @Override
sqian8c685422019-02-22 15:55:18 -080010418 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010419 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010420 if (!exactMatch) {
10421 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010422 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010423 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010424 }
joonhunshin4ac60942023-11-15 15:23:39 +000010425
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010426 if (!mApp.getResources().getBoolean(
10427 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10429 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10430 }
joonhunshin4ac60942023-11-15 15:23:39 +000010431
sqian11b7a0e2018-12-05 18:48:28 -080010432 final long identity = Binder.clearCallingIdentity();
10433 try {
sqian854d44b2018-12-12 16:48:18 -080010434 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010435 //Note: we ignore passed in param exactMatch. We can remove it once
10436 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010437 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010438 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010439 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010440 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010441 }
sqian11b7a0e2018-12-05 18:48:28 -080010442 }
10443 return false;
10444 } finally {
10445 Binder.restoreCallingIdentity(identity);
10446 }
10447 }
10448
sqianf4ca7ed2019-01-15 18:32:07 -080010449 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010450 * Start emergency callback mode for GsmCdmaPhone for testing.
10451 */
10452 @Override
10453 public void startEmergencyCallbackMode() {
10454 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10455 "startEmergencyCallbackMode");
10456 enforceModifyPermission();
10457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 for (Phone phone : PhoneFactory.getPhones()) {
10460 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10461 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10462 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10463 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10464 gsmCdmaPhone.obtainMessage(
10465 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10466 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10467 }
10468 }
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
10474 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010475 * Update emergency number list for test mode.
10476 */
10477 @Override
10478 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10479 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10480 "updateEmergencyNumberListTestMode");
10481
10482 final long identity = Binder.clearCallingIdentity();
10483 try {
10484 for (Phone phone: PhoneFactory.getPhones()) {
10485 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10486 if (tracker != null) {
10487 tracker.executeEmergencyNumberTestModeCommand(action, num);
10488 }
10489 }
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 /**
10496 * Get the full emergency number list for test mode.
10497 */
10498 @Override
10499 public List<String> getEmergencyNumberListTestMode() {
10500 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10501 "getEmergencyNumberListTestMode");
10502
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
10505 Set<String> emergencyNumbers = new HashSet<>();
10506 for (Phone phone: PhoneFactory.getPhones()) {
10507 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10508 if (tracker != null) {
10509 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10510 emergencyNumbers.add(num.getNumber());
10511 }
10512 }
10513 }
10514 return new ArrayList<>(emergencyNumbers);
10515 } finally {
10516 Binder.restoreCallingIdentity(identity);
10517 }
10518 }
10519
chen xud6b45bd2018-10-30 22:27:10 -070010520 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010521 public int getEmergencyNumberDbVersion(int subId) {
10522 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10523
joonhunshin4ac60942023-11-15 15:23:39 +000010524 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10525 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10526
Shuo Qian3b6ee772019-11-13 17:43:31 -080010527 final long identity = Binder.clearCallingIdentity();
10528 try {
10529 final Phone phone = getPhone(subId);
10530 if (phone == null) {
10531 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10532 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10533 }
10534 return phone.getEmergencyNumberDbVersion();
10535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
10539
10540 @Override
10541 public void notifyOtaEmergencyNumberDbInstalled() {
10542 enforceModifyPermission();
10543
joonhunshin4ac60942023-11-15 15:23:39 +000010544 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10545 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10546
Shuo Qian3b6ee772019-11-13 17:43:31 -080010547 final long identity = Binder.clearCallingIdentity();
10548 try {
10549 for (Phone phone: PhoneFactory.getPhones()) {
10550 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10551 if (tracker != null) {
10552 tracker.updateOtaEmergencyNumberDatabase();
10553 }
10554 }
10555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
10560 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010561 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010562 enforceActiveEmergencySessionPermission();
10563
joonhunshin4ac60942023-11-15 15:23:39 +000010564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10565 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10566
Shuo Qian3b6ee772019-11-13 17:43:31 -080010567 final long identity = Binder.clearCallingIdentity();
10568 try {
10569 for (Phone phone: PhoneFactory.getPhones()) {
10570 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10571 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010572 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10573 }
10574 }
10575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
10579
10580 @Override
10581 public void resetOtaEmergencyNumberDbFilePath() {
10582 enforceActiveEmergencySessionPermission();
10583
joonhunshin4ac60942023-11-15 15:23:39 +000010584 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10585 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10586
Shuo Qianc373f112020-03-05 17:55:34 -080010587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 for (Phone phone: PhoneFactory.getPhones()) {
10590 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10591 if (tracker != null) {
10592 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010593 }
10594 }
10595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010601 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10602 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10603 Phone phone = getPhone(subId);
10604 if (phone == null) {
10605 return null;
10606 }
10607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 UiccProfile profile = UiccController.getInstance()
10610 .getUiccProfileForPhone(phone.getPhoneId());
10611 if (profile != null) {
10612 return profile.getCertsFromCarrierPrivilegeAccessRules();
10613 }
10614 } finally {
10615 Binder.restoreCallingIdentity(identity);
10616 }
10617 return null;
10618 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010619
10620 /**
10621 * Enable or disable a modem stack.
10622 */
10623 @Override
10624 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10625 enforceModifyPermission();
10626
joonhunshin4ac60942023-11-15 15:23:39 +000010627 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10628 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10629
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010630 final long identity = Binder.clearCallingIdentity();
10631 try {
10632 Phone phone = PhoneFactory.getPhone(slotIndex);
10633 if (phone == null) {
10634 return false;
10635 } else {
10636 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10637 }
10638 } finally {
10639 Binder.restoreCallingIdentity(identity);
10640 }
10641 }
Michelecea4cf22018-12-21 15:00:11 -080010642
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010643 /**
10644 * Whether a modem stack is enabled or not.
10645 */
10646 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010647 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10648 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010649 Phone phone = PhoneFactory.getPhone(slotIndex);
10650 if (phone == null) return false;
10651
10652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010653 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10654 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010655 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10656 }
10657
joonhunshin4ac60942023-11-15 15:23:39 +000010658 enforceTelephonyFeatureWithException(callingPackage,
10659 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10660
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010661 final long identity = Binder.clearCallingIdentity();
10662 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010663 try {
10664 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10665 } catch (NoSuchElementException ex) {
10666 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10667 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010668 } finally {
10669 Binder.restoreCallingIdentity(identity);
10670 }
10671 }
10672
Michelecea4cf22018-12-21 15:00:11 -080010673 @Override
Michele0ea7d782019-03-19 14:58:42 -070010674 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010675 enforceModifyPermission();
10676
joonhunshin4ac60942023-11-15 15:23:39 +000010677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10678 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10679
Michelecea4cf22018-12-21 15:00:11 -080010680 final long identity = Binder.clearCallingIdentity();
10681 try {
10682 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010683 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010684 .commit();
10685 } finally {
10686 Binder.restoreCallingIdentity(identity);
10687 }
10688 }
10689
10690 @Override
Michele0ea7d782019-03-19 14:58:42 -070010691 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010692 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010694 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10695 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010696 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010697 }
Michelecea4cf22018-12-21 15:00:11 -080010698
joonhunshin4ac60942023-11-15 15:23:39 +000010699 enforceTelephonyFeatureWithException(callingPackage,
10700 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10701
Michelecea4cf22018-12-21 15:00:11 -080010702 final long identity = Binder.clearCallingIdentity();
10703 try {
Michele0ea7d782019-03-19 14:58:42 -070010704 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010709
Michele0ea7d782019-03-19 14:58:42 -070010710 @TelephonyManager.IsMultiSimSupportedResult
10711 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010712 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10713 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10714 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010715 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10716 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010717 }
10718 // Check if the hardware supports multisim functionality. If usage of multisim is not
10719 // supported by the modem, indicate that it is restricted.
10720 PhoneCapability staticCapability =
10721 mPhoneConfigurationManager.getStaticPhoneCapability();
10722 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010723 loge("isMultiSimSupportedInternal: no static configuration available");
10724 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010725 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010726 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010727 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10728 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010729 }
10730 // Check if support of multiple SIMs is restricted by carrier
10731 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010732 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010733 }
10734
Michele0ea7d782019-03-19 14:58:42 -070010735 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010736 }
10737
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010738 /**
10739 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010740 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10741 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10742 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010743 * @param numOfSims number of active sims we want to switch to
10744 */
10745 @Override
10746 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010747 if (numOfSims == 1) {
10748 enforceModifyPermission();
10749 } else {
10750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10751 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10752 }
joonhunshin4ac60942023-11-15 15:23:39 +000010753
10754 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10755 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10756
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010757 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010758
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010759 try {
Michele30b57b22019-03-01 12:01:14 -080010760 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010761 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010762 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10763 return;
10764 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010765 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10766 } finally {
10767 Binder.restoreCallingIdentity(identity);
10768 }
10769 }
10770
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010771 @Override
10772 public boolean isApplicationOnUicc(int subId, int appType) {
10773 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010774
10775 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10776 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10777
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010778 Phone phone = getPhone(subId);
10779 if (phone == null) {
10780 return false;
10781 }
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010784 UiccPort uiccPort = phone.getUiccPort();
10785 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010786 return false;
10787 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010788 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010789 if (uiccProfile == null) {
10790 return false;
10791 }
10792 if (TelephonyManager.APPTYPE_SIM <= appType
10793 && appType <= TelephonyManager.APPTYPE_ISIM) {
10794 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10795 }
10796 return false;
10797 } finally {
10798 Binder.restoreCallingIdentity(identity);
10799 }
10800 }
10801
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010802 /**
chen xub4baa772019-04-03 10:23:41 -070010803 * Get whether making changes to modem configurations will trigger reboot.
10804 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010805 */
10806 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010807 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10808 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010810 mApp, subId, callingPackage, callingFeatureId,
10811 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010812 return false;
10813 }
joonhunshin4ac60942023-11-15 15:23:39 +000010814
10815 enforceTelephonyFeatureWithException(callingPackage,
10816 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10817 "doesSwitchMultiSimConfigTriggerReboot");
10818
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
Nathan Harold29f5f052019-02-15 13:41:57 -080010827 private void updateModemStateMetrics() {
10828 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10829 // TODO: check the state for each modem if the api is ready.
10830 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10831 }
10832
Pengquan Meng3889a572019-01-23 11:16:29 -080010833 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010834 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010835 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010836 // Verify that the callingPackage belongs to the calling UID
10837 mApp.getSystemService(AppOpsManager.class)
10838 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010839
10840 enforceTelephonyFeatureWithException(callingPackage,
10841 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10842
Pengquan Meng3889a572019-01-23 11:16:29 -080010843 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010844 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010845 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010846 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10847 if (slotInfos != null) {
10848 for (int i = 0; i < slotInfos.length; i++) {
10849 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10850 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10851 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10852 portInfo.getLogicalSlotIndex()));
10853 }
10854 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010855 }
10856 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010857 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010858 } finally {
10859 Binder.restoreCallingIdentity(identity);
10860 }
10861 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010862
10863 /**
10864 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010865 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010866 */
jimsunf9ec1622022-09-13 21:18:43 +080010867 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010868 @Override
10869 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010870 return getHalVersion(HAL_SERVICE_RADIO);
10871 }
10872
10873 /**
10874 * Get the HAL Version of a specific service
10875 */
10876 @Override
10877 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010878 Phone phone = getDefaultPhone();
10879 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010880 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010881 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10882 return hv.major * 100 + hv.minor;
10883 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010884
10885 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010886 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010887 *
10888 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010889 */
10890 @Override
sangyun097dcf72024-01-04 10:35:49 +090010891 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010892 if (mFeatureFlags.hsumPackageManager()) {
10893 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10894 Binder.getCallingUserHandle(), 0).getPackageManager();
10895 if (pm == null) return null;
10896 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10897 return (callingUids == null) ? null : callingUids[0];
10898 }
10899 if (mPackageManager == null) return null;
10900 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10901 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010902 }
10903
10904 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010905 * @return The calling package name or "phone" if the caller is the phone process. This is done
10906 * because multiple Phone has multiple packages in it and the first element in the array is not
10907 * actually always the caller.
10908 * Note: This is for logging purposes only and should not be used for security checks.
10909 */
10910 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010911 PackageManager pm;
10912 if (mFeatureFlags.hsumPackageManager()) {
10913 pm = mApp.getBaseContext().createContextAsUser(
10914 Binder.getCallingUserHandle(), 0).getPackageManager();
10915 } else {
10916 pm = mApp.getPackageManager();
10917 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010918 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10919 if (uidName != null && !uidName.isEmpty()) return uidName;
10920 return getCurrentPackageName();
10921 }
10922
10923 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010924 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10925 * corresponding network requests on a subId.
10926 *
10927 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010928 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010929 * 2) APN is un-metered for this subscription, or
10930 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010931 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010932 *
10933 * @return whether data is allowed for a apn type.
10934 *
10935 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010936 */
10937 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010938 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010939 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10940 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010941
joonhunshin4ac60942023-11-15 15:23:39 +000010942 enforceTelephonyFeatureWithException(callingPackage,
10943 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10944
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010945 // Now that all security checks passes, perform the operation as ourselves.
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 Phone phone = getPhone(subId);
10949 if (phone == null) return false;
10950
Jack Yu27422a52022-03-21 10:38:05 -070010951 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010952 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010953 isMetered = phone.getDataNetworkController().getDataConfigManager()
10954 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10955 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010956 isDataEnabled = (phone.getDataSettingsManager() != null)
10957 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010958 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010959 } finally {
10960 Binder.restoreCallingIdentity(identity);
10961 }
10962 }
10963
10964 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010965 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010966 enforceReadPrivilegedPermission("isApnMetered");
10967
joonhunshin4ac60942023-11-15 15:23:39 +000010968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10969 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10970
Malcolm Chene5ad5792019-04-18 13:51:02 -070010971 // Now that all security checks passes, perform the operation as ourselves.
10972 final long identity = Binder.clearCallingIdentity();
10973 try {
10974 Phone phone = getPhone(subId);
10975 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010976 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10977 DataUtils.apnTypeToNetworkCapability(apnType),
10978 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010983
10984 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010985 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10986 int subscriptionId, IBooleanConsumer resultCallback) {
10987 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010988
10989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10990 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10991
Hall Liu73f5d362020-01-20 13:42:00 -080010992 long token = Binder.clearCallingIdentity();
10993 try {
10994 Phone phone = getPhone(subscriptionId);
10995 if (phone == null) {
10996 try {
10997 if (resultCallback != null) {
10998 resultCallback.accept(false);
10999 }
11000 } catch (RemoteException e) {
11001 // ignore
11002 }
11003 return;
11004 }
11005 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11006 Pair.create(specifiers, (x) -> {
11007 try {
11008 if (resultCallback != null) {
11009 resultCallback.accept(x);
11010 }
11011 } catch (RemoteException e) {
11012 // ignore
11013 }
11014 });
11015 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11016 } finally {
11017 Binder.restoreCallingIdentity(token);
11018 }
11019 }
11020
11021 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011022 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11023 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011024 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011025 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011026
11027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11028 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11029
Sarah Chin679c08a2020-11-18 13:39:35 -080011030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11031 final long identity = Binder.clearCallingIdentity();
11032 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011033 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11034 if (result instanceof IllegalStateException) {
11035 throw (IllegalStateException) result;
11036 }
11037 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011038 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11039 return specifiers;
11040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
11044
11045 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011046 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011047 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011048
11049 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11050 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11051
Jack Yu8b766fc2022-03-21 09:42:33 -070011052 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011053 }
11054
11055 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011056 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11057 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011058 if (callingPackage == null) {
11059 callingPackage = getCurrentPackageName();
11060 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011061 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11062 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011063 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11064 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011065 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11066 }
11067 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11068 Intent intent = new Intent();
11069 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11070 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11071 // Bring up choose default SMS subscription dialog right now
11072 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11073 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011074 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011075 }
chen xud5ca2d52019-05-28 15:20:57 -070011076
11077 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011078 public void showSwitchToManagedProfileDialog() {
11079 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011080 try {
11081 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11082 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11083 // for work telephony.
11084 Intent intent = new Intent(Intent.ACTION_SENDTO);
11085 intent.setData(Uri.parse("smsto:"));
11086 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011087 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011088 } catch (ActivityNotFoundException e) {
11089 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11090 Intent intent = new Intent();
11091 intent.setClass(mApp, ErrorDialogActivity.class);
11092 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011093 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011094 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011095 }
11096
11097 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011098 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11100 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11101
chen xud5ca2d52019-05-28 15:20:57 -070011102 //TODO investigate if this API should require proper permission check in R b/133791609
11103 final long identity = Binder.clearCallingIdentity();
11104 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011105 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11106 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11107 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11108 return carrierUAProfUrl;
11109 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011110 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11111 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011112 } finally {
11113 Binder.restoreCallingIdentity(identity);
11114 }
11115 }
11116
11117 @Override
11118 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11120 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11121
chen xud5ca2d52019-05-28 15:20:57 -070011122 //TODO investigate if this API should require proper permission check in R b/133791609
11123 final long identity = Binder.clearCallingIdentity();
11124 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011125 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11126 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11127 if (!TextUtils.isEmpty(carrierUserAgent)) {
11128 return carrierUserAgent;
11129 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011130 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11131 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011132 } finally {
11133 Binder.restoreCallingIdentity(identity);
11134 }
11135 }
Jack Yub07d4972019-05-28 16:12:25 -070011136
11137 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011138 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11139 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011140
joonhunshin4ac60942023-11-15 15:23:39 +000011141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11142 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11143
Jack Yub07d4972019-05-28 16:12:25 -070011144 final long identity = Binder.clearCallingIdentity();
11145 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011146 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011147 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011148
Ling Maf188d502022-09-16 15:22:36 -070011149 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011150 } finally {
11151 Binder.restoreCallingIdentity(identity);
11152 }
11153 }
11154
11155 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011156 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011157 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011158 enforceModifyPermission();
11159
joonhunshin4ac60942023-11-15 15:23:39 +000011160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11161 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11162
changbettyd5c246e2019-12-24 15:40:37 +080011163 final long identity = Binder.clearCallingIdentity();
11164 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011165 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011166 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011167
Ling Maf188d502022-09-16 15:22:36 -070011168 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011169 } finally {
11170 Binder.restoreCallingIdentity(identity);
11171 }
11172 }
11173
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011174 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011175 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011176 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11177 * otherwise.
11178 */
11179 @Override
11180 public void setCepEnabled(boolean isCepEnabled) {
11181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11182
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11186 for (Phone phone : PhoneFactory.getPhones()) {
11187 Phone defaultPhone = phone.getImsPhone();
11188 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11189 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11190 ImsPhoneCallTracker imsPhoneCallTracker =
11191 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11192 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11193 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11194 + imsPhone.getMsisdn());
11195 }
11196 }
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
allenwtsu46dcc572020-01-08 18:24:03 +080011201
11202 /**
11203 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11204 *
11205 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11206 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11207 * before being read.
11208 */
11209 @Override
11210 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11211 isCompressed) {
11212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11213 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011214 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11215 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11216 }
joonhunshin4ac60942023-11-15 15:23:39 +000011217
11218 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11219 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11220 Binder.getCallingUserHandle())) {
11221 if (!isImsAvailableOnDevice()) {
11222 // ProvisioningManager can not handle ServiceSpecificException.
11223 // Throw the IllegalStateException and annotate ProvisioningManager.
11224 throw new IllegalStateException("IMS not available on device.");
11225 }
11226 } else {
11227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11228 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11229 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011230 }
11231
11232 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011233 try {
Hui Wang761a6682020-10-31 05:12:53 +000011234 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11235 } finally {
11236 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011237 }
11238 }
zoey chene02881a2019-12-30 16:11:23 +080011239
11240 @Override
11241 public boolean isIccLockEnabled(int subId) {
11242 enforceReadPrivilegedPermission("isIccLockEnabled");
11243
joonhunshin4ac60942023-11-15 15:23:39 +000011244 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11245 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11246
zoey chene02881a2019-12-30 16:11:23 +080011247 // Now that all security checks passes, perform the operation as ourselves.
11248 final long identity = Binder.clearCallingIdentity();
11249 try {
11250 Phone phone = getPhone(subId);
11251 if (phone != null && phone.getIccCard() != null) {
11252 return phone.getIccCard().getIccLockEnabled();
11253 } else {
11254 return false;
11255 }
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 }
11260
11261 /**
11262 * Set the ICC pin lock enabled or disabled.
11263 *
11264 * @return an integer representing the status of IccLock enabled or disabled in the following
11265 * three cases:
11266 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11267 * successfully.
11268 * - Positive number and zero for remaining password attempts.
11269 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11270 *
11271 */
11272 @Override
11273 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11274 enforceModifyPermission();
11275
joonhunshin4ac60942023-11-15 15:23:39 +000011276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11277 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11278
zoey chene02881a2019-12-30 16:11:23 +080011279 Phone phone = getPhone(subId);
11280 if (phone == null) {
11281 return 0;
11282 }
11283 // Now that all security checks passes, perform the operation as ourselves.
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11287 new Pair<Boolean, String>(enabled, password), phone, null);
11288 return attemptsRemaining;
11289
11290 } catch (Exception e) {
11291 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11292 } finally {
11293 Binder.restoreCallingIdentity(identity);
11294 }
11295 return 0;
11296 }
11297
11298 /**
11299 * Change the ICC password used in ICC pin lock.
11300 *
11301 * @return an integer representing the status of IccLock changed in the following three cases:
11302 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11303 * - Positive number and zero for remaining password attempts.
11304 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11305 *
11306 */
11307 @Override
11308 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11309 enforceModifyPermission();
11310
joonhunshin4ac60942023-11-15 15:23:39 +000011311 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11312 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11313
zoey chene02881a2019-12-30 16:11:23 +080011314 Phone phone = getPhone(subId);
11315 if (phone == null) {
11316 return 0;
11317 }
11318 // Now that all security checks passes, perform the operation as ourselves.
11319 final long identity = Binder.clearCallingIdentity();
11320 try {
11321 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11322 new Pair<String, String>(oldPassword, newPassword), phone, null);
11323 return attemptsRemaining;
11324
11325 } catch (Exception e) {
11326 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11327 } finally {
11328 Binder.restoreCallingIdentity(identity);
11329 }
11330 return 0;
11331 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011332
11333 /**
11334 * Request for receiving user activity notification
11335 */
11336 @Override
11337 public void requestUserActivityNotification() {
11338 if (!mNotifyUserActivity.get()
11339 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11340 mNotifyUserActivity.set(true);
11341 }
11342 }
11343
11344 /**
11345 * Called when userActivity is signalled in the power manager.
11346 * This is safe to call from any thread, with any window manager locks held or not.
11347 */
11348 @Override
11349 public void userActivity() {
11350 // ***************************************
11351 // * Inherited from PhoneWindowManager *
11352 // ***************************************
11353 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11354 // WITH ITS LOCKS HELD.
11355 //
11356 // This code must be VERY careful about the locks
11357 // it acquires.
11358 // In fact, the current code acquires way too many,
11359 // and probably has lurking deadlocks.
11360
Jack Yu86374492024-09-16 13:05:44 -070011361 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011362 throw new SecurityException("Only the OS may call notifyUserActivity()");
11363 }
11364
11365 if (mNotifyUserActivity.getAndSet(false)) {
11366 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11367 USER_ACTIVITY_NOTIFICATION_DELAY);
11368 }
11369 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011370
11371 @Override
11372 public boolean canConnectTo5GInDsdsMode() {
11373 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11374 }
Jack Yud10cdd42020-09-28 20:28:01 -070011375
11376 @Override
11377 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11378 String callingFeatureId) {
11379 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11380 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11381 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11382 }
11383
joonhunshin4ac60942023-11-15 15:23:39 +000011384 enforceTelephonyFeatureWithException(callingPackage,
11385 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11386
Jack Yud10cdd42020-09-28 20:28:01 -070011387 Phone phone = getPhone(subId);
11388 if (phone == null) {
11389 throw new RuntimeException("phone is not available");
11390 }
11391 // Now that all security checks passes, perform the operation as ourselves.
11392 final long identity = Binder.clearCallingIdentity();
11393 try {
11394 return phone.getEquivalentHomePlmns();
11395 } finally {
11396 Binder.restoreCallingIdentity(identity);
11397 }
11398 }
Daniel Bright59e67312020-11-13 11:49:37 -080011399
11400 @Override
11401 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011402 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011403 if (!mApp.getResources().getBoolean(
11404 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11406 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11407 "isRadioInterfaceCapabilitySupported");
11408 }
joonhunshin4ac60942023-11-15 15:23:39 +000011409
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011410 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011411 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011412 if (radioInterfaceCapabilities == null) {
11413 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011414 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011415 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011416 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011417
Hui Wang641e81c2020-10-12 12:14:23 -070011418 @Override
11419 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11420 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011421 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11422 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11423 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11424 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11425 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011426
11427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11428 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11429
Hui Wang641e81c2020-10-12 12:14:23 -070011430 if (DBG) {
11431 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11432 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11433 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11434 }
11435
11436 if (!SubscriptionManager.isValidSubscriptionId(subId)
11437 || appType < TelephonyManager.APPTYPE_UNKNOWN
11438 || appType > TelephonyManager.APPTYPE_ISIM
11439 || nafUrl == null || securityProtocol == null || callback == null) {
11440 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11441 if (callback != null) {
11442 try {
11443 callback.onAuthenticationFailure(
11444 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11445 } catch (RemoteException exception) {
11446 log("Fail to notify onAuthenticationFailure due to " + exception);
11447 }
11448 return;
11449 }
11450 }
11451
11452 final long token = Binder.clearCallingIdentity();
11453 try {
11454 getGbaManager(subId).bootstrapAuthenticationRequest(
11455 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011456 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011457 } finally {
11458 Binder.restoreCallingIdentity(token);
11459 }
11460 }
11461
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011462 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011463 * Attempts to set the radio power state for all phones for thermal reason.
11464 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011465 * requested radio power state will actually be set. See {@link
11466 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11467 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011468 * @param enable {@code true} if trying to turn radio on.
11469 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11470 * false}.
11471 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011472 private boolean setRadioPowerForThermal(boolean enable) {
11473 boolean isPhoneAvailable = false;
11474 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11475 Phone phone = PhoneFactory.getPhone(i);
11476 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011477 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011478 isPhoneAvailable = true;
11479 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011480 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011481
11482 // return true if successfully informed the phone object about the thermal radio power
11483 // request.
11484 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011485 }
11486
11487 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011488 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011489 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11490 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11491 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11492 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11493 throw new IllegalArgumentException("modem does not support data throttling");
11494 }
11495
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011496 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11497 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011498 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011499 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11500 }
11501
Sarah Chinecc78c42022-03-31 21:16:48 -070011502 setDataEnabledForReason(
11503 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011504
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011505 if (isDataThrottlingSupported) {
11506 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011507 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011508 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11509 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11510 } else if (thermalMitigationResult
11511 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011512 log("Modem likely does not support data throttling on secondary carrier. Data " +
11513 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11514 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011515 }
11516 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011517 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011518
11519 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011520 }
11521
Jack Nudelman644b91a2021-03-12 14:09:48 -080011522 private static List<String> getThermalMitigationAllowlist(Context context) {
11523 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11524 for (String pckg : context.getResources()
11525 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11526 sThermalMitigationAllowlistedPackages.add(pckg);
11527 }
11528 }
11529
11530 return sThermalMitigationAllowlistedPackages;
11531 }
11532
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011533 private boolean isAnyPhoneInEmergencyState() {
11534 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11535 if (tm.isInEmergencyCall()) {
11536 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11537 return true;
11538 }
11539 for (Phone phone : PhoneFactory.getPhones()) {
11540 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11541 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011542 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11543 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011544 return true;
11545 }
11546 }
11547
11548 return false;
11549 }
11550
Jack Nudelman644b91a2021-03-12 14:09:48 -080011551 /**
11552 * Used by shell commands to add an authorized package name for thermal mitigation.
11553 * @param packageName name of package to be allowlisted
11554 * @param context
11555 */
11556 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11557 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11558 sThermalMitigationAllowlistedPackages.add(packageName);
11559 }
11560
11561 /**
11562 * Used by shell commands to remove an authorized package name for thermal mitigation.
11563 * @param packageName name of package to remove from allowlist
11564 * @param context
11565 */
11566 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11567 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11568 sThermalMitigationAllowlistedPackages.remove(packageName);
11569 }
11570
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011571 /**
11572 * Thermal mitigation request to control functionalities at modem.
11573 *
11574 * @param subId the id of the subscription.
11575 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011576 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011577 *
11578 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11579 */
11580 @Override
11581 @ThermalMitigationResult
11582 public int sendThermalMitigationRequest(
11583 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011584 ThermalMitigationRequest thermalMitigationRequest,
11585 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011586 enforceModifyPermission();
11587
Jack Nudelman644b91a2021-03-12 14:09:48 -080011588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011589
11590 enforceTelephonyFeatureWithException(callingPackage,
11591 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11592
Jack Nudelman644b91a2021-03-12 14:09:48 -080011593 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11594 .contains(callingPackage)) {
11595 throw new SecurityException("Calling package must be configured in the device config. "
11596 + "calling package: " + callingPackage);
11597 }
11598
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11600 final long identity = Binder.clearCallingIdentity();
11601
11602 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11603 try {
11604 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11605 switch (thermalMitigationAction) {
11606 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11607 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011608 handleDataThrottlingRequest(subId,
11609 thermalMitigationRequest.getDataThrottlingRequest(),
11610 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011611 break;
11612 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11613 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11614 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11615 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11616 }
11617
11618 // Ensure that radio is on. If not able to power on due to phone being
11619 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011620 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011621 thermalMitigationResult =
11622 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11623 break;
11624 }
11625
11626 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011627 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011628 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11629 break;
11630 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11631 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11632 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11633 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11634 }
11635
11636 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11637 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011638 Phone phone = getPhone(subId);
11639 if (phone == null) {
11640 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011641 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011642 break;
11643 }
11644
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011645 TelephonyConnectionService service =
11646 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011647 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011648 Log.e(LOG_TAG, "An emergency call is pending");
11649 thermalMitigationResult =
11650 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11651 break;
11652 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011653 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011654 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011655 break;
11656 }
11657 } else {
11658 thermalMitigationResult =
11659 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11660 break;
11661 }
11662
11663 // Turn radio off. If not able to power off due to phone being unavailable,
11664 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011665 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011666 thermalMitigationResult =
11667 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11668 break;
11669 }
11670 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011671 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011672 break;
11673 default:
11674 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11675 + "not exist. Requested action: " + thermalMitigationAction);
11676 }
11677 } catch (IllegalArgumentException e) {
11678 throw e;
11679 } catch (Exception e) {
11680 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11681 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11682 } finally {
11683 Binder.restoreCallingIdentity(identity);
11684 }
11685
11686 if (DBG) {
11687 log("thermalMitigationRequest returning with thermalMitigationResult: "
11688 + thermalMitigationResult);
11689 }
11690
11691 return thermalMitigationResult;
11692 }
Hui Wang641e81c2020-10-12 12:14:23 -070011693
11694 /**
11695 * Set the GbaService Package Name that Telephony will bind to.
11696 *
11697 * @param subId The sim that the GbaService is associated with.
11698 * @param packageName The name of the package to be replaced with.
11699 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11700 */
11701 @Override
11702 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11703 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011704 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011705 final long identity = Binder.clearCallingIdentity();
11706 try {
Jack Yu02533f12024-10-03 18:44:32 -070011707 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011708 } finally {
11709 Binder.restoreCallingIdentity(identity);
11710 }
11711 }
11712
11713 /**
11714 * Return the package name of the currently bound GbaService.
11715 *
11716 * @param subId The sim that the GbaService is associated with.
11717 * @return the package name of the GbaService configuration, null if GBA is not supported.
11718 */
11719 @Override
11720 public String getBoundGbaService(int subId) {
11721 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11722
11723 final long identity = Binder.clearCallingIdentity();
11724 try {
11725 return getGbaManager(subId).getServicePackage();
11726 } finally {
11727 Binder.restoreCallingIdentity(identity);
11728 }
11729 }
11730
11731 /**
11732 * Set the release time for telephony to unbind GbaService.
11733 *
11734 * @param subId The sim that the GbaService is associated with.
11735 * @param interval The release time to unbind GbaService by millisecond.
11736 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11737 */
11738 @Override
11739 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11740 enforceModifyPermission();
11741
11742 final long identity = Binder.clearCallingIdentity();
11743 try {
11744 return getGbaManager(subId).overrideReleaseTime(interval);
11745 } finally {
11746 Binder.restoreCallingIdentity(identity);
11747 }
11748 }
11749
11750 /**
11751 * Return the release time for telephony to unbind GbaService.
11752 *
11753 * @param subId The sim that the GbaService is associated with.
11754 * @return The release time to unbind GbaService by millisecond.
11755 */
11756 @Override
11757 public int getGbaReleaseTime(int subId) {
11758 enforceReadPrivilegedPermission("getGbaReleaseTime");
11759
11760 final long identity = Binder.clearCallingIdentity();
11761 try {
11762 return getGbaManager(subId).getReleaseTime();
11763 } finally {
11764 Binder.restoreCallingIdentity(identity);
11765 }
11766 }
11767
11768 private GbaManager getGbaManager(int subId) {
11769 GbaManager instance = GbaManager.getInstance(subId);
11770 if (instance == null) {
11771 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11772 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11773 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11774 }
11775 return instance;
11776 }
Hui Wang761a6682020-10-31 05:12:53 +000011777
11778 /**
11779 * indicate whether the device and the carrier can support
11780 * RCS VoLTE single registration.
11781 */
11782 @Override
11783 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011784 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11785 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11786 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11787 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011788
11789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11791 }
11792
11793 final long identity = Binder.clearCallingIdentity();
11794 try {
11795 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11796 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011797 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11798 if (isCapable != null) {
11799 return isCapable;
11800 }
Hui Wang761a6682020-10-31 05:12:53 +000011801 }
Hui Wang67af90e2021-06-04 16:57:15 -070011802 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11803 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011804 } finally {
11805 Binder.restoreCallingIdentity(identity);
11806 }
11807 }
11808
11809 /**
11810 * Register RCS provisioning callback.
11811 */
11812 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011813 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011814 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011815 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011816 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011817 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11818 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011819
11820 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11821 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11822 }
joonhunshin4ac60942023-11-15 15:23:39 +000011823 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11824 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11825 Binder.getCallingUserHandle())) {
11826 if (!isImsAvailableOnDevice()) {
11827 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11828 "IMS not available on device.");
11829 }
11830 } else {
11831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11832 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011833 }
11834
11835 final long identity = Binder.clearCallingIdentity();
11836 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011837 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011838 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011839 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11840 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011841 }
Hui Wang761a6682020-10-31 05:12:53 +000011842 } finally {
11843 Binder.restoreCallingIdentity(identity);
11844 }
11845 }
11846
11847 /**
11848 * Unregister RCS provisioning callback.
11849 */
11850 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011851 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011852 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011853 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011854 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011855 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11856 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011857
11858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11860 }
joonhunshin4ac60942023-11-15 15:23:39 +000011861
11862 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11863 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11864 Binder.getCallingUserHandle())) {
11865 if (!isImsAvailableOnDevice()) {
11866 // operation failed silently
11867 Rlog.w(LOG_TAG, "IMS not available on device.");
11868 return;
11869 }
11870 } else {
11871 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11872 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11873 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011874 }
11875
11876 final long identity = Binder.clearCallingIdentity();
11877 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011878 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011879 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
11884
11885 /**
11886 * trigger RCS reconfiguration.
11887 */
11888 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011889 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11890 "triggerRcsReconfiguration",
11891 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011892
11893 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11894 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11895 }
joonhunshin4ac60942023-11-15 15:23:39 +000011896 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11897 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11898 Binder.getCallingUserHandle())) {
11899 if (!isImsAvailableOnDevice()) {
11900 // ProvisioningManager can not handle ServiceSpecificException.
11901 // Throw the IllegalStateException and annotate ProvisioningManager.
11902 throw new IllegalStateException("IMS not available on device.");
11903 }
11904 } else {
11905 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11906 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011907 }
11908
11909 final long identity = Binder.clearCallingIdentity();
11910 try {
11911 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11912 } finally {
11913 Binder.restoreCallingIdentity(identity);
11914 }
11915 }
11916
11917 /**
11918 * Provide the client configuration parameters of the RCS application.
11919 */
11920 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011921 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11922 "setRcsClientConfiguration",
11923 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011924
11925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11926 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11927 }
joonhunshin4ac60942023-11-15 15:23:39 +000011928 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11929 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11930 Binder.getCallingUserHandle())) {
11931 if (!isImsAvailableOnDevice()) {
11932 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11933 "IMS not available on device.");
11934 }
11935 } else {
11936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11937 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011938 }
11939
11940 final long identity = Binder.clearCallingIdentity();
11941
11942 try {
11943 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11944 if (configBinder == null) {
11945 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011946 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11947 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011948 } else {
11949 configBinder.setRcsClientConfiguration(rcc);
11950 }
joonhunshin3e154242021-09-17 06:33:39 +000011951
11952 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11953 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011954 } catch (RemoteException e) {
11955 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011956 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11957 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011958 } finally {
11959 Binder.restoreCallingIdentity(identity);
11960 }
11961 }
11962
11963 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011964 * Enables or disables the test mode for RCS VoLTE single registration.
11965 */
11966 @Override
11967 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11969 "setRcsSingleRegistrationTestModeEnabled");
11970
11971 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11972 }
11973
11974 /**
11975 * Gets the test mode for RCS VoLTE single registration.
11976 */
11977 @Override
11978 public boolean getRcsSingleRegistrationTestModeEnabled() {
11979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11980 "getRcsSingleRegistrationTestModeEnabled");
11981
11982 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11983 }
11984
11985 /**
Hui Wang761a6682020-10-31 05:12:53 +000011986 * Overrides the config of RCS VoLTE single registration enabled for the device.
11987 */
11988 @Override
11989 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11990 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11991 "setDeviceSingleRegistrationEnabledOverride");
11992 enforceModifyPermission();
11993
11994 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11995 : Boolean.parseBoolean(enabledStr);
11996 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011997 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011998 }
11999
12000 /**
Tyler Gunn92479152021-01-20 16:30:10 -080012001 * Sends a device to device communication message. Only usable via shell.
12002 * @param message message to send.
12003 * @param value message value.
12004 */
12005 @Override
12006 public void sendDeviceToDeviceMessage(int message, int value) {
12007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012008 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012009 enforceModifyPermission();
12010
12011 final long identity = Binder.clearCallingIdentity();
12012 try {
12013 TelephonyConnectionService service =
12014 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12015 if (service == null) {
12016 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12017 return;
12018 }
12019 service.sendTestDeviceToDeviceMessage(message, value);
12020 } finally {
12021 Binder.restoreCallingIdentity(identity);
12022 }
12023 }
12024
Tyler Gunnbabbda02021-02-10 11:05:02 -080012025 /**
12026 * Sets the specified device to device transport active.
12027 * @param transport The transport to set active.
12028 */
12029 @Override
12030 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12032 "setActiveDeviceToDeviceTransport");
12033 enforceModifyPermission();
12034
12035 final long identity = Binder.clearCallingIdentity();
12036 try {
12037 TelephonyConnectionService service =
12038 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12039 if (service == null) {
12040 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12041 return;
12042 }
12043 service.setActiveDeviceToDeviceTransport(transport);
12044 } finally {
12045 Binder.restoreCallingIdentity(identity);
12046 }
12047 }
Tyler Gunn92479152021-01-20 16:30:10 -080012048
Tyler Gunnd4339262021-05-03 14:46:49 -070012049 @Override
12050 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12052 "setDeviceToDeviceForceEnabled");
12053
12054 final long identity = Binder.clearCallingIdentity();
12055 try {
12056 Arrays.stream(PhoneFactory.getPhones()).forEach(
12057 p -> {
12058 Phone thePhone = p.getImsPhone();
12059 if (thePhone != null && thePhone instanceof ImsPhone) {
12060 ImsPhone imsPhone = (ImsPhone) thePhone;
12061 CallTracker tracker = imsPhone.getCallTracker();
12062 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12063 ImsPhoneCallTracker imsPhoneCallTracker =
12064 (ImsPhoneCallTracker) tracker;
12065 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12066 }
12067 }
12068 }
12069 );
12070 } finally {
12071 Binder.restoreCallingIdentity(identity);
12072 }
12073 }
12074
Tyler Gunn92479152021-01-20 16:30:10 -080012075 /**
Hui Wang761a6682020-10-31 05:12:53 +000012076 * Gets the config of RCS VoLTE single registration enabled for the device.
12077 */
12078 @Override
12079 public boolean getDeviceSingleRegistrationEnabled() {
12080 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12081 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12082 }
12083
12084 /**
12085 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12086 */
12087 @Override
12088 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12090 "setCarrierSingleRegistrationEnabledOverride");
12091 enforceModifyPermission();
12092
12093 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12094 : Boolean.parseBoolean(enabledStr);
12095 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12096 subId, enabled);
12097 }
12098
12099 /**
12100 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12101 */
12102 @Override
12103 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12104 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12105 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12106 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012107
12108 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012109 * Overrides the ims feature validation result
12110 */
12111 @Override
12112 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12113 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12114 "setImsFeatureValidationOverride");
12115
12116 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12117 : Boolean.parseBoolean(enabledStr);
12118 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12119 subId, enabled);
12120 }
12121
12122 /**
12123 * Gets the ims feature validation override value
12124 */
12125 @Override
12126 public boolean getImsFeatureValidationOverride(int subId) {
12127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12128 "getImsFeatureValidationOverride");
12129 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12130 }
12131
12132 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012133 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12134 * their mobile plan.
12135 */
12136 @Override
12137 public String getMobileProvisioningUrl() {
12138 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12139 final long identity = Binder.clearCallingIdentity();
12140 try {
12141 return getDefaultPhone().getMobileProvisioningUrl();
12142 } finally {
12143 Binder.restoreCallingIdentity(identity);
12144 }
12145 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012146
James.cf Linbcdf8b32021-01-14 16:44:13 +080012147 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012148 * Get the EAB contact from the EAB database.
12149 */
12150 @Override
12151 public String getContactFromEab(String contact) {
12152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12153 enforceModifyPermission();
12154 final long identity = Binder.clearCallingIdentity();
12155 try {
12156 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12157 } finally {
12158 Binder.restoreCallingIdentity(identity);
12159 }
12160 }
12161
12162 /**
Calvin Pana1434322021-07-01 19:27:01 +080012163 * Get the EAB capability from the EAB database.
12164 */
12165 @Override
12166 public String getCapabilityFromEab(String contact) {
12167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12168 enforceModifyPermission();
12169 final long identity = Binder.clearCallingIdentity();
12170 try {
12171 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12172 } finally {
12173 Binder.restoreCallingIdentity(identity);
12174 }
12175 }
12176
12177 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012178 * Remove the EAB contacts from the EAB database.
12179 */
12180 @Override
12181 public int removeContactFromEab(int subId, String contacts) {
12182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12183 enforceModifyPermission();
12184 final long identity = Binder.clearCallingIdentity();
12185 try {
12186 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12187 } finally {
12188 Binder.restoreCallingIdentity(identity);
12189 }
12190 }
12191
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012192 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012193 public boolean getDeviceUceEnabled() {
12194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12195 final long identity = Binder.clearCallingIdentity();
12196 try {
12197 return mApp.getDeviceUceEnabled();
12198 } finally {
12199 Binder.restoreCallingIdentity(identity);
12200 }
12201 }
12202
12203 @Override
12204 public void setDeviceUceEnabled(boolean isEnabled) {
12205 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12206 final long identity = Binder.clearCallingIdentity();
12207 try {
12208 mApp.setDeviceUceEnabled(isEnabled);
12209 } finally {
12210 Binder.restoreCallingIdentity(identity);
12211 }
12212 }
12213
Brad Ebinger14d467f2021-02-12 06:18:28 +000012214 /**
12215 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12216 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12217 */
12218 // Used for SHELL command only right now.
12219 @Override
12220 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12221 List<String> featureTags) {
12222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12223 "addUceRegistrationOverrideShell");
12224 final long identity = Binder.clearCallingIdentity();
12225 try {
12226 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12227 new ArraySet<>(featureTags));
12228 } catch (ImsException e) {
12229 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12230 } finally {
12231 Binder.restoreCallingIdentity(identity);
12232 }
12233 }
12234
12235 /**
12236 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12237 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12238 */
12239 // Used for SHELL command only right now.
12240 @Override
12241 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12242 List<String> featureTags) {
12243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12244 "removeUceRegistrationOverrideShell");
12245 final long identity = Binder.clearCallingIdentity();
12246 try {
12247 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12248 new ArraySet<>(featureTags));
12249 } catch (ImsException e) {
12250 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12251 } finally {
12252 Binder.restoreCallingIdentity(identity);
12253 }
12254 }
12255
12256 /**
12257 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12258 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12259 */
12260 // Used for SHELL command only right now.
12261 @Override
12262 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12263 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12264 "clearUceRegistrationOverrideShell");
12265 final long identity = Binder.clearCallingIdentity();
12266 try {
12267 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12268 } catch (ImsException e) {
12269 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12270 } finally {
12271 Binder.restoreCallingIdentity(identity);
12272 }
12273 }
12274
12275 /**
12276 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12277 */
12278 // Used for SHELL command only right now.
12279 @Override
12280 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12282 "getLatestRcsContactUceCapabilityShell");
12283 final long identity = Binder.clearCallingIdentity();
12284 try {
12285 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12286 } catch (ImsException e) {
12287 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12288 } finally {
12289 Binder.restoreCallingIdentity(identity);
12290 }
12291 }
12292
12293 /**
12294 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12295 * device does not have an active PUBLISH.
12296 */
12297 // Used for SHELL command only right now.
12298 @Override
12299 public String getLastUcePidfXmlShell(int subId) {
12300 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12301 final long identity = Binder.clearCallingIdentity();
12302 try {
12303 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12304 } catch (ImsException e) {
12305 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12306 } finally {
12307 Binder.restoreCallingIdentity(identity);
12308 }
12309 }
12310
James.cf Line8713a42021-04-29 16:04:26 +080012311 /**
12312 * Remove UCE requests cannot be sent to the network status.
12313 */
12314 // Used for SHELL command only right now.
12315 @Override
12316 public boolean removeUceRequestDisallowedStatus(int subId) {
12317 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12318 final long identity = Binder.clearCallingIdentity();
12319 try {
12320 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12321 } catch (ImsException e) {
12322 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12323 } finally {
12324 Binder.restoreCallingIdentity(identity);
12325 }
12326 }
12327
James.cf Lin18bb9002021-05-25 01:37:38 +080012328 /**
12329 * Remove UCE requests cannot be sent to the network status.
12330 */
12331 // Used for SHELL command only.
12332 @Override
12333 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12334 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12335 final long identity = Binder.clearCallingIdentity();
12336 try {
12337 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12338 } catch (ImsException e) {
12339 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12340 } finally {
12341 Binder.restoreCallingIdentity(identity);
12342 }
12343 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012344
James.cf Lin4b784aa2021-01-31 03:25:15 +080012345 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012346 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12347 String callingPackage) {
12348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12349 mApp, subId, "setSignalStrengthUpdateRequest");
12350
joonhunshin4ac60942023-11-15 15:23:39 +000012351 enforceTelephonyFeatureWithException(callingPackage,
12352 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12353
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012354 final int callingUid = Binder.getCallingUid();
12355 // Verify that tha callingPackage belongs to the calling UID
12356 mApp.getSystemService(AppOpsManager.class)
12357 .checkPackage(callingUid, callingPackage);
12358
Rambo Wang3607f502021-02-01 21:51:40 -080012359 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012360
12361 final long identity = Binder.clearCallingIdentity();
12362 try {
12363 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12364 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12365
12366 if (result instanceof IllegalStateException) {
12367 throw (IllegalStateException) result;
12368 }
12369 } finally {
12370 Binder.restoreCallingIdentity(identity);
12371 }
12372 }
12373
12374 @Override
12375 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12376 String callingPackage) {
12377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12378 mApp, subId, "clearSignalStrengthUpdateRequest");
12379
joonhunshin4ac60942023-11-15 15:23:39 +000012380 enforceTelephonyFeatureWithException(callingPackage,
12381 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12382
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012383 final int callingUid = Binder.getCallingUid();
12384 // Verify that tha callingPackage belongs to the calling UID
12385 mApp.getSystemService(AppOpsManager.class)
12386 .checkPackage(callingUid, callingPackage);
12387
12388 final long identity = Binder.clearCallingIdentity();
12389 try {
12390 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12391 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12392
12393 if (result instanceof IllegalStateException) {
12394 throw (IllegalStateException) result;
12395 }
12396 } finally {
12397 Binder.restoreCallingIdentity(identity);
12398 }
12399 }
12400
Rambo Wang3607f502021-02-01 21:51:40 -080012401 private static void validateSignalStrengthUpdateRequest(Context context,
12402 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012403 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012404 // phone/system process do not have further restriction on request
12405 return;
12406 }
12407
12408 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012409 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012410 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012411 context.enforceCallingOrSelfPermission(
12412 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12413 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012414 }
12415
12416 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012417 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012418 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012419 || info.isEnabled()) {
12420 throw new IllegalArgumentException(
12421 "Only system can set hide fields in SignalThresholdInfo");
12422 }
12423
12424 // Thresholds length for each RAN need in range. This has been validated in
12425 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12426 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12427 final int[] thresholds = info.getThresholds();
12428 Objects.requireNonNull(thresholds);
12429 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12430 || thresholds.length
12431 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12432 throw new IllegalArgumentException(
12433 "thresholds length is out of range: " + thresholds.length);
12434 }
12435 }
12436 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012437
12438 /**
12439 * Gets the current phone capability.
12440 *
12441 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12442 * @return the PhoneCapability which describes the data connection capability of modem.
12443 * It's used to evaluate possible phone config change, for example from single
12444 * SIM device to multi-SIM device.
12445 */
12446 @Override
12447 public PhoneCapability getPhoneCapability() {
12448 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012449
12450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12451 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12452
SongFerngWang8236caa2021-01-17 21:51:44 +080012453 final long identity = Binder.clearCallingIdentity();
12454 try {
12455 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12456 } finally {
12457 Binder.restoreCallingIdentity(identity);
12458 }
12459 }
Michele Berionne5e411512020-11-13 02:36:59 +000012460
12461 /**
12462 * Prepare TelephonyManager for an unattended reboot. The reboot is
12463 * required to be done shortly after the API is invoked.
12464 */
12465 @Override
12466 @TelephonyManager.PrepareUnattendedRebootResult
12467 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012468 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012469 enforceRebootPermission();
12470
joonhunshin4ac60942023-11-15 15:23:39 +000012471 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12472 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12473
Michele Berionne5e411512020-11-13 02:36:59 +000012474 final long identity = Binder.clearCallingIdentity();
12475 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012476 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012477 } finally {
12478 Binder.restoreCallingIdentity(identity);
12479 }
12480 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012481
12482 /**
12483 * Request to get the current slicing configuration including URSP rules and
12484 * NSSAIs (configured, allowed and rejected).
12485 *
12486 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12487 */
12488 @Override
12489 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012490 TelephonyPermissions
12491 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12492 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012493
joonhunshin4ac60942023-11-15 15:23:39 +000012494 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12495 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12496 "getSlicingConfig");
12497
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012498 final long identity = Binder.clearCallingIdentity();
12499 try {
12500 Phone phone = getDefaultPhone();
12501 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12502 } finally {
12503 Binder.restoreCallingIdentity(identity);
12504 }
12505 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012506
12507 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012508 * Check whether the given premium capability is available for purchase from the carrier.
12509 *
12510 * @param capability The premium capability to check.
12511 * @param subId The subId to check the premium capability for.
12512 *
12513 * @return Whether the given premium capability is available to purchase.
12514 */
12515 @Override
12516 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12517 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12518 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12519 log("Premium capability "
12520 + TelephonyManager.convertPremiumCapabilityToString(capability)
12521 + " is not available for purchase due to missing permissions.");
12522 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12523 + "permission READ_BASIC_PHONE_STATE.");
12524 }
12525
joonhunshin4ac60942023-11-15 15:23:39 +000012526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12527 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12528
Sarah Chin2ec39f62022-08-31 17:03:26 -070012529 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012530 if (phone == null) {
12531 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12532 return false;
12533 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012534 final long identity = Binder.clearCallingIdentity();
12535 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012536 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012537 .isPremiumCapabilityAvailableForPurchase(capability);
12538 } finally {
12539 Binder.restoreCallingIdentity(identity);
12540 }
12541 }
12542
12543 /**
12544 * Purchase the given premium capability from the carrier.
12545 *
12546 * @param capability The premium capability to purchase.
12547 * @param callback The result of the purchase request.
12548 * @param subId The subId to purchase the premium capability for.
12549 */
12550 @Override
12551 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12552 log("purchasePremiumCapability: capability="
12553 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12554 + getCurrentPackageName());
12555
12556 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12557 mApp, "purchasePremiumCapability")) {
12558 log("purchasePremiumCapability "
12559 + TelephonyManager.convertPremiumCapabilityToString(capability)
12560 + " failed due to missing permissions.");
12561 throw new SecurityException("purchasePremiumCapability requires permission "
12562 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012563 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12564 mApp, "purchasePremiumCapability")) {
12565 log("purchasePremiumCapability "
12566 + TelephonyManager.convertPremiumCapabilityToString(capability)
12567 + " failed due to missing permissions.");
12568 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012569 }
12570
joonhunshin4ac60942023-11-15 15:23:39 +000012571 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12572 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12573
Sarah Chin2ec39f62022-08-31 17:03:26 -070012574 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012575 if (phone == null) {
12576 try {
12577 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12578 callback.accept(result);
12579 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12580 } catch (RemoteException e) {
12581 String logStr = "Purchase premium capability "
12582 + TelephonyManager.convertPremiumCapabilityToString(capability)
12583 + " failed due to RemoteException handling null phone: " + e;
12584 if (DBG) log(logStr);
12585 AnomalyReporter.reportAnomaly(
12586 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12587 }
12588 return;
12589 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012590
12591 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012592 try {
Jack Yube3fa442024-09-16 14:39:45 -070012593 if (mFeatureFlags.hsumPackageManager()) {
12594 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12595 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12596 } else {
12597 callingProcess = mApp.getPackageManager().getApplicationInfo(
12598 getCurrentPackageName(), 0).processName;
12599 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012600 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012601 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012602 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012603
12604 boolean isVisible = false;
12605 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12606 if (am != null) {
12607 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12608 if (processes != null) {
12609 for (ActivityManager.RunningAppProcessInfo process : processes) {
12610 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012611 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012612 if (process.processName.equals(callingProcess) && process.importance
12613 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12614 isVisible = true;
12615 break;
12616 }
12617 }
12618 }
12619 }
12620
12621 if (!isVisible) {
12622 try {
12623 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12624 callback.accept(result);
12625 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12626 } catch (RemoteException e) {
12627 String logStr = "Purchase premium capability "
12628 + TelephonyManager.convertPremiumCapabilityToString(capability)
12629 + " failed due to RemoteException handling background application: " + e;
12630 if (DBG) log(logStr);
12631 AnomalyReporter.reportAnomaly(
12632 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12633 }
12634 return;
12635 }
12636
Sarah Chin71b3a852022-09-28 15:54:19 -070012637 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012638 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012639 }
12640
12641 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012642 * Register an IMS connection state callback
12643 */
12644 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012645 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12646 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012647 if (feature == ImsFeature.FEATURE_MMTEL) {
12648 // ImsMmTelManager
12649 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12650 TelephonyPermissions
12651 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12652 mApp, subId, "registerImsStateCallback");
12653 } else if (feature == ImsFeature.FEATURE_RCS) {
12654 // ImsRcsManager or SipDelegateManager
12655 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12656 Binder.getCallingUid(), "registerImsStateCallback",
12657 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12658 Manifest.permission.READ_PRECISE_PHONE_STATE,
12659 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12660 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12661 }
12662
12663 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12665 "IMS not available on device.");
12666 }
12667
12668 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12669 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12670 }
12671
12672 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12673 if (controller == null) {
12674 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12675 "IMS not available on device.");
12676 }
12677
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012678 if (callingPackage == null) {
12679 callingPackage = getCurrentPackageName();
12680 }
12681
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012682 final long token = Binder.clearCallingIdentity();
12683 try {
12684 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012685 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012686 } catch (ImsException e) {
12687 throw new ServiceSpecificException(e.getCode());
12688 } finally {
12689 Binder.restoreCallingIdentity(token);
12690 }
12691 }
12692
12693 /**
12694 * Unregister an IMS connection state callback
12695 */
12696 @Override
12697 public void unregisterImsStateCallback(IImsStateCallback cb) {
12698 final long token = Binder.clearCallingIdentity();
12699 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12700 if (controller == null) {
12701 return;
12702 }
12703 try {
12704 controller.unregisterImsStateCallback(cb);
12705 } finally {
12706 Binder.restoreCallingIdentity(token);
12707 }
12708 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012709
12710 /**
12711 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12712 *
12713 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012714 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012715 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012716 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012717 * If there is current registered network this value will be same as the registered cell
12718 * identity. If the device goes out of service the previous cell identity is cached and
12719 * will be returned. If the cache age of the Cell identity is more than 24 hours
12720 * it will be cleared and null will be returned.
12721 *
12722 */
12723 @Override
12724 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12725 String callingFeatureId) {
12726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12727 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12728 LocationAccessPolicy.checkLocationPermission(mApp,
12729 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12730 .setCallingPackage(callingPackage)
12731 .setCallingFeatureId(callingFeatureId)
12732 .setCallingPid(Binder.getCallingPid())
12733 .setCallingUid(Binder.getCallingUid())
12734 .setMethod("getLastKnownCellIdentity")
12735 .setLogAsInfo(true)
12736 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12737 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12738 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12739 .build());
12740
12741 boolean hasFinePermission =
12742 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12743 if (!hasFinePermission
12744 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12745 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012746 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012747 }
12748
12749 final long identity = Binder.clearCallingIdentity();
12750 try {
Ling Mac28f0212023-03-24 16:07:15 -070012751 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012752 if (sst == null) return null;
12753 return sst.getLastKnownCellIdentity();
12754 } finally {
12755 Binder.restoreCallingIdentity(identity);
12756 }
12757 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012758
jimsun3b9ccac2021-10-26 15:01:23 +080012759 /**
12760 * Sets the modem service class Name that Telephony will bind to.
12761 *
12762 * @param serviceName The class name of the modem service.
12763 * @return true if the operation is succeed, otherwise false.
12764 */
12765 public boolean setModemService(String serviceName) {
12766 Log.d(LOG_TAG, "setModemService - " + serviceName);
12767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012769 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12770 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012771 return mPhoneConfigurationManager.setModemService(serviceName);
12772 }
12773
12774 /**
12775 * Return the class name of the currently bounded modem service.
12776 *
12777 * @return the class name of the modem service.
12778 */
12779 public String getModemService() {
12780 String result;
12781 Log.d(LOG_TAG, "getModemService");
12782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12783 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012784 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012785 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12786 "getModemService");
12787 result = mPhoneConfigurationManager.getModemService();
12788 Log.d(LOG_TAG, "result = " + result);
12789 return result;
12790 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012791
Hakjun Choi3ee81112023-12-19 15:40:58 +000012792 /**
12793 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12794 * including carrier config, entitlement server, and config update.
12795 *
12796 * @param subId subId The subscription ID of the carrier.
12797 *
12798 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12799 * be returned.
12800 *
12801 * @throws SecurityException if the caller doesn't have the required permission.
12802 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012803 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12804 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012805 final long identity = Binder.clearCallingIdentity();
12806 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012807 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012808 } finally {
12809 Binder.restoreCallingIdentity(identity);
12810 }
12811 }
12812
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012813 @Override
12814 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12815 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12816 mApp.enforceCallingOrSelfPermission(
12817 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12819
12820 final long identity = Binder.clearCallingIdentity();
12821 try {
12822 Phone phone = getPhone(subId);
12823 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012824 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12825 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012826 phone.setVoiceServiceStateOverride(hasService);
12827 } finally {
12828 Binder.restoreCallingIdentity(identity);
12829 }
12830 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012831
12832 /**
12833 * set removable eSIM as default eUICC.
12834 *
12835 * @hide
12836 */
12837 @Override
12838 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12839 enforceModifyPermission();
12840 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12841
12842 final long identity = Binder.clearCallingIdentity();
12843 try {
12844 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12845 } finally {
12846 Binder.restoreCallingIdentity(identity);
12847 }
12848 }
12849
12850 /**
12851 * Returns whether the removable eSIM is default eUICC or not.
12852 *
12853 * @hide
12854 */
12855 @Override
12856 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12857 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12858 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12859
12860 final long identity = Binder.clearCallingIdentity();
12861 try {
12862 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12863 } finally {
12864 Binder.restoreCallingIdentity(identity);
12865 }
12866 }
12867
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012868 /**
12869 * Get the component name of the default app to direct respond-via-message intent for the
12870 * user associated with this subscription, update the cache if there is no respond-via-message
12871 * application currently configured for this user.
12872 * @return component name of the app and class to direct Respond Via Message intent to, or
12873 * {@code null} if the functionality is not supported.
12874 * @hide
12875 */
12876 @Override
12877 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12878 boolean updateIfNeeded) {
12879 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012880
joonhunshin4ac60942023-11-15 15:23:39 +000012881 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12882 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12883 "getDefaultRespondViaMessageApplication");
12884
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012885 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12886
Grant Menkeb0372492024-09-19 18:01:29 -070012887 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12888 UserHandle mainUser = null;
12889 Context userContext = null;
12890 final long identity = Binder.clearCallingIdentity();
12891 try {
12892 mainUser = mUserManager.getMainUser();
12893 userContext = context.createContextAsUser(mainUser, 0);
12894 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12895 } finally {
12896 Binder.restoreCallingIdentity(identity);
12897 }
12898 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12899 updateIfNeeded, mainUser);
12900 } else {
12901 UserHandle userHandle = null;
12902 final long identity = Binder.clearCallingIdentity();
12903 try {
12904 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12905 } finally {
12906 Binder.restoreCallingIdentity(identity);
12907 }
12908 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12909 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012910 }
Grant Menkeb0372492024-09-19 18:01:29 -070012911
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012912 }
Jack Yuf5badd92022-12-08 00:50:53 -080012913
12914 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012915 * Set whether the device is able to connect with null ciphering or integrity
12916 * algorithms. This is a global setting and will apply to all active subscriptions
12917 * and all new subscriptions after this.
12918 *
12919 * @param enabled when true, null cipher and integrity algorithms are allowed.
12920 * @hide
12921 */
12922 @Override
12923 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12924 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12925 enforceModifyPermission();
12926 checkForNullCipherAndIntegritySupport();
12927
12928 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12929 // for listening to these preference changes and applying them immediately.
12930 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12931 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12932 editor.apply();
12933
12934 for (Phone phone: PhoneFactory.getPhones()) {
12935 phone.handleNullCipherEnabledChange();
12936 }
12937 }
12938
12939
12940 /**
12941 * Get whether the device is able to connect with null ciphering or integrity
12942 * algorithms. Note that this retrieves the phone-global preference and not
12943 * the state of the radio.
12944 *
12945 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12946 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12947 * version for this feature.
12948 * @hide
12949 */
12950 @Override
12951 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12952 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12953 enforceReadPermission();
12954 checkForNullCipherAndIntegritySupport();
12955 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12956 }
12957
12958 private void checkForNullCipherAndIntegritySupport() {
12959 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12960 throw new UnsupportedOperationException(
12961 "Null cipher and integrity operations require HAL 2.1 or above");
12962 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012963 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12964 throw new UnsupportedOperationException(
12965 "Null cipher and integrity operations unsupported by modem");
12966 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012967 }
12968
Gil Cukierman06403e12023-11-29 16:33:03 +000012969 private void checkForIdentifierDisclosureNotificationSupport() {
12970 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12971 throw new UnsupportedOperationException(
12972 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12973 + "above");
12974 }
12975 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12976 throw new UnsupportedOperationException(
12977 "Cellular identifier disclosure transparency operations unsupported by modem");
12978 }
12979 }
12980
Michael Groover826b71d2023-12-21 22:08:06 -060012981 private void checkForNullCipherNotificationSupport() {
12982 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12983 throw new UnsupportedOperationException(
12984 "Null cipher notification operations require HAL 2.2 or above");
12985 }
12986 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12987 throw new UnsupportedOperationException(
12988 "Null cipher notification operations unsupported by modem");
12989 }
12990 }
12991
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012992 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012993 * Get the SIM state for the slot index.
12994 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12995 *
12996 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12997 */
12998 @Override
12999 @SimState
13000 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070013001 if (!mApp.getResources().getBoolean(
13002 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13004 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13005 }
joonhunshin4ac60942023-11-15 15:23:39 +000013006
Jack Yuf5badd92022-12-08 00:50:53 -080013007 IccCardConstants.State simState;
13008 if (slotIndex < 0) {
13009 simState = IccCardConstants.State.UNKNOWN;
13010 } else {
13011 Phone phone = null;
13012 try {
13013 phone = PhoneFactory.getPhone(slotIndex);
13014 } catch (IllegalStateException e) {
13015 // ignore
13016 }
13017 if (phone == null) {
13018 simState = IccCardConstants.State.UNKNOWN;
13019 } else {
13020 IccCard icc = phone.getIccCard();
13021 if (icc == null) {
13022 simState = IccCardConstants.State.UNKNOWN;
13023 } else {
13024 simState = icc.getState();
13025 }
13026 }
13027 }
13028 return simState.ordinal();
13029 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013030
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013031 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13032 boolean enableLogcat,
13033 long logcatStartTimestampMillis, boolean enableTelecomDump,
13034 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013035 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013036 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13037 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13038 ecdDataBuilder
13039 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13040 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013041 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013042 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013043 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013044 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13045 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013046 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13047 Executors.newCachedThreadPool(), db,
13048 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013049 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013050 }
13051
13052 /**
13053 * Request telephony to persist state for debugging emergency call failures.
13054 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013055 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013056 * @param enableLogcat whether to collect logcat output
13057 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13058 * @param enableTelecomDump whether to collect telecom dumpsys
13059 * @param enableTelephonyDump whether to collect telephony dumpsys
13060 */
13061 @Override
13062 @RequiresPermission(android.Manifest.permission.DUMP)
13063 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13064 long logcatStartTimestampMillis, boolean enableTelecomDump,
13065 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013066 // Verify that the caller has READ_DROPBOX_DATA permission.
13067 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13068 && Flags.enableReadDropboxPermission()) {
13069 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13070 "persistEmergencyCallDiagnosticData");
13071 } else {
13072 // Otherwise, enforce legacy permission.
13073 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13074 "persistEmergencyCallDiagnosticData");
13075 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013076 final long identity = Binder.clearCallingIdentity();
13077 try {
13078 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13079 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13080
13081 } finally {
13082 Binder.restoreCallingIdentity(identity);
13083 }
13084 }
13085
Hui Wang9b5793a2022-12-05 14:38:06 -060013086 /**
13087 * Get current cell broadcast ranges.
13088 */
13089 @Override
13090 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13091 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13092 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13093 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013094
13095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13096 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13097
Hui Wang9b5793a2022-12-05 14:38:06 -060013098 final long identity = Binder.clearCallingIdentity();
13099 try {
13100 return getPhone(subId).getCellBroadcastIdRanges();
13101 } finally {
13102 Binder.restoreCallingIdentity(identity);
13103 }
13104 }
13105
13106 /**
13107 * Set reception of cell broadcast messages with the list of the given ranges
13108 *
13109 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13110 */
13111 @Override
13112 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13113 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13114 @Nullable IIntegerConsumer callback) {
13115 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13116 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013117
13118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13119 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13120
Hui Wang9b5793a2022-12-05 14:38:06 -060013121 final long identity = Binder.clearCallingIdentity();
13122 try {
13123 Phone phone = getPhoneFromSubId(subId);
13124 if (DBG) {
13125 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13126 }
13127 phone.setCellBroadcastIdRanges(ranges, result -> {
13128 if (callback != null) {
13129 try {
13130 callback.accept(result);
13131 } catch (RemoteException e) {
13132 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13133 }
13134 }
13135 });
13136 } finally {
13137 Binder.restoreCallingIdentity(identity);
13138 }
13139 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013140
13141 /**
13142 * Returns whether the device supports the domain selection service.
13143 *
13144 * @return {@code true} if the device supports the domain selection service.
13145 */
13146 @Override
13147 public boolean isDomainSelectionSupported() {
13148 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13149 "isDomainSelectionSupported");
13150
13151 final long identity = Binder.clearCallingIdentity();
13152 try {
13153 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13154 } finally {
13155 Binder.restoreCallingIdentity(identity);
13156 }
13157 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013158
13159 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013160 * Returns whether the AOSP domain selection service is supported.
13161 *
13162 * @return {@code true} if the AOSP domain selection service is supported,
13163 * {@code false} otherwise.
13164 */
13165 @Override
13166 public boolean isAospDomainSelectionService() {
13167 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13168 "isAospDomainSelectionService");
13169
13170 final long identity = Binder.clearCallingIdentity();
13171 try {
13172 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13173 String dssComponentName = mApp.getResources().getString(
13174 R.string.config_domain_selection_service_component_name);
13175 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13176 TelephonyDomainSelectionService.class.getName());
13177 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13178 + ", aosp=" + componentName.flattenToString());
13179 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13180 }
13181 } finally {
13182 Binder.restoreCallingIdentity(identity);
13183 }
13184 return false;
13185 }
13186
13187 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013188 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13189 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13190 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013191 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013192 * @param enableSatellite {@code true} to enable the satellite modem and
13193 * {@code false} to disable.
13194 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013195 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013196 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013197 *
13198 * @throws SecurityException if the caller doesn't have the required permission.
13199 */
13200 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013201 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013202 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013203 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013204 final long identity = Binder.clearCallingIdentity();
13205 try {
13206 if (enableSatellite) {
youngtaecha3a9c8a62024-11-01 20:46:08 +000013207 String caller = "PIM:requestSatelliteEnabled";
Hyosun322782b2024-10-24 11:37:59 +000013208 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13209 @Override
13210 protected void onReceiveResult(int resultCode, Bundle resultData) {
13211 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13212 + ", resultData=" + resultData);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013213 mSatelliteController.decrementResultReceiverCount(caller);
13214
Hyosun322782b2024-10-24 11:37:59 +000013215 boolean isAllowed = false;
13216 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13217 callback::accept);
13218 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13219 if (resultData != null
13220 && resultData.containsKey(
13221 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13222 isAllowed = resultData.getBoolean(
13223 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13224 } else {
13225 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13226 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013227 } else {
Hyosun322782b2024-10-24 11:37:59 +000013228 result.accept(resultCode);
13229 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013230 }
Hyosun322782b2024-10-24 11:37:59 +000013231 if (isAllowed) {
Thomas Nguyendd8e0832024-11-01 00:18:58 +000013232 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13233 @Override
13234 protected void onReceiveResult(int resultCode, Bundle resultData) {
13235 Log.d(LOG_TAG, "updateSystemSelectionChannels resultCode="
13236 + resultCode);
13237 mSatelliteController.requestSatelliteEnabled(
Duke Lee8852e512024-10-06 12:55:43 +090013238 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyendd8e0832024-11-01 00:18:58 +000013239 }
13240 };
13241 mSatelliteAccessController.updateSystemSelectionChannels(
13242 resultReceiver);
Hyosun322782b2024-10-24 11:37:59 +000013243 } else {
13244 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13245 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013246 }
Hyosun322782b2024-10-24 11:37:59 +000013247 };
13248 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13249 resultReceiver, true);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013250 mSatelliteController.incrementResultReceiverCount(caller);
Hyosun322782b2024-10-24 11:37:59 +000013251 } else {
13252 // No need to check if satellite is allowed at current location when disabling
13253 // satellite
13254 mSatelliteController.requestSatelliteEnabled(
13255 enableSatellite, enableDemoMode, isEmergency, callback);
13256 }
13257 } finally {
13258 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013259 }
Sarah Chin503828c2023-02-01 23:54:20 -080013260 }
13261
13262 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013263 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013264 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013265 * @param result The result receiver that returns whether the satellite modem is enabled
13266 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013267 *
13268 * @throws SecurityException if the caller doesn't have the required permission.
13269 */
13270 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013271 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013272 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013273 final long identity = Binder.clearCallingIdentity();
13274 try {
13275 mSatelliteController.requestIsSatelliteEnabled(result);
13276 } finally {
13277 Binder.restoreCallingIdentity(identity);
13278 }
Sarah Chin503828c2023-02-01 23:54:20 -080013279 }
13280
13281 /**
Sarah Chin43457982023-02-15 17:50:38 -080013282 * Request to get whether the satellite service demo mode is enabled.
13283 *
Sarah Chin43457982023-02-15 17:50:38 -080013284 * @param result The result receiver that returns whether the satellite demo mode is enabled
13285 * if the request is successful or an error code if the request failed.
13286 *
13287 * @throws SecurityException if the caller doesn't have the required permission.
13288 */
13289 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013290 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013291 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013292 final long identity = Binder.clearCallingIdentity();
13293 try {
13294 mSatelliteController.requestIsDemoModeEnabled(result);
13295 } finally {
13296 Binder.restoreCallingIdentity(identity);
13297 }
Sarah Chin43457982023-02-15 17:50:38 -080013298 }
13299
13300 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013301 * Request to get whether the satellite service is enabled with emergency mode.
13302 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013303 * @param result The result receiver that returns whether the satellite emergency mode is
13304 * enabled if the request is successful or an error code if the request failed.
13305 *
13306 * @throws SecurityException if the caller doesn't have the required permission.
13307 */
13308 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013309 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013310 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013311 final long identity = Binder.clearCallingIdentity();
13312 try {
13313 mSatelliteController.requestIsEmergencyModeEnabled(result);
13314 } finally {
13315 Binder.restoreCallingIdentity(identity);
13316 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013317 }
13318
13319 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013320 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013321 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013322 * @param result The result receiver that returns whether the satellite service is supported on
13323 * the device if the request is successful or an error code if the request failed.
Hyosun322782b2024-10-24 11:37:59 +000013324 *
13325 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chin503828c2023-02-01 23:54:20 -080013326 */
13327 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013328 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013329 enforceSatelliteCommunicationPermission("requestIsSatelliteSupported");
13330 final long identity = Binder.clearCallingIdentity();
13331 try {
13332 mSatelliteController.requestIsSatelliteSupported(result);
13333 } finally {
13334 Binder.restoreCallingIdentity(identity);
13335 }
Sarah Chin503828c2023-02-01 23:54:20 -080013336 }
13337
13338 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013339 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013340 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013341 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13342 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013343 *
13344 * @throws SecurityException if the caller doesn't have required permission.
13345 */
13346 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013347 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013348 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013349 final long identity = Binder.clearCallingIdentity();
13350 try {
13351 mSatelliteController.requestSatelliteCapabilities(result);
13352 } finally {
13353 Binder.restoreCallingIdentity(identity);
13354 }
Sarah Chin503828c2023-02-01 23:54:20 -080013355 }
13356
13357 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013358 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013359 * This can be called by the pointing UI when the user starts pointing to the satellite.
13360 * Modem should continue to report the pointing input as the device or satellite moves.
13361 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013362 * @param resultCallback The callback to get the result of the request.
13363 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013364 *
13365 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013366 */
13367 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013368 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013369 @NonNull IIntegerConsumer resultCallback,
13370 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13371 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013372 final long identity = Binder.clearCallingIdentity();
13373 try {
13374 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13375 } finally {
13376 Binder.restoreCallingIdentity(identity);
13377 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013378 }
13379
13380 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013381 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013382 * This can be called by the pointing UI when the user stops pointing to the satellite.
13383 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013384 * @param resultCallback The callback to get the result of the request.
13385 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013386 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013387 *
13388 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013389 */
13390 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013391 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013392 @NonNull IIntegerConsumer resultCallback,
13393 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13394 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013395 final long identity = Binder.clearCallingIdentity();
13396 try {
13397 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13398 } finally {
13399 Binder.restoreCallingIdentity(identity);
13400 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013401 }
13402
13403 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013404 * Register the subscription with a satellite provider.
13405 * This is needed to register the subscription if the provider allows dynamic registration.
13406 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013407 * @param token The token to be used as a unique identifier for provisioning with satellite
13408 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013409 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013410 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013411 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013412 * @return The signal transport used by the caller to cancel the provision request,
13413 * or {@code null} if the request failed.
13414 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013415 * @throws SecurityException if the caller doesn't have the required permission.
13416 */
13417 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013418 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013419 @NonNull String token, @NonNull byte[] provisionData,
13420 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013421 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013422 final long identity = Binder.clearCallingIdentity();
13423 try {
13424 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013425 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013426 } finally {
13427 Binder.restoreCallingIdentity(identity);
13428 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013429 }
13430
13431 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013432 * Unregister the device/subscription with the satellite provider.
13433 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013434 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013435 * should report as deprovisioned.
13436 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013437 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013438 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013439 *
13440 * @throws SecurityException if the caller doesn't have the required permission.
13441 */
13442 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013443 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013444 @NonNull String token, @NonNull IIntegerConsumer callback) {
13445 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013446 final long identity = Binder.clearCallingIdentity();
13447 try {
13448 mSatelliteController.deprovisionSatelliteService(token, callback);
13449 } finally {
13450 Binder.restoreCallingIdentity(identity);
13451 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013452 }
13453
13454 /**
Sarah Chin43457982023-02-15 17:50:38 -080013455 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013456 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013457 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013458 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013459 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013460 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013461 * @throws SecurityException if the caller doesn't have the required permission.
13462 */
13463 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013464 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013465 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013466 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013467 final long identity = Binder.clearCallingIdentity();
13468 try {
13469 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13470 } finally {
13471 Binder.restoreCallingIdentity(identity);
13472 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013473 }
13474
13475 /**
Sarah Chin43457982023-02-15 17:50:38 -080013476 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013477 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013478 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013479 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013480 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013481 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013482 * @throws SecurityException if the caller doesn't have the required permission.
13483 */
13484 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013485 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013486 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013487 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013488 final long identity = Binder.clearCallingIdentity();
13489 try {
13490 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13491 } finally {
13492 Binder.restoreCallingIdentity(identity);
13493 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013494 }
13495
13496 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013497 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013498 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013499 * @param result The result receiver that returns whether the device is provisioned with a
13500 * satellite provider if the request is successful or an error code if the
13501 * request failed.
13502 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013503 * @throws SecurityException if the caller doesn't have the required permission.
13504 */
13505 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013506 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013507 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013508 final long identity = Binder.clearCallingIdentity();
13509 try {
13510 mSatelliteController.requestIsSatelliteProvisioned(result);
13511 } finally {
13512 Binder.restoreCallingIdentity(identity);
13513 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013514 }
13515
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013516 /**
Sarah Chin43457982023-02-15 17:50:38 -080013517 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013518 *
Sarah Chin43457982023-02-15 17:50:38 -080013519 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013520 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013521 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013522 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013523 * @throws SecurityException if the caller doesn't have the required permission.
13524 */
13525 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013526 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013527 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013528 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013529 final long identity = Binder.clearCallingIdentity();
13530 try {
13531 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13532 } finally {
13533 Binder.restoreCallingIdentity(identity);
13534 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013535 }
13536
13537 /**
Sarah Chin43457982023-02-15 17:50:38 -080013538 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013539 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013540 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013541 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013542 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013543 *
13544 * @throws SecurityException if the caller doesn't have the required permission.
13545 */
13546 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013547 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013548 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013549 final long identity = Binder.clearCallingIdentity();
13550 try {
13551 mSatelliteController.unregisterForModemStateChanged(callback);
13552 } finally {
13553 Binder.restoreCallingIdentity(identity);
13554 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013555 }
13556
13557 /**
13558 * Register to receive incoming datagrams over satellite.
13559 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013560 * @param callback The callback to handle incoming datagrams over satellite.
13561 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013562 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013563 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013564 * @throws SecurityException if the caller doesn't have the required permission.
13565 */
13566 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013567 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013568 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013569 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013570 final long identity = Binder.clearCallingIdentity();
13571 try {
13572 return mSatelliteController.registerForIncomingDatagram(callback);
13573 } finally {
13574 Binder.restoreCallingIdentity(identity);
13575 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013576 }
13577
13578 /**
13579 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013580 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013581 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013582 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013583 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013584 *
13585 * @throws SecurityException if the caller doesn't have the required permission.
13586 */
13587 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013588 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013589 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013590 final long identity = Binder.clearCallingIdentity();
13591 try {
13592 mSatelliteController.unregisterForIncomingDatagram(callback);
13593 } finally {
13594 Binder.restoreCallingIdentity(identity);
13595 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013596 }
13597
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013598 /**
13599 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013600 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013601 * This method requests modem to check if there are any pending datagrams to be received over
13602 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013603 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013604 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013605 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013606 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013607 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013608 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013609 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013610 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013611 final long identity = Binder.clearCallingIdentity();
13612 try {
13613 mSatelliteController.pollPendingDatagrams(callback);
13614 } finally {
13615 Binder.restoreCallingIdentity(identity);
13616 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013617 }
13618
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013619 /**
13620 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013621 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013622 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13623 * input to this method. Datagram received here will be passed down to modem without any
13624 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013625 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013626 * @param datagramType datagram type indicating whether the datagram is of type
13627 * SOS_SMS or LOCATION_SHARING.
13628 * @param datagram encoded gateway datagram which is encrypted by the caller.
13629 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013630 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13631 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013632 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013633 *
13634 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013635 */
13636 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013637 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013638 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13639 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013640 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013641 final long identity = Binder.clearCallingIdentity();
13642 try {
13643 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13644 callback);
13645 } finally {
13646 Binder.restoreCallingIdentity(identity);
13647 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013648 }
13649
Sarah Chindf715ec2023-02-13 13:46:24 -080013650 /**
Duke Lee8852e512024-10-06 12:55:43 +090013651 * Returns integer array of disallowed reasons of satellite.
13652 *
13653 * @return Integer array of disallowed reasons of satellite.
13654 *
13655 * @throws SecurityException if the caller doesn't have the required permission.
13656 */
13657 @NonNull public int[] getSatelliteDisallowedReasons() {
13658 enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons");
13659 final long identity = Binder.clearCallingIdentity();
13660 try {
13661 return mSatelliteAccessController.getSatelliteDisallowedReasons()
13662 .stream().mapToInt(Integer::intValue).toArray();
13663 } finally {
13664 Binder.restoreCallingIdentity(identity);
13665 }
13666 }
13667
13668 /**
13669 * Registers for disallowed reasons change event from satellite service.
13670 *
13671 * @param callback The callback to handle disallowed reasons changed event.
13672 *
13673 * @throws SecurityException if the caller doesn't have the required permission.
13674 */
13675 @Override
13676 public void registerForSatelliteDisallowedReasonsChanged(
13677 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13678 enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged");
13679 final long identity = Binder.clearCallingIdentity();
13680 try {
13681 mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback);
13682 } finally {
13683 Binder.restoreCallingIdentity(identity);
13684 }
13685 }
13686
13687 /**
13688 * Unregisters for disallowed reasons change event from satellite service.
13689 * If callback was not registered before, the request will be ignored.
13690 *
13691 * @param callback The callback to handle disallowed reasons changed event.
13692 * {@link #registerForSatelliteDisallowedReasonsChanged(
13693 * ISatelliteDisallowedReasonsCallback)}.
13694 * @throws SecurityException if the caller doesn't have the required permission.
13695 */
13696 @Override
13697 public void unregisterForSatelliteDisallowedReasonsChanged(
13698 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13699 enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged");
13700 final long identity = Binder.clearCallingIdentity();
13701 try {
13702 mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback);
13703 } finally {
13704 Binder.restoreCallingIdentity(identity);
13705 }
13706 }
13707
13708 /**
Sarah Chindf715ec2023-02-13 13:46:24 -080013709 * Request to get whether satellite communication is allowed for the current location.
13710 *
13711 * @param subId The subId of the subscription to check whether satellite communication is
13712 * allowed for the current location for.
13713 * @param result The result receiver that returns whether satellite communication is allowed
13714 * for the current location if the request is successful or an error code
13715 * if the request failed.
13716 *
13717 * @throws SecurityException if the caller doesn't have the required permission.
13718 */
13719 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013720 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013721 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013722 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013723 final long identity = Binder.clearCallingIdentity();
13724 try {
13725 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13726 false);
13727 } finally {
13728 Binder.restoreCallingIdentity(identity);
13729 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013730 }
13731
13732 /**
youngtaechaedc8a1c2024-10-15 09:07:25 +000013733 * Request to get satellite access configuration for the current location.
13734 *
13735 * @param result The result receiver that returns the satellite access configuration
13736 * for the current location if the request is successful or an error code
13737 * if the request failed.
13738 *
13739 * @throws SecurityException if the caller doesn't have the required permission.
13740 */
13741 @Override
13742 public void requestSatelliteAccessConfigurationForCurrentLocation(
13743 @NonNull ResultReceiver result) {
13744 enforceSatelliteCommunicationPermission(
13745 "requestSatelliteAccessConfigurationForCurrentLocation");
13746 final long identity = Binder.clearCallingIdentity();
13747 try {
13748 mSatelliteAccessController
13749 .requestSatelliteAccessConfigurationForCurrentLocation(result);
13750 } finally {
13751 Binder.restoreCallingIdentity(identity);
13752 }
13753 }
13754
13755 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013756 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013757 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013758 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013759 * be visible if the request is successful or an error code if the request failed.
13760 *
13761 * @throws SecurityException if the caller doesn't have the required permission.
13762 */
13763 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013764 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013765 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013766 final long identity = Binder.clearCallingIdentity();
13767 try {
13768 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13769 } finally {
13770 Binder.restoreCallingIdentity(identity);
13771 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013772 }
13773
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013774 /**
Daniel Banta99cc7532024-11-15 02:31:08 +000013775 * Request to get the currently selected satellite subscription id.
13776 *
13777 * @param result The result receiver that returns the currently selected satellite subscription
13778 * id if the request is successful or an error code if the request failed.
13779 *
13780 * @throws SecurityException if the caller doesn't have the required permission.
13781 */
13782 @Override
13783 public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) {
13784 enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId");
13785 final long identity = Binder.clearCallingIdentity();
13786 try {
13787 mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result);
13788 } finally {
13789 Binder.restoreCallingIdentity(identity);
13790 }
13791 }
13792
13793 /**
Daniel Banta93320242024-11-21 00:34:41 +000013794 * Registers for selected satellite subscription changed event from the satellite service.
13795 *
13796 * @param callback The callback to handle the satellite subscription changed event.
13797 *
13798 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13799 *
13800 * @throws SecurityException if the caller doesn't have required permission.
13801 */
13802 @Override
13803 @SatelliteManager.SatelliteResult
13804 public int registerForSelectedNbIotSatelliteSubscriptionChanged(
13805 @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
13806 enforceSatelliteCommunicationPermission(
13807 "registerForSelectedNbIotSatelliteSubscriptionChanged");
13808 final long identity = Binder.clearCallingIdentity();
13809 try {
13810 return mSatelliteController.registerForSelectedNbIotSatelliteSubscriptionChanged(
13811 callback);
13812 } finally {
13813 Binder.restoreCallingIdentity(identity);
13814 }
13815 }
13816
13817 /**
13818 * Unregisters for selected satellite subscription changed event from the satellite service.
13819 * If callback was not registered before, the request will be ignored.
13820 *
13821 * @param callback The callback that was passed to {@link
13822 * #registerForSelectedNbIotSatelliteSubscriptionChanged(
13823 * ISelectedNbIotSatelliteSubscriptionCallback)}.
13824 *
13825 * @throws SecurityException if the caller doesn't have required permission.
13826 */
13827 @Override
13828 public void unregisterForSelectedNbIotSatelliteSubscriptionChanged(
13829 @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
13830 enforceSatelliteCommunicationPermission(
13831 "unregisterForSelectedNbIotSatelliteSubscriptionChanged");
13832 final long identity = Binder.clearCallingIdentity();
13833 try {
13834 mSatelliteController.unregisterForSelectedNbIotSatelliteSubscriptionChanged(
13835 callback);
13836 } finally {
13837 Binder.restoreCallingIdentity(identity);
13838 }
13839 }
13840
13841 /**
joonhunshin59104152024-09-11 09:55:35 +000013842 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013843 *
joonhunshin59104152024-09-11 09:55:35 +000013844 * @param isAligned {@code true} Device is aligned with the satellite.
13845 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013846 *
13847 * @throws SecurityException if the caller doesn't have required permission.
13848 */
13849 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13850
joonhunshin83da7cd2024-08-22 08:53:35 +000013851 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013852 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13853 final long identity = Binder.clearCallingIdentity();
13854 try {
13855 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13856 } finally {
13857 Binder.restoreCallingIdentity(identity);
13858 }
Hakjun Choiae365972023-04-25 11:00:31 +000013859 }
13860
13861 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013862 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13863 * by modem.
13864 *
13865 * @param subId The subId of the subscription to request for.
13866 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013867 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013868 * operation.
13869 *
13870 * @throws SecurityException if the caller doesn't have required permission.
13871 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013872 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013873 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13874 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013875 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013876 final long identity = Binder.clearCallingIdentity();
13877 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013878 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013879 } finally {
13880 Binder.restoreCallingIdentity(identity);
13881 }
13882 }
13883
13884 /**
13885 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13886 * by modem.
13887 *
13888 * @param subId The subId of the subscription to request for.
13889 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013890 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013891 * operation.
13892 *
13893 * @throws SecurityException if the caller doesn't have required permission.
13894 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013895 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013896 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13897 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013898 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013899 final long identity = Binder.clearCallingIdentity();
13900 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013901 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013902 } finally {
13903 Binder.restoreCallingIdentity(identity);
13904 }
13905 }
13906
13907 /**
13908 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013909 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013910 *
13911 * @param subId The subId of the subscription to request for.
13912 *
13913 * @return Integer array of reasons for disallowing satellite communication.
13914 *
13915 * @throws SecurityException if the caller doesn't have the required permission.
13916 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013917 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013918 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013919 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013920 final long identity = Binder.clearCallingIdentity();
13921 try {
13922 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013923 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013924 return reasonSet.stream().mapToInt(i->i).toArray();
13925 } finally {
13926 Binder.restoreCallingIdentity(identity);
13927 }
13928 }
13929
13930 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013931 * Request to get the signal strength of the satellite connection.
13932 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013933 * @param result Result receiver to get the error code of the request and the current signal
13934 * strength of the satellite connection.
13935 *
13936 * @throws SecurityException if the caller doesn't have required permission.
13937 */
13938 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013939 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013940 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13941 final long identity = Binder.clearCallingIdentity();
13942 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013943 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013944 } finally {
13945 Binder.restoreCallingIdentity(identity);
13946 }
13947 }
13948
13949 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013950 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13951 * is not successful, a {@link ServiceSpecificException} that contains
13952 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013953 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013954 * @param callback The callback to handle the NTN signal strength changed event. If the
13955 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13956 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13957 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13958 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013959 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013960 * @throws SecurityException If the caller doesn't have the required permission.
13961 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013962 */
13963 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013964 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013965 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013966 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13967 final long identity = Binder.clearCallingIdentity();
13968 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013969 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013970 } finally {
13971 Binder.restoreCallingIdentity(identity);
13972 }
13973 }
13974
13975 /**
13976 * Unregisters for NTN signal strength changed from satellite modem.
13977 * If callback was not registered before, the request will be ignored.
13978 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013979 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013980 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013981 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013982 *
13983 * @throws SecurityException if the caller doesn't have the required permission.
13984 */
13985 @Override
13986 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013987 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013988 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13989 final long identity = Binder.clearCallingIdentity();
13990 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013991 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013992 } finally {
13993 Binder.restoreCallingIdentity(identity);
13994 }
13995 }
13996
13997 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013998 * Registers for satellite capabilities change event from the satellite service.
13999 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014000 * @param callback The callback to handle the satellite capabilities changed event.
14001 *
14002 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14003 *
14004 * @throws SecurityException if the caller doesn't have required permission.
14005 */
14006 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014007 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014008 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014009 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000014010 final long identity = Binder.clearCallingIdentity();
14011 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014012 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000014013 } finally {
14014 Binder.restoreCallingIdentity(identity);
14015 }
14016 }
14017
14018 /**
14019 * Unregisters for satellite capabilities change event from the satellite service.
14020 * If callback was not registered before, the request will be ignored.
14021 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014022 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000014023 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000014024 *
14025 * @throws SecurityException if the caller doesn't have required permission.
14026 */
14027 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000014028 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014029 @NonNull ISatelliteCapabilitiesCallback callback) {
14030 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000014031 final long identity = Binder.clearCallingIdentity();
14032 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014033 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000014034 } finally {
14035 Binder.restoreCallingIdentity(identity);
14036 }
14037 }
14038
14039 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000014040 * Registers for the satellite supported state changed.
14041 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014042 * @param callback The callback to handle the satellite supported state changed event.
14043 *
14044 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14045 *
14046 * @throws SecurityException if the caller doesn't have the required permission.
14047 */
14048 @Override
14049 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014050 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014051 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014052 final long identity = Binder.clearCallingIdentity();
14053 try {
14054 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
14055 } finally {
14056 Binder.restoreCallingIdentity(identity);
14057 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014058 }
14059
14060 /**
14061 * Unregisters for the satellite supported state changed.
14062 * If callback was not registered before, the request will be ignored.
14063 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014064 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014065 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000014066 *
14067 * @throws SecurityException if the caller doesn't have the required permission.
14068 */
14069 @Override
14070 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014071 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014072 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014073 final long identity = Binder.clearCallingIdentity();
14074 try {
14075 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
14076 } finally {
14077 Binder.restoreCallingIdentity(identity);
14078 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014079 }
14080
14081 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014082 * This API can be used by only CTS to update satellite vendor service package name.
14083 *
14084 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000014085 * @param provisioned Whether satellite should be provisioned or not.
14086 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014087 * @return {@code true} if the satellite vendor service is set successfully,
14088 * {@code false} otherwise.
14089 */
Hakjun Choic3393242024-06-26 18:02:08 +000014090 public boolean setSatelliteServicePackageName(String servicePackageName,
14091 String provisioned) {
14092 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
14093 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014094 TelephonyPermissions.enforceShellOnly(
14095 Binder.getCallingUid(), "setSatelliteServicePackageName");
14096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14097 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14098 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014099 final long identity = Binder.clearCallingIdentity();
14100 try {
14101 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
14102 provisioned);
14103 } finally {
14104 Binder.restoreCallingIdentity(identity);
14105 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014106 }
14107
14108 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014109 * This API can be used by only CTS to update satellite gateway service package name.
14110 *
14111 * @param servicePackageName The package name of the satellite gateway service.
14112 * @return {@code true} if the satellite gateway service is set successfully,
14113 * {@code false} otherwise.
14114 */
14115 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
14116 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
14117 TelephonyPermissions.enforceShellOnly(
14118 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
14119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14120 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14121 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014122 final long identity = Binder.clearCallingIdentity();
14123 try {
14124 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
14125 } finally {
14126 Binder.restoreCallingIdentity(identity);
14127 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014128 }
14129
14130 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070014131 * This API can be used by only CTS to update satellite pointing UI app package and class names.
14132 *
14133 * @param packageName The package name of the satellite pointing UI app.
14134 * @param className The class name of the satellite pointing UI app.
14135 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
14136 * {@code false} otherwise.
14137 */
14138 public boolean setSatellitePointingUiClassName(
14139 @Nullable String packageName, @Nullable String className) {
14140 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
14141 + ", className=" + className);
14142 TelephonyPermissions.enforceShellOnly(
14143 Binder.getCallingUid(), "setSatellitePointingUiClassName");
14144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14145 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014146 "setSatellitePointingUiClassName");
14147 final long identity = Binder.clearCallingIdentity();
14148 try {
14149 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
14150 } finally {
14151 Binder.restoreCallingIdentity(identity);
14152 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070014153 }
14154
14155 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014156 * This API can be used by only CTS to update the timeout duration in milliseconds that
14157 * satellite should stay at listening mode to wait for the next incoming page before disabling
14158 * listening mode.
14159 *
14160 * @param timeoutMillis The timeout duration in millisecond.
14161 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14162 */
14163 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14164 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14165 TelephonyPermissions.enforceShellOnly(
14166 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14168 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14169 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014170 final long identity = Binder.clearCallingIdentity();
14171 try {
14172 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14173 } finally {
14174 Binder.restoreCallingIdentity(identity);
14175 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014176 }
14177
14178 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014179 * This API can be used by only CTS to control ingoring cellular service state event.
14180 *
14181 * @param enabled Whether to enable boolean config.
14182 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14183 */
14184 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014185 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014186 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014187 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14189 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014190 "setSatelliteIgnoreCellularServiceState");
14191 final long identity = Binder.clearCallingIdentity();
14192 try {
14193 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14194 } finally {
14195 Binder.restoreCallingIdentity(identity);
14196 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014197 }
14198
14199 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014200 * This API can be used by only CTS to override the timeout durations used by the
14201 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014202 *
14203 * @param timeoutMillis The timeout duration in millisecond.
14204 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14205 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014206 public boolean setDatagramControllerTimeoutDuration(
14207 boolean reset, int timeoutType, long timeoutMillis) {
14208 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14209 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014210 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014211 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14213 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014214 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014215 final long identity = Binder.clearCallingIdentity();
14216 try {
14217 return mSatelliteController.setDatagramControllerTimeoutDuration(
14218 reset, timeoutType, timeoutMillis);
14219 } finally {
14220 Binder.restoreCallingIdentity(identity);
14221 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014222 }
14223
14224 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014225 * This API can be used by only CTS to override the boolean configs used by the
14226 * DatagramController module.
14227 *
14228 * @param enable Whether to enable or disable boolean config.
14229 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14230 */
14231 public boolean setDatagramControllerBooleanConfig(
14232 boolean reset, int booleanType, boolean enable) {
14233 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14234 + ", reset=" + reset + ", enable=" + enable);
14235 TelephonyPermissions.enforceShellOnly(
14236 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14238 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14239 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014240 final long identity = Binder.clearCallingIdentity();
14241 try {
14242 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14243 enable);
14244 } finally {
14245 Binder.restoreCallingIdentity(identity);
14246 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014247 }
14248
14249
14250 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014251 * This API can be used by only CTS to override the timeout durations used by the
14252 * SatelliteController module.
14253 *
14254 * @param timeoutMillis The timeout duration in millisecond.
14255 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14256 */
14257 public boolean setSatelliteControllerTimeoutDuration(
14258 boolean reset, int timeoutType, long timeoutMillis) {
14259 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14260 + reset + ", timeoutMillis=" + timeoutMillis);
14261 TelephonyPermissions.enforceShellOnly(
14262 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14264 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14265 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014266 final long identity = Binder.clearCallingIdentity();
14267 try {
14268 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14269 reset, timeoutType, timeoutMillis);
14270 } finally {
14271 Binder.restoreCallingIdentity(identity);
14272 }
Hakjun Choiae365972023-04-25 11:00:31 +000014273 }
14274
14275 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014276 * This API can be used in only testing to override connectivity status in monitoring emergency
14277 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14278 *
14279 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14280 * of the following values to enable the override:
14281 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14282 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14283 * To disable the override, use -1 for handoverType.
14284 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14285 * delaySeconds after the emergency call starts.
14286 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14287 */
14288 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14289 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14290 TelephonyPermissions.enforceShellOnly(
14291 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14293 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14294 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014295 final long identity = Binder.clearCallingIdentity();
14296 try {
14297 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14298 handoverType, delaySeconds);
14299 } finally {
14300 Binder.restoreCallingIdentity(identity);
14301 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014302 }
14303
14304 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014305 * This API can be used in only testing to override oem-enabled satellite provision status.
14306 *
14307 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14308 * otherwise.
14309 * @param isProvisioned The overriding provision status.
14310 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14311 */
14312 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14313 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14314 + ", isProvisioned=" + isProvisioned);
14315 TelephonyPermissions.enforceShellOnly(
14316 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14318 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14319 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014320 final long identity = Binder.clearCallingIdentity();
14321 try {
14322 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14323 } finally {
14324 Binder.restoreCallingIdentity(identity);
14325 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014326 }
14327
14328 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014329 * This API should be used by only CTS tests to forcefully set telephony country codes.
14330 *
14331 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14332 */
14333 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14334 Map cachedNetworkCountryCodes, String locationCountryCode,
14335 long locationCountryCodeTimestampNanos) {
14336 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14337 + String.join(", ", currentNetworkCountryCodes)
14338 + ", locationCountryCode=" + locationCountryCode
14339 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14340 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14341 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014344 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14345 final long identity = Binder.clearCallingIdentity();
14346 try {
14347 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14348 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14349 cachedNetworkCountryCodes, locationCountryCode,
14350 locationCountryCodeTimestampNanos);
14351 } finally {
14352 Binder.restoreCallingIdentity(identity);
14353 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014354 }
14355
14356 /**
14357 * This API should be used by only CTS tests to override the overlay configs of satellite
14358 * access controller.
14359 *
14360 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14361 * otherwise.
14362 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14363 */
14364 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14365 String s2CellFile, long locationFreshDurationNanos,
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014366 List<String> satelliteCountryCodes, String satelliteAccessConfigurationFile) {
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014367 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14368 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14369 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14370 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014371 ? String.join(", ", satelliteCountryCodes) : null)
14372 + ", satelliteAccessConfigurationFile=" + satelliteAccessConfigurationFile);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014373 TelephonyPermissions.enforceShellOnly(
14374 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14376 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14377 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014378 final long identity = Binder.clearCallingIdentity();
14379 try {
14380 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014381 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes,
14382 satelliteAccessConfigurationFile);
Hyosun322782b2024-10-24 11:37:59 +000014383 } finally {
14384 Binder.restoreCallingIdentity(identity);
14385 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014386 }
14387
14388 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014389 * This API can be used by only CTS to override the cached value for the device overlay config
14390 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14391 * outgoing satellite datagrams should be sent to modem in demo mode.
14392 *
14393 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14394 * satellite modem or not.
14395 *
14396 * @return {@code true} if the operation is successful, {@code false} otherwise.
14397 */
14398 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14399 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14400 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14401 + "disabled");
14402 return false;
14403 }
14404 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14405 TelephonyPermissions.enforceShellOnly(
14406 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14408 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14409 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014410 final long identity = Binder.clearCallingIdentity();
14411 try {
14412 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14413 shouldSendToModemInDemoMode);
14414 } finally {
14415 Binder.restoreCallingIdentity(identity);
14416 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014417 }
14418
14419 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014420 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14421 *
14422 * @param state a state indicates whether satellite access allowed state should be cached and
14423 * the allowed state.
14424 * @return {@code true} if the setting is successful, {@code false} otherwise.
14425 */
14426 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14427 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14428 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14429 + "oemEnabledSatelliteFlag is disabled");
14430 return false;
14431 }
14432
14433 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14434 + "state=" + state);
14435 TelephonyPermissions.enforceShellOnly(
14436 Binder.getCallingUid(),
14437 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14439 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14440 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014441 final long identity = Binder.clearCallingIdentity();
14442 try {
14443 return mSatelliteAccessController
14444 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14445 } finally {
14446 Binder.restoreCallingIdentity(identity);
14447 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014448 }
14449
14450 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014451 * Sets the service defined in ComponentName to be bound.
14452 *
14453 * This should only be used for testing.
14454 * @return {@code true} if the DomainSelectionService to bind to was set,
14455 * {@code false} otherwise.
14456 */
14457 @Override
14458 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14459 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14460
14461 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14462 "setDomainSelectionServiceOverride");
14463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14464 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14465
14466 final long identity = Binder.clearCallingIdentity();
14467 try {
14468 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14469 return DomainSelectionResolver.getInstance()
14470 .setDomainSelectionServiceOverride(componentName);
14471 }
14472 } finally {
14473 Binder.restoreCallingIdentity(identity);
14474 }
14475 return false;
14476 }
14477
14478 /**
14479 * Clears the DomainSelectionService override.
14480 *
14481 * This should only be used for testing.
14482 * @return {@code true} if the DomainSelectionService override was cleared,
14483 * {@code false} otherwise.
14484 */
14485 @Override
14486 public boolean clearDomainSelectionServiceOverride() {
14487 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14488
14489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14490 "clearDomainSelectionServiceOverride");
14491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14492 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14493
14494 final long identity = Binder.clearCallingIdentity();
14495 try {
14496 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14497 return DomainSelectionResolver.getInstance()
14498 .clearDomainSelectionServiceOverride();
14499 }
14500 } finally {
14501 Binder.restoreCallingIdentity(identity);
14502 }
14503 return false;
14504 }
14505
14506 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014507 * Enable or disable notifications sent for cellular identifier disclosure events.
14508 *
14509 * Disclosure events are defined as instances where a device has sent a cellular identifier
14510 * on the Non-access stratum (NAS) before a security context is established. As a result the
14511 * identifier is sent in the clear, which has privacy implications for the user.
14512 *
14513 * @param enable if notifications about disclosure events should be enabled
14514 * @throws SecurityException if the caller does not have the required privileges
14515 * @throws UnsupportedOperationException if the modem does not support this feature.
14516 */
14517 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014518 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014519 enforceModifyPermission();
14520 checkForIdentifierDisclosureNotificationSupport();
14521
14522 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14523 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14524 editor.apply();
14525
14526 // Each phone instance is responsible for updating its respective modem immediately
14527 // after we've made a preference change.
14528 for (Phone phone : PhoneFactory.getPhones()) {
14529 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14530 }
14531 }
14532
14533 /**
14534 * Get whether or not cellular identifier disclosure notifications are enabled.
14535 *
14536 * @throws SecurityException if the caller does not have the required privileges
14537 * @throws UnsupportedOperationException if the modem does not support this feature.
14538 */
14539 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014540 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014541 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14542 checkForIdentifierDisclosureNotificationSupport();
14543 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14544 }
14545
14546 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014547 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14548 * are in use by the cellular modem.
14549 *
14550 * @throws IllegalStateException if the Telephony process is not currently available
14551 * @throws SecurityException if the caller does not have the required privileges
14552 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14553 * and integrity algorithms in use
14554 * @hide
14555 */
14556 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014557 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014558 enforceModifyPermission();
14559 checkForNullCipherNotificationSupport();
14560
14561 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14562 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14563 editor.apply();
14564
14565 // Each phone instance is responsible for updating its respective modem immediately
14566 // after a preference change.
14567 for (Phone phone : PhoneFactory.getPhones()) {
14568 phone.handleNullCipherNotificationPreferenceChanged();
14569 }
14570 }
14571
14572 /**
14573 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14574 * cellular modem.
14575 *
14576 * @throws IllegalStateException if the Telephony process is not currently available
14577 * @throws SecurityException if the caller does not have the required privileges
14578 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14579 * and integrity algorithms in use
14580 * @hide
14581 */
14582 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14583 public boolean isNullCipherNotificationsEnabled() {
14584 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14585 checkForNullCipherNotificationSupport();
14586 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14587 }
14588
14589 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014590 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14591 *
14592 * <p>This method behaves in one of the following ways:
14593 * <ul>
14594 * <li>return true : if the calling package has the appop permission {@link
14595 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14596 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14597 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14598 * Owner device identifier access check, or the calling package has carrier privileges</>
14599 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14600 * </ul>
14601 */
14602 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14603 String callingPackage, @Nullable String callingFeatureId, String message) {
14604 for (Phone phone : PhoneFactory.getPhones()) {
14605 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14606 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14607 return true;
14608 }
14609 }
14610 return false;
14611 }
arunvoddud7401012022-12-15 16:08:12 +000014612
14613 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014614 * @return The subscription manager service instance.
14615 */
14616 public SubscriptionManagerService getSubscriptionManagerService() {
14617 return SubscriptionManagerService.getInstance();
14618 }
14619
14620 /**
arunvoddud7401012022-12-15 16:08:12 +000014621 * Class binds the consumer[callback] and carrierId.
14622 */
14623 private static class CallerCallbackInfo {
14624 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014625 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014626
Steve Statia28b7cb32024-03-11 23:58:50 +000014627 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014628 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014629 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014630 }
14631
14632 public Consumer<Integer> getConsumer() {
14633 return mConsumer;
14634 }
14635
Steve Statia28b7cb32024-03-11 23:58:50 +000014636 public Set<Integer> getCarrierIds() {
14637 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014638 }
14639 }
joonhunshin4ac60942023-11-15 15:23:39 +000014640
14641 /*
14642 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14643 * But the context that is passed in is unused if the phone app is already alive.
14644 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14645 */
14646 @VisibleForTesting
14647 public void setPackageManager(PackageManager packageManager) {
14648 mPackageManager = packageManager;
14649 }
14650
14651 /*
Nate Myren453c3472024-03-13 11:28:11 -070014652 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14653 * But the context that is passed in is unused if the phone app is already alive.
14654 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14655 */
14656 @VisibleForTesting
14657 public void setAppOpsManager(AppOpsManager appOps) {
14658 mAppOps = appOps;
14659 }
14660
14661 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014662 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14663 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14664 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14665 */
14666 @VisibleForTesting
14667 public void setFeatureFlags(FeatureFlags featureFlags) {
14668 mFeatureFlags = featureFlags;
14669 }
14670
14671 /**
14672 * Make sure the device has required telephony feature
14673 *
14674 * @throws UnsupportedOperationException if the device does not have required telephony feature
14675 */
14676 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14677 @NonNull String telephonyFeature, @NonNull String methodName) {
14678 if (callingPackage == null || mPackageManager == null) {
14679 return;
14680 }
14681
14682 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14683 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014684 Binder.getCallingUserHandle())
14685 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14686 // Skip to check associated telephony feature,
14687 // if compatibility change is not enabled for the current process or
14688 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014689 return;
14690 }
14691
14692 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14693 throw new UnsupportedOperationException(
14694 methodName + " is unsupported without " + telephonyFeature);
14695 }
14696 }
youngtaecha5d483d52024-04-29 17:05:45 +000014697
14698 /**
14699 * Registers for the satellite communication allowed state changed.
14700 *
14701 * @param subId The subId of the subscription to register for the satellite communication
14702 * allowed state changed.
14703 * @param callback The callback to handle the satellite communication allowed
14704 * state changed event.
14705 *
14706 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14707 *
14708 * @throws SecurityException if the caller doesn't have the required permission.
14709 */
14710 @Override
14711 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14712 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14713 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014714 final long identity = Binder.clearCallingIdentity();
14715 try {
14716 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14717 subId, callback);
14718 } finally {
14719 Binder.restoreCallingIdentity(identity);
14720 }
youngtaecha5d483d52024-04-29 17:05:45 +000014721 }
14722
14723 /**
14724 * Unregisters for the satellite communication allowed state changed.
14725 * If callback was not registered before, the request will be ignored.
14726 *
14727 * @param subId The subId of the subscription to unregister for the satellite communication
14728 * allowed state changed.
14729 * @param callback The callback that was passed to
14730 * {@link #registerForCommunicationAllowedStateChanged(int,
14731 * ISatelliteCommunicationAllowedStateCallback)}. *
14732 * @throws SecurityException if the caller doesn't have the required permission.
14733 */
14734 @Override
14735 public void unregisterForCommunicationAllowedStateChanged(
14736 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14737 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014738 final long identity = Binder.clearCallingIdentity();
14739 try {
14740 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14741 callback);
14742 } finally {
14743 Binder.restoreCallingIdentity(identity);
14744 }
youngtaecha5d483d52024-04-29 17:05:45 +000014745 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014746
14747 /**
14748 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14749 *
14750 * @param subId The subId of the subscription to the satellite session stats for.
14751 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14752 * if the request is successful or an error code if the request failed.
14753 *
14754 * @throws SecurityException if the caller doesn't have required permission.
14755 */
14756 @Override
14757 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14758 enforceModifyPermission();
14759 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014760 final long identity = Binder.clearCallingIdentity();
14761 try {
14762 mSatelliteController.requestSatelliteSessionStats(subId, result);
14763 } finally {
14764 Binder.restoreCallingIdentity(identity);
14765 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014766 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014767
14768 /**
14769 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14770 *
14771 * @param result The result receiver, which returns the list of prioritized satellite tokens
14772 * to be used for provision if the request is successful or an error code if the request failed.
14773 *
14774 * @throws SecurityException if the caller doesn't have the required permission.
14775 */
14776 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014777 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14778 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014779 final long identity = Binder.clearCallingIdentity();
14780 try {
14781 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14782 } finally {
14783 Binder.restoreCallingIdentity(identity);
14784 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014785 }
14786
14787 /**
14788 * Deliver the list of provisioned satellite subscriber ids.
14789 *
14790 * @param list List of provisioned satellite subscriber ids.
14791 * @param result The result receiver that returns whether deliver success or fail.
14792 *
14793 * @throws SecurityException if the caller doesn't have the required permission.
14794 */
14795 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014796 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014797 @NonNull ResultReceiver result) {
14798 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014799 final long identity = Binder.clearCallingIdentity();
14800 try {
14801 mSatelliteController.provisionSatellite(list, result);
14802 } finally {
14803 Binder.restoreCallingIdentity(identity);
14804 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014805 }
Hyosund6aaf062024-08-23 23:02:10 +000014806
14807 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014808 * Deliver the list of deprovisioned satellite subscriber ids.
14809 *
14810 * @param list List of deprovisioned satellite subscriber ids.
14811 * @param result The result receiver that returns whether deliver success or fail.
14812 *
14813 * @throws SecurityException if the caller doesn't have the required permission.
14814 */
14815 @Override
14816 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14817 @NonNull ResultReceiver result) {
14818 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14819 final long identity = Binder.clearCallingIdentity();
14820 try {
14821 mSatelliteController.deprovisionSatellite(list, result);
14822 } finally {
14823 Binder.restoreCallingIdentity(identity);
14824 }
14825 }
14826
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014827
14828 /**
14829 * Inform whether application supports NTN SMS in satellite mode.
14830 *
14831 * This method is used by default messaging application to inform framework whether it supports
14832 * NTN SMS or not.
14833 *
14834 * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}.
14835 *
14836 * @throws SecurityException if the caller doesn't have required permission.
14837 */
14838 @Override
14839 public void setNtnSmsSupported(boolean ntnSmsSupported) {
14840 enforceSatelliteCommunicationPermission("setNtnSmsSupported");
14841 enforceSendSmsPermission();
14842 mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
14843 }
14844
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014845 /**
Hyosund6aaf062024-08-23 23:02:10 +000014846 * This API can be used by only CTS to override the cached value for the device overlay config
14847 * value :
14848 * config_satellite_gateway_service_package and
14849 * config_satellite_carrier_roaming_esos_provisioned_class.
14850 * These values are set before sending an intent to broadcast there are any change to list of
14851 * subscriber informations.
14852 *
14853 * @param name the name is one of the following that constitute an intent.
14854 * Component package name, or component class name.
14855 * @return {@code true} if the setting is successful, {@code false} otherwise.
14856 */
14857 @Override
14858 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14859 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14860 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14861 + " carrierRoamingNbIotNtn is disabled");
14862 return false;
14863 }
14864 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14865 TelephonyPermissions.enforceShellOnly(
14866 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14868 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14869 "setSatelliteSubscriberIdListChangedIntentComponent");
14870 final long identity = Binder.clearCallingIdentity();
14871 try {
14872 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14873 } finally {
14874 Binder.restoreCallingIdentity(identity);
14875 }
14876 }
Jack Yu26735292024-09-25 14:33:49 -070014877
14878 /**
14879 * This API can be used by only CTS to override the Euicc UI component.
14880 *
14881 * @param componentName ui component to be launched for testing. {@code null} to reset.
14882 *
14883 * @hide
14884 */
14885 @Override
14886 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14887 enforceModifyPermission();
14888 log("setTestEuiccUiComponent: " + componentName);
14889 mTestEuiccUiComponent = componentName;
14890 }
14891
14892 /**
14893 * This API can be used by only CTS to retrieve the Euicc UI component.
14894 *
14895 * @return Euicc UI component. {@code null} if not available.
14896 * @hide
14897 */
14898 @Override
14899 @Nullable
14900 public ComponentName getTestEuiccUiComponent() {
14901 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14902 return mTestEuiccUiComponent;
14903 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014904
14905 /**
14906 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14907 *
14908 * @param state to update Ntn Eligibility.
14909 * @param resetRequired to reset the overridden flag in satellite controller.
14910 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14911 */
14912 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14913 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014914 final long identity = Binder.clearCallingIdentity();
14915 try {
14916 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14917 resetRequired);
14918 } finally {
14919 Binder.restoreCallingIdentity(identity);
14920 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014921 }
jinjeongc29c54e2024-11-15 08:11:18 +000014922
14923 /**
14924 * Returns carrier id maps to the passing {@link CarrierIdentifier}.
14925 *
14926 * @param carrierIdentifier {@link CarrierIdentifier}.
14927 *
14928 * @return carrier id from passing {@link CarrierIdentifier} or UNKNOWN_CARRIER_ID
14929 * if the carrier cannot be identified
14930 */
14931 public int getCarrierIdFromIdentifier(@NonNull CarrierIdentifier carrierIdentifier) {
14932 enforceReadPrivilegedPermission("getCarrierIdFromIdentifier");
14933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
14934 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromIdentifier");
14935
14936 final long identity = Binder.clearCallingIdentity();
14937 try {
14938 return CarrierResolver.getCarrierIdFromIdentifier(mApp, carrierIdentifier);
14939 } finally {
14940 Binder.restoreCallingIdentity(identity);
14941 }
14942 }
Jack Yufa8ed012023-02-11 15:42:28 -080014943}