blob: d5ae671d13afd499198681f9cfbced9dea311731 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
28import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080029
Shuo Qianccbaf742021-02-22 18:32:21 -080030import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
31import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070032import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070033import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000034import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070035
Brad Ebinger34c09a52021-02-17 23:23:21 +000036import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080037import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080038import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070039import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080041import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080043import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070044import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000045import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080046import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000047import android.compat.annotation.ChangeId;
48import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000049import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070050import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070051import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.content.Context;
53import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070055import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070056import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.net.Uri;
58import android.os.AsyncResult;
59import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080060import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080062import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070064import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080065import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080066import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.Looper;
68import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070069import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080070import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070071import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080073import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080074import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070075import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070076import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080077import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000078import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000159import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000161import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800162import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000163import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800164import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000165import android.telephony.satellite.NtnSignalStrength;
166import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800167import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000168import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800169import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800170import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteProvisionStateCallback;
Hyosun Kimb11f3ea2024-08-07 23:35:59 +0000172import android.telephony.satellite.SatelliteSubscriberInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700175import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800177import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Andrew Lee312e8172014-10-23 17:01:36 -0700179import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800180import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800181import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800182import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800183import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700185import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700186import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800187import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800188import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800191import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700192import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800193import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800194import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000197import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800199import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800202import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800203import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700205import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700208import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800209import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700210import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700211import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700212import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700213import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800214import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800215import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700216import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700218import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700219import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800220import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800221import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700223import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000224import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700226import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700227import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800228import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700229import com.android.internal.telephony.imsphone.ImsPhone;
230import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000231import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800232import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000233import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800234import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
235import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700236import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237import com.android.internal.telephony.uicc.IccIoResult;
238import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700240import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800244import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800246import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000247import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700248import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700249import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800250import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800251import com.android.phone.callcomposer.CallComposerPictureManager;
252import com.android.phone.callcomposer.CallComposerPictureTransfer;
253import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800254import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000255import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700256import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700257import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000258import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800260import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700262import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800263import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800264import com.android.services.telephony.TelecomAccountRegistry;
265import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000266import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800267import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800268
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.IOException;
272import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700273import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000276import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800277import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800278import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800280import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100281import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800285import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700286import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800287import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800288import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800289import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291/**
292 * Implementation of the ITelephony interface.
293 */
Santos Cordon117fee72014-05-16 17:56:12 -0700294public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 private static final String LOG_TAG = "PhoneInterfaceManager";
296 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
297 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800298 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
300 // Message codes used with mMainThreadHandler
301 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
303 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 private static final int CMD_OPEN_CHANNEL = 9;
305 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
306 private static final int CMD_CLOSE_CHANNEL = 11;
307 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800308 private static final int CMD_NV_READ_ITEM = 13;
309 private static final int EVENT_NV_READ_ITEM_DONE = 14;
310 private static final int CMD_NV_WRITE_ITEM = 15;
311 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
312 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
313 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_RESET_MODEM_CONFIG = 19;
315 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800316 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
317 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800318 private static final int CMD_SEND_ENVELOPE = 25;
319 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700320 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
321 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
322 private static final int CMD_EXCHANGE_SIM_IO = 31;
323 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
325 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700326 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700328 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
329 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700330 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
331 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
332 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
333 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700334 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
335 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
336 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
337 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700338 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800339 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
340 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000341 private static final int CMD_SWITCH_SLOTS = 50;
342 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700343 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
344 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
345 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
346 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
347 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
348 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
349 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
350 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700351 private static final int CMD_GET_ALL_CELL_INFO = 60;
352 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
353 private static final int CMD_GET_CELL_LOCATION = 62;
354 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700355 private static final int CMD_MODEM_REBOOT = 64;
356 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700357 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
358 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800359 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
360 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700361 private static final int CMD_GET_MODEM_STATUS = 70;
362 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700363 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
364 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700365 private static final int CMD_ERASE_MODEM_CONFIG = 74;
366 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800367 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
368 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
369 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
370 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800371 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
372 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800374 private static final int CMD_GET_CALL_FORWARDING = 83;
375 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
376 private static final int CMD_SET_CALL_FORWARDING = 85;
377 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
378 private static final int CMD_GET_CALL_WAITING = 87;
379 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
380 private static final int CMD_SET_CALL_WAITING = 89;
381 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700382 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
383 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
384 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
385 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700386 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
387 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800388 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
389 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int CMD_SET_DATA_THROTTLING = 99;
391 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800392 private static final int CMD_SET_SIM_POWER = 101;
393 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800394 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
395 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
396 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
397 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800398 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
399 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000400 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800401 private static final int CMD_GET_SLICING_CONFIG = 110;
402 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800403 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700404 private static final int CMD_ENABLE_VONR = 113;
405 private static final int EVENT_ENABLE_VONR_DONE = 114;
406 private static final int CMD_IS_VONR_ENABLED = 115;
407 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700408 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
409 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000419 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
420 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600421 // Null cipher notification support was added in IRadioNetwork 2.2
422 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /** The singleton instance. */
425 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800426 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000429 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800430 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final CallManager mCM;
432 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000433
434 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800435 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final SharedPreferences mTelephonySharedPreferences;
439 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800440 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700441 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000442 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000443 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800448 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449
Derek Tan97ebb422014-09-05 16:55:38 -0700450 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
451 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800452 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800453 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700454
Michelecea4cf22018-12-21 15:00:11 -0800455 // String to store multi SIM allowed
456 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
457
Derek Tan740e1672017-06-27 14:56:27 -0700458 // The AID of ISD-R.
459 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
460
yinxub1bed742017-04-17 11:45:04 -0700461 private NetworkScanRequestTracker mNetworkScanRequestTracker;
462
David Kelly5e06a7f2018-03-12 14:10:59 +0000463 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
464 private static final int MANUFACTURER_CODE_LENGTH = 8;
465
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800467 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800468
Sarah Chin2ec39f62022-08-31 17:03:26 -0700469 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
470 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
471
Derek Tan89e89d42014-07-08 17:00:10 -0700472 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 * Experiment flag to enable erase modem config on reset network, default value is false
474 */
475 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
476 "reset_network_erase_modem_config_enabled";
477
Rambo Wang0f050d82021-02-12 11:43:36 -0800478 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800479
Gary Jian76280a42022-12-07 16:18:33 +0800480 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
481
arunvoddub1365e62024-07-31 09:42:31 +0000482 private static final int LINE1_NUMBER_MAX_LEN = 50;
483
sandeepjsb6c87872021-09-27 15:34:44 +0000484 /**
485 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
486 * one ICCID active at the same time.
487 * Apps should use below API signatures if targeting SDK is T and beyond.
488 *
489 * @hide
490 */
491 @ChangeId
492 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
493 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800494
Naina Nallurid63128d2019-09-17 14:10:30 -0700495 /**
Chen Xu540470b2021-12-14 17:15:47 -0800496 * Apps targeting on Android T and beyond will get exception whenever icc close channel
497 * operation fails.
498 */
499 @ChangeId
500 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
501 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
502
503 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 * A request object to use for transmitting data to an ICC.
505 */
506 private static final class IccAPDUArgument {
507 public int channel, cla, command, p1, p2, p3;
508 public String data;
509
510 public IccAPDUArgument(int channel, int cla, int command,
511 int p1, int p2, int p3, String data) {
512 this.channel = channel;
513 this.cla = cla;
514 this.command = command;
515 this.p1 = p1;
516 this.p2 = p2;
517 this.p3 = p3;
518 this.data = data;
519 }
520 }
521
522 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700523 * A request object to use for transmitting data to an ICC.
524 */
525 private static final class ManualNetworkSelectionArgument {
526 public OperatorInfo operatorInfo;
527 public boolean persistSelection;
528
529 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
530 this.operatorInfo = operatorInfo;
531 this.persistSelection = persistSelection;
532 }
533 }
534
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 private static final class PurchasePremiumCapabilityArgument {
536 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700537 public @NonNull IIntegerConsumer callback;
538
539 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800540 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700542 this.callback = callback;
543 }
544 }
545
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700546 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
548 * request after sending. The main thread will notify the request when it is complete.
549 */
550 private static final class MainThreadRequest {
551 /** The argument to use for the request */
552 public Object argument;
553 /** The result of the request that is run on the main thread */
554 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800555 // The subscriber id that this request applies to. Defaults to
556 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
557 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558
Nathan Harold92bed182018-10-12 18:16:49 -0700559 // In cases where subId is unavailable, the caller needs to specify the phone.
560 public Phone phone;
561
vagdeviaf9a5b92018-08-15 16:01:53 -0700562 public WorkSource workSource;
563
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 public MainThreadRequest(Object argument) {
565 this.argument = argument;
566 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800567
Nathan Harold92bed182018-10-12 18:16:49 -0700568 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
569 this.argument = argument;
570 if (phone != null) {
571 this.phone = phone;
572 }
573 this.workSource = workSource;
574 }
575
vagdeviaf9a5b92018-08-15 16:01:53 -0700576 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800577 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800578 if (subId != null) {
579 this.subId = subId;
580 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700581 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 }
584
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800585 private static final class IncomingThirdPartyCallArgs {
586 public final ComponentName component;
587 public final String callId;
588 public final String callerDisplayName;
589
590 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
591 String callerDisplayName) {
592 this.component = component;
593 this.callId = callId;
594 this.callerDisplayName = callerDisplayName;
595 }
596 }
597
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598 /**
599 * A handler that processes messages on the main thread in the phone process. Since many
600 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
601 * inbound binder threads to the main thread in the phone process. The Binder thread
602 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
603 * on, which will be notified when the operation completes and will contain the result of the
604 * request.
605 *
606 * <p>If a MainThreadRequest object is provided in the msg.obj field,
607 * note that request.result must be set to something non-null for the calling thread to
608 * unblock.
609 */
610 private final class MainThreadHandler extends Handler {
611 @Override
612 public void handleMessage(Message msg) {
613 MainThreadRequest request;
614 Message onCompleted;
615 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000616 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800618 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619
620 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 case CMD_HANDLE_USSD_REQUEST: {
622 request = (MainThreadRequest) msg.obj;
623 final Phone phone = getPhoneFromRequest(request);
624 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800625 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700627
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 if (!isUssdApiAllowed(request.subId)) {
629 // Carrier does not support use of this API, return failure.
630 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
631 UssdResponse response = new UssdResponse(ussdRequest, null);
632 Bundle returnData = new Bundle();
633 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
634 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700635
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 request.result = true;
637 notifyRequester(request);
638 return;
639 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700640
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 try {
642 request.result = phone != null
643 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
644 } catch (CallStateException cse) {
645 request.result = false;
646 }
647 // Wake up the requesting thread
648 notifyRequester(request);
649 break;
pkanwar32d516d2016-10-14 19:37:38 -0700650 }
651
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700654 final Phone phone = getPhoneFromRequest(request);
655 request.result = phone != null ?
656 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
657 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000666 uiccPort = getUiccPortFromRequest(request);
667 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800669 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800673 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000674 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800675 iccArgument.channel, iccArgument.cla, iccArgument.command,
676 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
677 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 ar = (AsyncResult) msg.obj;
683 request = (MainThreadRequest) ar.userObj;
684 if (ar.exception == null && ar.result != null) {
685 request.result = ar.result;
686 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 if (ar.result == null) {
689 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800690 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800692 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 } else {
694 loge("iccTransmitApduLogicalChannel: Unknown exception");
695 }
696 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700697 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 break;
699
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
701 request = (MainThreadRequest) msg.obj;
702 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000703 uiccPort = getUiccPortFromRequest(request);
704 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 } else {
709 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800710 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800712 iccArgument.cla, iccArgument.command, iccArgument.p1,
713 iccArgument.p2,
714 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 }
716 break;
717
718 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
719 ar = (AsyncResult) msg.obj;
720 request = (MainThreadRequest) ar.userObj;
721 if (ar.exception == null && ar.result != null) {
722 request.result = ar.result;
723 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800724 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 if (ar.result == null) {
726 loge("iccTransmitApduBasicChannel: Empty response");
727 } else if (ar.exception instanceof CommandException) {
728 loge("iccTransmitApduBasicChannel: CommandException: " +
729 ar.exception);
730 } else {
731 loge("iccTransmitApduBasicChannel: Unknown exception");
732 }
733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 break;
736
737 case CMD_EXCHANGE_SIM_IO:
738 request = (MainThreadRequest) msg.obj;
739 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000740 uiccPort = getUiccPortFromRequest(request);
741 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800743 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700745 } else {
746 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
747 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000748 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700749 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
750 iccArgument.data, onCompleted);
751 }
752 break;
753
754 case EVENT_EXCHANGE_SIM_IO_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result;
759 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800760 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 break;
764
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 case CMD_SEND_ENVELOPE:
766 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000767 uiccPort = getUiccPortFromRequest(request);
768 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800770 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 } else {
773 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800774 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 break;
777
778 case EVENT_SEND_ENVELOPE_DONE:
779 ar = (AsyncResult) msg.obj;
780 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700781 if (ar.exception == null && ar.result != null) {
782 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800783 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800784 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700785 if (ar.result == null) {
786 loge("sendEnvelopeWithStatus: Empty response");
787 } else if (ar.exception instanceof CommandException) {
788 loge("sendEnvelopeWithStatus: CommandException: " +
789 ar.exception);
790 } else {
791 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
792 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800793 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700794 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800795 break;
796
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 case CMD_OPEN_CHANNEL:
798 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000799 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800800 IccLogicalChannelRequest openChannelRequest =
801 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000802 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800804 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800805 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700806 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700807 } else {
808 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800809 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
810 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 break;
813
814 case EVENT_OPEN_CHANNEL_DONE:
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700818 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700819 int[] result = (int[]) ar.result;
820 int channelId = result[0];
821 byte[] selectResponse = null;
822 if (result.length > 1) {
823 selectResponse = new byte[result.length - 1];
824 for (int i = 1; i < result.length; ++i) {
825 selectResponse[i - 1] = (byte) result[i];
826 }
827 }
828 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800829 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800830
831 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700832 if (uiccPort == null) {
833 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
834 } else {
835 IccLogicalChannelRequest channelRequest =
836 (IccLogicalChannelRequest) request.argument;
837 channelRequest.channel = channelId;
838 uiccPort.onLogicalChannelOpened(channelRequest);
839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700840 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 if (ar.result == null) {
842 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700844 if (ar.exception != null) {
845 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
846 }
847
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700848 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700849 if (ar.exception instanceof CommandException) {
850 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800851 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700852 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700854 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700855 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700856 }
857 }
858 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800859 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700861 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700862 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 break;
864
865 case CMD_CLOSE_CHANNEL:
866 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000867 uiccPort = getUiccPortFromRequest(request);
868 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700869 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800870 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800871 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800872 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700873 } else {
874 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000875 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700876 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 break;
878
879 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null) {
883 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800884 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700885 if (uiccPort == null) {
886 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
887 } else {
888 final int channelId = (Integer) request.argument;
889 uiccPort.onLogicalChannelClosed(channelId);
890 }
Chen Xu540470b2021-12-14 17:15:47 -0800891 } else {
892 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800893 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800894 if (ar.exception instanceof CommandException) {
895 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
896 CommandException.Error error =
897 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800898 if (error == CommandException.Error.INVALID_ARGUMENTS) {
899 // should only throw exceptions from the binder threads.
900 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800901 "iccCloseLogicalChannel: invalid argument ");
902 }
903 } else {
904 loge("iccCloseLogicalChannel: Unknown exception");
905 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800906 request.result = (exception != null) ? exception :
907 new IllegalStateException(
908 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800909 }
910 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
913 case CMD_NV_READ_ITEM:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
917 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800918 break;
919
920 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700921 ar = (AsyncResult) msg.obj;
922 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800923 if (ar.exception == null && ar.result != null) {
924 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800926 request.result = "";
927 if (ar.result == null) {
928 loge("nvReadItem: Empty response");
929 } else if (ar.exception instanceof CommandException) {
930 loge("nvReadItem: CommandException: " +
931 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800933 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700934 }
935 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700936 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700937 break;
938
Jake Hambye994d462014-02-03 13:10:13 -0800939 case CMD_NV_WRITE_ITEM:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
942 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800943 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700944 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
947 case EVENT_NV_WRITE_ITEM_DONE:
948 handleNullReturnEvent(msg, "nvWriteItem");
949 break;
950
951 case CMD_NV_WRITE_CDMA_PRL:
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800954 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800955 break;
956
957 case EVENT_NV_WRITE_CDMA_PRL_DONE:
958 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
959 break;
960
chen xu6dac5ab2018-10-26 17:39:23 -0700961 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800962 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700963 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800964 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800965 break;
966
chen xu6dac5ab2018-10-26 17:39:23 -0700967 case EVENT_RESET_MODEM_CONFIG_DONE:
968 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800969 break;
970
Sooraj Sasindran37444802020-08-11 10:40:43 -0700971 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
974 request);
975 Phone phone = getPhoneFromRequest(request);
976 if (phone != null) {
977 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
978 } else {
979 loge("isNRDualConnectivityEnabled: No phone object");
980 request.result = false;
981 notifyRequester(request);
982 }
983 break;
984 }
985
986 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 if (ar.exception == null && ar.result != null) {
990 request.result = ar.result;
991 } else {
992 // request.result must be set to something non-null
993 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700994 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700995 request.result = ar.result;
996 } else {
997 request.result = false;
998 }
999 if (ar.result == null) {
1000 loge("isNRDualConnectivityEnabled: Empty response");
1001 } else if (ar.exception instanceof CommandException) {
1002 loge("isNRDualConnectivityEnabled: CommandException: "
1003 + ar.exception);
1004 } else {
1005 loge("isNRDualConnectivityEnabled: Unknown exception");
1006 }
1007 }
1008 notifyRequester(request);
1009 break;
1010
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001011 case CMD_IS_VONR_ENABLED: {
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1014 request);
1015 Phone phone = getPhoneFromRequest(request);
1016 if (phone != null) {
1017 phone.isVoNrEnabled(onCompleted, request.workSource);
1018 } else {
1019 loge("isVoNrEnabled: No phone object");
1020 request.result = false;
1021 notifyRequester(request);
1022 }
1023 break;
1024 }
1025
1026 case EVENT_IS_VONR_ENABLED_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception == null && ar.result != null) {
1030 request.result = ar.result;
1031 } else {
1032 // request.result must be set to something non-null
1033 // for the calling thread to unblock
1034 if (ar.result != null) {
1035 request.result = ar.result;
1036 } else {
1037 request.result = false;
1038 }
1039 if (ar.result == null) {
1040 loge("isVoNrEnabled: Empty response");
1041 } else if (ar.exception instanceof CommandException) {
1042 loge("isVoNrEnabled: CommandException: "
1043 + ar.exception);
1044 } else {
1045 loge("isVoNrEnabled: Unknown exception");
1046 }
1047 }
1048 notifyRequester(request);
1049 break;
1050
Sooraj Sasindran37444802020-08-11 10:40:43 -07001051 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1054 Phone phone = getPhoneFromRequest(request);
1055 if (phone != null) {
1056 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1057 request.workSource);
1058 } else {
1059 loge("enableNrDualConnectivity: No phone object");
1060 request.result =
1061 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1062 notifyRequester(request);
1063 }
1064 break;
1065 }
1066
1067 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
1070 if (ar.exception == null) {
1071 request.result =
1072 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1073 } else {
1074 request.result =
1075 TelephonyManager
1076 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1077 if (ar.exception instanceof CommandException) {
1078 CommandException.Error error =
1079 ((CommandException) (ar.exception)).getCommandError();
1080 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1081 request.result =
1082 TelephonyManager
1083 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001084 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1085 request.result =
1086 TelephonyManager
1087 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001088 }
1089 loge("enableNrDualConnectivity" + ": CommandException: "
1090 + ar.exception);
1091 } else {
1092 loge("enableNrDualConnectivity" + ": Unknown exception");
1093 }
1094 }
1095 notifyRequester(request);
1096 break;
1097 }
1098
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001099 case CMD_ENABLE_VONR: {
1100 request = (MainThreadRequest) msg.obj;
1101 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1102 Phone phone = getPhoneFromRequest(request);
1103 if (phone != null) {
1104 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1105 request.workSource);
1106 } else {
1107 loge("setVoNrEnabled: No phone object");
1108 request.result =
1109 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1110 notifyRequester(request);
1111 }
1112 break;
1113 }
1114
1115 case EVENT_ENABLE_VONR_DONE: {
1116 ar = (AsyncResult) msg.obj;
1117 request = (MainThreadRequest) ar.userObj;
1118 if (ar.exception == null) {
1119 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1120 } else {
1121 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1126 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1128 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1129 } else {
1130 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1131 }
1132 loge("setVoNrEnabled" + ": CommandException: "
1133 + ar.exception);
1134 } else {
1135 loge("setVoNrEnabled" + ": Unknown exception");
1136 }
1137 }
1138 notifyRequester(request);
1139 break;
1140 }
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1145 request);
1146 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 break;
1148
SongFerngWang3ef3e072020-12-21 16:41:52 +08001149 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 if (ar.exception == null && ar.result != null) {
1153 request.result = ar.result; // Integer
1154 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301155 // request.result must be set to something non-null
1156 // for the calling thread to unblock
1157 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001161 loge("getAllowedNetworkTypesBitmask: CommandException: "
1162 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001165 }
1166 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 break;
1169
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001172 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1173 request);
1174 Pair<Integer, Long> reasonWithNetworkTypes =
1175 (Pair<Integer, Long>) request.argument;
1176 getPhoneFromRequest(request).setAllowedNetworkTypes(
1177 reasonWithNetworkTypes.first,
1178 reasonWithNetworkTypes.second,
1179 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001180 break;
1181
SongFerngWang3ef3e072020-12-21 16:41:52 +08001182 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1183 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001184 break;
1185
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001186 case CMD_SET_VOICEMAIL_NUMBER:
1187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1189 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001190 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1191 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001192 break;
1193
1194 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1195 handleNullReturnEvent(msg, "setVoicemailNumber");
1196 break;
1197
Stuart Scott54788802015-03-30 13:18:01 -07001198 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1199 request = (MainThreadRequest) msg.obj;
1200 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1201 request);
1202 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1203 break;
1204
1205 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1206 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1207 break;
1208
Shishir Agrawal302c8692015-06-19 13:49:39 -07001209 case CMD_PERFORM_NETWORK_SCAN:
1210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1212 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1213 break;
1214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001218 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1219 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1220 request.argument;
1221 int callForwardingReason = args.first;
1222 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 break;
Hall Liu27d24262020-09-18 19:04:59 -07001224 }
1225 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001226 ar = (AsyncResult) msg.obj;
1227 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001228 TelephonyManager.CallForwardingInfoCallback callback =
1229 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1230 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001232 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001233 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1234 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1235 // Service Class is a bit mask per 3gpp 27.007. Search for
1236 // any service for voice call.
1237 if ((callForwardInfo.serviceClass
1238 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001239 callForwardingInfo = new CallForwardingInfo(
1240 callForwardInfo.status
1241 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001242 callForwardInfo.reason,
1243 callForwardInfo.number,
1244 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
1246 }
1247 }
1248 // Didn't find a call forward info for voice call.
1249 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001250 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1251 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 }
Hall Liu27d24262020-09-18 19:04:59 -07001253 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001254 } else {
1255 if (ar.result == null) {
1256 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1257 }
1258 if (ar.exception != null) {
1259 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1260 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 int errorCode = TelephonyManager
1262 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 if (ar.exception instanceof CommandException) {
1264 CommandException.Error error =
1265 ((CommandException) (ar.exception)).getCommandError();
1266 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001267 errorCode = TelephonyManager
1268 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001269 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager
1271 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 }
1273 }
Hall Liu27d24262020-09-18 19:04:59 -07001274 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276 break;
Hall Liu27d24262020-09-18 19:04:59 -07001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278
Hall Liu27d24262020-09-18 19:04:59 -07001279 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001280 request = (MainThreadRequest) msg.obj;
1281 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001282 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001284 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1285 request.argument).first;
1286 request.phone.setCallForwardingOption(
1287 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001288 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001289 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001290 callForwardingInfoToSet.getReason(),
1291 callForwardingInfoToSet.getNumber(),
1292 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001299 Consumer<Integer> callback =
1300 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1301 request.argument).second;
1302 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 int errorCode = TelephonyManager.CallForwardingInfoCallback
1305 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001306 if (ar.exception instanceof CommandException) {
1307 CommandException.Error error =
1308 ((CommandException) (ar.exception)).getCommandError();
1309 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001310 errorCode = TelephonyManager.CallForwardingInfoCallback
1311 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001312 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001313 errorCode = TelephonyManager.CallForwardingInfoCallback
1314 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
1316 }
1317 callback.accept(errorCode);
1318 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001319 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321 break;
Hall Liu27d24262020-09-18 19:04:59 -07001322 }
Shuo Qian4a594052020-01-23 11:59:30 -08001323
Hall Liu27d24262020-09-18 19:04:59 -07001324 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1327 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1328 break;
Hall Liu27d24262020-09-18 19:04:59 -07001329 }
Shuo Qian4a594052020-01-23 11:59:30 -08001330
Hall Liu27d24262020-09-18 19:04:59 -07001331 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001334 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001335 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001337 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001338 // Service Class is a bit mask per 3gpp 27.007.
1339 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001340 if (callForwardResults.length > 1
1341 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001342 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001343 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001344 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1345 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001348 }
1349 } else {
1350 if (ar.result == null) {
1351 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1352 }
1353 if (ar.exception != null) {
1354 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1355 }
1356 if (ar.exception instanceof CommandException) {
1357 CommandException.Error error =
1358 ((CommandException) (ar.exception)).getCommandError();
1359 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001361 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001362 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1363 callWaitingStatus =
1364 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001365 }
1366 }
1367 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001368 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001369 break;
Hall Liu27d24262020-09-18 19:04:59 -07001370 }
Shuo Qian4a594052020-01-23 11:59:30 -08001371
Hall Liu27d24262020-09-18 19:04:59 -07001372 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001375 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1376 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001377 break;
Hall Liu27d24262020-09-18 19:04:59 -07001378 }
Shuo Qian4a594052020-01-23 11:59:30 -08001379
Hall Liu27d24262020-09-18 19:04:59 -07001380 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001383 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1384 Consumer<Integer> callback =
1385 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1386 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001387 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001388 if (ar.exception instanceof CommandException) {
1389 CommandException.Error error =
1390 ((CommandException) (ar.exception)).getCommandError();
1391 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001393 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1394 callback.accept(
1395 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001396 } else {
1397 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1398 }
1399 } else {
1400 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1401 }
1402 } else {
1403 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1404 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001405 }
Shuo Qian4a594052020-01-23 11:59:30 -08001406 break;
Hall Liu27d24262020-09-18 19:04:59 -07001407 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001408 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 CellNetworkScanResult cellScanResult;
1412 if (ar.exception == null && ar.result != null) {
1413 cellScanResult = new CellNetworkScanResult(
1414 CellNetworkScanResult.STATUS_SUCCESS,
1415 (List<OperatorInfo>) ar.result);
1416 } else {
1417 if (ar.result == null) {
1418 loge("getCellNetworkScanResults: Empty response");
1419 }
1420 if (ar.exception != null) {
1421 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1422 }
1423 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1424 if (ar.exception instanceof CommandException) {
1425 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001426 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001427 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1428 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1429 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1430 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1431 }
1432 }
1433 cellScanResult = new CellNetworkScanResult(errorCode, null);
1434 }
1435 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001437 break;
1438
1439 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1440 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001441 ManualNetworkSelectionArgument selArg =
1442 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001443 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1444 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001445 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1446 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001447 break;
1448
1449 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null) {
1453 request.result = true;
1454 } else {
1455 request.result = false;
1456 loge("setNetworkSelectionModeManual " + ar.exception);
1457 }
1458 notifyRequester(request);
1459 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001460 break;
1461
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 case CMD_GET_MODEM_ACTIVITY_INFO:
1463 request = (MainThreadRequest) msg.obj;
1464 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001465 if (defaultPhone != null) {
1466 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 } else {
1468 ResultReceiver result = (ResultReceiver) request.argument;
1469 Bundle bundle = new Bundle();
1470 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001471 new ModemActivityInfo(0, 0, 0,
1472 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001474 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 break;
1476
Hall Liud0f208c2020-10-14 16:54:44 -07001477 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001480 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001481 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001482 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001483 if (mLastModemActivityInfo == null) {
1484 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1485 mLastModemActivitySpecificInfo[0] =
1486 new ActivityStatsTechSpecificInfo(
1487 0,
1488 0,
1489 new int[ModemActivityInfo.getNumTxPowerLevels()],
1490 0);
1491 mLastModemActivityInfo =
1492 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1493 }
1494
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001496 // Update the last modem activity info and the result of the request.
1497 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1498 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001499 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001500 } else {
1501 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001502 }
Kai Shi917fdc62022-11-28 14:01:02 -08001503 // This is needed to decouple ret from mLastModemActivityInfo
1504 // We don't want to return mLastModemActivityInfo which is updated
1505 // inside mergeModemActivityInfo()
1506 ret = new ModemActivityInfo(
1507 mLastModemActivityInfo.getTimestampMillis(),
1508 mLastModemActivityInfo.getSleepTimeMillis(),
1509 mLastModemActivityInfo.getIdleTimeMillis(),
1510 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001511
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512 } else {
1513 if (ar.result == null) {
1514 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001515 error = TelephonyManager.ModemActivityInfoException
1516 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001518 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001519 error = TelephonyManager.ModemActivityInfoException
1520 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001521 } else {
1522 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001523 error = TelephonyManager.ModemActivityInfoException
1524 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001525 }
1526 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001527 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001528 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001529 bundle.putParcelable(
1530 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001531 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001532 } else {
1533 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1534 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001535 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001536 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001537 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001538 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001539
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001540 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001542 CarrierRestrictionRules argument =
1543 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001545 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001547 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001548
1549 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001555 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1556 if (ar.exception instanceof CommandException) {
1557 loge("setAllowedCarriers: CommandException: " + ar.exception);
1558 CommandException.Error error =
1559 ((CommandException) (ar.exception)).getCommandError();
1560 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1561 request.result =
1562 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1563 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001564 } else {
1565 loge("setAllowedCarriers: Unknown exception");
1566 }
1567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001569 break;
1570
1571 case CMD_GET_ALLOWED_CARRIERS:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001574 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001575 break;
1576
1577 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception == null && ar.result != null) {
1581 request.result = ar.result;
1582 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001583 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001584 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001585 if (ar.result == null) {
1586 loge("getAllowedCarriers: Empty response");
1587 } else if (ar.exception instanceof CommandException) {
1588 loge("getAllowedCarriers: CommandException: " +
1589 ar.exception);
1590 } else {
1591 loge("getAllowedCarriers: Unknown exception");
1592 }
1593 }
arunvoddud7401012022-12-15 16:08:12 +00001594 if (request.argument != null) {
1595 // This is for the implementation of carrierRestrictionStatus.
1596 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1597 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001598 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001599 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1600 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1601 CarrierRestrictionRules carrierRestrictionRules =
1602 (CarrierRestrictionRules) ar.result;
1603 int carrierId = -1;
1604 try {
1605 CarrierIdentifier carrierIdentifier =
1606 carrierRestrictionRules.getAllowedCarriers().get(0);
1607 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1608 carrierIdentifier);
1609 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1610 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1611 }
1612 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001613 int restrictedStatus =
1614 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1615 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1616 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001617 lockStatus = TelephonyManager
1618 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001619 }
1620 } else {
1621 Rlog.e(LOG_TAG,
1622 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1623 }
1624 callback.accept(lockStatus);
1625 } else {
1626 // This is for the implementation of getAllowedCarriers.
1627 notifyRequester(request);
1628 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001629 break;
1630
Nathan Haroldb3014052017-01-25 15:57:32 -08001631 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception == null && ar.result != null) {
1635 request.result = ar.result;
1636 } else {
1637 request.result = new IllegalArgumentException(
1638 "Failed to retrieve Forbidden Plmns");
1639 if (ar.result == null) {
1640 loge("getForbiddenPlmns: Empty response");
1641 } else {
1642 loge("getForbiddenPlmns: Unknown exception");
1643 }
1644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001645 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001646 break;
1647
1648 case CMD_GET_FORBIDDEN_PLMNS:
1649 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001650 uiccPort = getUiccPortFromRequest(request);
1651 if (uiccPort == null) {
1652 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001653 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001654 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657 }
1658 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001659 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001660 if (uiccApp == null) {
1661 loge("getForbiddenPlmns() no app with specified type -- "
1662 + appType);
1663 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001664 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001665 break;
1666 } else {
1667 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1668 + " specified type -- " + appType);
1669 }
1670 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1671 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001672 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001673 break;
1674
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001675 case CMD_SWITCH_SLOTS:
1676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001677 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001679 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 break;
1681
1682 case EVENT_SWITCH_SLOTS_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001686 notifyRequester(request);
1687 break;
1688 case CMD_GET_NETWORK_SELECTION_MODE:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1691 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1692 break;
1693
1694 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1695 ar = (AsyncResult) msg.obj;
1696 request = (MainThreadRequest) ar.userObj;
1697 if (ar.exception != null) {
1698 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1699 } else {
1700 int mode = ((int[]) ar.result)[0];
1701 if (mode == 0) {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1703 } else {
1704 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1705 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001706 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001707 notifyRequester(request);
1708 break;
1709 case CMD_GET_CDMA_ROAMING_MODE:
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1712 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1713 break;
1714 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 if (ar.exception != null) {
1718 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1719 } else {
1720 request.result = ((int[]) ar.result)[0];
1721 }
1722 notifyRequester(request);
1723 break;
1724 case CMD_SET_CDMA_ROAMING_MODE:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1727 int mode = (int) request.argument;
1728 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1729 break;
1730 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 request.result = ar.exception == null;
1734 notifyRequester(request);
1735 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001736 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1737 request = (MainThreadRequest) msg.obj;
1738 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1739 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1740 break;
1741 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 if (ar.exception != null) {
1745 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1746 } else {
1747 request.result = ((int[]) ar.result)[0];
1748 }
1749 notifyRequester(request);
1750 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001751 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1752 request = (MainThreadRequest) msg.obj;
1753 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1754 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001755 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1756 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001757 break;
1758 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 request.result = ar.exception == null;
1762 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001763 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 case CMD_GET_ALL_CELL_INFO:
1765 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001767 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 case EVENT_GET_ALL_CELL_INFO_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001772 // If a timeout occurs, the response will be null
1773 request.result = (ar.exception == null && ar.result != null)
1774 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001775 synchronized (request) {
1776 request.notifyAll();
1777 }
1778 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 case CMD_REQUEST_CELL_INFO_UPDATE:
1780 request = (MainThreadRequest) msg.obj;
1781 request.phone.requestCellInfoUpdate(request.workSource,
1782 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1783 break;
1784 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1788 try {
1789 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001790 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001791 cb.onError(
1792 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1793 ar.exception.getClass().getName(),
1794 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001795 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001797 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001798 } else {
1799 // use the result as returned
1800 cb.onCellInfo((List<CellInfo>) ar.result);
1801 }
1802 } catch (RemoteException re) {
1803 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1804 }
1805 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001807 request = (MainThreadRequest) msg.obj;
1808 WorkSource ws = (WorkSource) request.argument;
1809 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001810 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001812 }
1813 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 if (ar.exception == null) {
1817 request.result = ar.result;
1818 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001819 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001821 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001822 }
1823
1824 synchronized (request) {
1825 request.notifyAll();
1826 }
1827 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001828 }
chen xu6dac5ab2018-10-26 17:39:23 -07001829 case CMD_MODEM_REBOOT:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001832 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001833 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001834 case EVENT_CMD_MODEM_REBOOT_DONE:
1835 handleNullReturnEvent(msg, "rebootModem");
1836 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001837 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001838 request = (MainThreadRequest) msg.obj;
1839 boolean enable = (boolean) request.argument;
1840 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001841 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001842 PhoneConfigurationManager.getInstance()
1843 .enablePhone(request.phone, enable, onCompleted);
1844 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001845 }
Michele Berionne5e411512020-11-13 02:36:59 +00001846 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001847 ar = (AsyncResult) msg.obj;
1848 request = (MainThreadRequest) ar.userObj;
1849 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001851 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001852 if ((boolean) request.result) {
1853 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1854 updateModemStateMetrics();
1855 } else {
1856 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1857 + ar.exception);
1858 }
1859 notifyRequester(request);
1860 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001861 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001862 case CMD_GET_MODEM_STATUS:
1863 request = (MainThreadRequest) msg.obj;
1864 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1865 PhoneConfigurationManager.getInstance()
1866 .getPhoneStatusFromModem(request.phone, onCompleted);
1867 break;
1868 case EVENT_GET_MODEM_STATUS_DONE:
1869 ar = (AsyncResult) msg.obj;
1870 request = (MainThreadRequest) ar.userObj;
1871 int id = request.phone.getPhoneId();
1872 if (ar.exception == null && ar.result != null) {
1873 request.result = ar.result;
1874 //update the cache as modem status has changed
1875 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1876 (boolean) request.result);
1877 } else {
1878 // Return true if modem status cannot be retrieved. For most cases,
1879 // modem status is on. And for older version modems, GET_MODEM_STATUS
1880 // and disable modem are not supported. Modem is always on.
1881 // TODO: this should be fixed in R to support a third
1882 // status UNKNOWN b/131631629
1883 request.result = true;
1884 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1885 + ar.exception);
1886 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001887 notifyRequester(request);
1888 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001889 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1892 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1893 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1894 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1895 break;
1896 }
1897 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1898 ar = (AsyncResult) msg.obj;
1899 request = (MainThreadRequest) ar.userObj;
1900 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1901 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1902 args.second.accept(ar.exception == null);
1903 notifyRequester(request);
1904 break;
1905 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001906 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1907 request = (MainThreadRequest) msg.obj;
1908 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1909 Phone phone = getPhoneFromRequest(request);
1910 if (phone != null) {
1911 phone.getSystemSelectionChannels(onCompleted);
1912 } else {
1913 loge("getSystemSelectionChannels: No phone object");
1914 request.result = new ArrayList<RadioAccessSpecifier>();
1915 notifyRequester(request);
1916 }
1917 break;
1918 }
1919 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null && ar.result != null) {
1923 request.result = ar.result;
1924 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001925 request.result = new IllegalStateException(
1926 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001927 if (ar.result == null) {
1928 loge("getSystemSelectionChannels: Empty response");
1929 } else {
1930 loge("getSystemSelectionChannels: Unknown exception");
1931 }
1932 }
1933 notifyRequester(request);
1934 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001935 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1936 ar = (AsyncResult) msg.obj;
1937 request = (MainThreadRequest) ar.userObj;
1938 if (ar.exception == null && ar.result != null) {
1939 request.result = ar.result;
1940 } else {
1941 request.result = -1;
1942 loge("Failed to set Forbidden Plmns");
1943 if (ar.result == null) {
1944 loge("setForbidenPlmns: Empty response");
1945 } else if (ar.exception != null) {
1946 loge("setForbiddenPlmns: Exception: " + ar.exception);
1947 request.result = -1;
1948 } else {
1949 loge("setForbiddenPlmns: Unknown exception");
1950 }
1951 }
1952 notifyRequester(request);
1953 break;
1954 case CMD_SET_FORBIDDEN_PLMNS:
1955 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001956 uiccPort = getUiccPortFromRequest(request);
1957 if (uiccPort == null) {
1958 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001959 request.result = -1;
1960 notifyRequester(request);
1961 break;
1962 }
1963 Pair<Integer, List<String>> setFplmnsArgs =
1964 (Pair<Integer, List<String>>) request.argument;
1965 appType = setFplmnsArgs.first;
1966 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001967 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001968 if (uiccApp == null) {
1969 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1970 request.result = -1;
1971 loge("Failed to get UICC App");
1972 notifyRequester(request);
1973 } else {
1974 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1975 ((SIMRecords) uiccApp.getIccRecords())
1976 .setForbiddenPlmns(onCompleted, fplmns);
1977 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001978 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001979 case CMD_ERASE_MODEM_CONFIG:
1980 request = (MainThreadRequest) msg.obj;
1981 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1982 defaultPhone.eraseModemConfig(onCompleted);
1983 break;
1984 case EVENT_ERASE_MODEM_CONFIG_DONE:
1985 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001986 break;
zoey chene02881a2019-12-30 16:11:23 +08001987
Kai Shif70f46f2021-03-03 13:59:46 -08001988 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1989 request = (MainThreadRequest) msg.obj;
1990 request.result = defaultPhone.eraseDataInSharedPreferences();
1991 notifyRequester(request);
1992 break;
1993
zoey chene02881a2019-12-30 16:11:23 +08001994 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1995 request = (MainThreadRequest) msg.obj;
1996 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1997 Pair<String, String> changed = (Pair<String, String>) request.argument;
1998 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1999 changed.first, changed.second, onCompleted);
2000 break;
2001 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2002 ar = (AsyncResult) msg.obj;
2003 request = (MainThreadRequest) ar.userObj;
2004 if (ar.exception == null) {
2005 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002006 // If the operation is successful, update the PIN storage
2007 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2008 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002009 UiccController.getInstance().getPinStorage()
2010 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002011 } else {
2012 request.result = msg.arg1;
2013 }
2014 notifyRequester(request);
2015 break;
2016
Michele Berionne5e411512020-11-13 02:36:59 +00002017 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002018 request = (MainThreadRequest) msg.obj;
2019 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2020 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2021 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2022 enabled.first, enabled.second, onCompleted);
2023 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002024 }
zoey chene02881a2019-12-30 16:11:23 +08002025 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2026 ar = (AsyncResult) msg.obj;
2027 request = (MainThreadRequest) ar.userObj;
2028 if (ar.exception == null) {
2029 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002030 // If the operation is successful, update the PIN storage
2031 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2032 int phoneId = getPhoneFromRequest(request).getPhoneId();
2033 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002034 UiccController.getInstance().getPinStorage()
2035 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002036 } else {
2037 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2038 }
zoey chene02881a2019-12-30 16:11:23 +08002039 } else {
2040 request.result = msg.arg1;
2041 }
Michele Berionne5e411512020-11-13 02:36:59 +00002042
2043
zoey chene02881a2019-12-30 16:11:23 +08002044 notifyRequester(request);
2045 break;
2046
Peter Wangdafb9ac2020-01-15 14:13:38 -08002047 case MSG_NOTIFY_USER_ACTIVITY:
2048 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002049 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002050 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2051 getDefaultPhone().getContext().sendBroadcastAsUser(
2052 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2053 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002054
2055 case CMD_SET_DATA_THROTTLING: {
2056 request = (MainThreadRequest) msg.obj;
2057 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2058 DataThrottlingRequest dataThrottlingRequest =
2059 (DataThrottlingRequest) request.argument;
2060 Phone phone = getPhoneFromRequest(request);
2061 if (phone != null) {
2062 phone.setDataThrottling(onCompleted,
2063 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2064 dataThrottlingRequest.getCompletionDurationMillis());
2065 } else {
2066 loge("setDataThrottling: No phone object");
2067 request.result =
2068 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2069 notifyRequester(request);
2070 }
2071
2072 break;
2073 }
2074 case EVENT_SET_DATA_THROTTLING_DONE:
2075 ar = (AsyncResult) msg.obj;
2076 request = (MainThreadRequest) ar.userObj;
2077
2078 if (ar.exception == null) {
2079 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2080 } else if (ar.exception instanceof CommandException) {
2081 loge("setDataThrottling: CommandException: " + ar.exception);
2082 CommandException.Error error =
2083 ((CommandException) (ar.exception)).getCommandError();
2084
2085 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2086 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002087 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002088 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2089 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002090 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2091 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002092 } else {
2093 request.result =
2094 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2095 }
2096 } else {
2097 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2098 }
2099 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2100 notifyRequester(request);
2101 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002102
2103 case CMD_SET_SIM_POWER: {
2104 request = (MainThreadRequest) msg.obj;
2105 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2106 request = (MainThreadRequest) msg.obj;
2107 int stateToSet =
2108 ((Pair<Integer, IIntegerConsumer>)
2109 request.argument).first;
2110 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2111 break;
2112 }
2113 case EVENT_SET_SIM_POWER_DONE: {
2114 ar = (AsyncResult) msg.obj;
2115 request = (MainThreadRequest) ar.userObj;
2116 IIntegerConsumer callback =
2117 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2118 if (ar.exception != null) {
2119 loge("setSimPower exception: " + ar.exception);
2120 int errorCode = TelephonyManager.CallForwardingInfoCallback
2121 .RESULT_ERROR_UNKNOWN;
2122 if (ar.exception instanceof CommandException) {
2123 CommandException.Error error =
2124 ((CommandException) (ar.exception)).getCommandError();
2125 if (error == CommandException.Error.SIM_ERR) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2127 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2129 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2131 } else {
2132 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2133 }
2134 }
2135 try {
2136 callback.accept(errorCode);
2137 } catch (RemoteException e) {
2138 // Ignore if the remote process is no longer available to call back.
2139 Log.w(LOG_TAG, "setSimPower: callback not available.");
2140 }
2141 } else {
2142 try {
2143 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2144 } catch (RemoteException e) {
2145 // Ignore if the remote process is no longer available to call back.
2146 Log.w(LOG_TAG, "setSimPower: callback not available.");
2147 }
2148 }
2149 break;
2150 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002151 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2152 request = (MainThreadRequest) msg.obj;
2153
2154 final Phone phone = getPhoneFromRequest(request);
2155 if (phone == null || phone.getServiceStateTracker() == null) {
2156 request.result = new IllegalStateException("Phone or SST is null");
2157 notifyRequester(request);
2158 break;
2159 }
2160
2161 Pair<Integer, SignalStrengthUpdateRequest> pair =
2162 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2163 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2164 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002165 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002166 request.subId, pair.first /*callingUid*/,
2167 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002168 break;
2169 }
2170 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2171 ar = (AsyncResult) msg.obj;
2172 request = (MainThreadRequest) ar.userObj;
2173 // request.result will be the exception of ar if present, true otherwise.
2174 // Be cautious not to leave result null which will wait() forever
2175 request.result = ar.exception != null ? ar.exception : true;
2176 notifyRequester(request);
2177 break;
2178 }
2179 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2180 request = (MainThreadRequest) msg.obj;
2181
2182 Phone phone = getPhoneFromRequest(request);
2183 if (phone == null || phone.getServiceStateTracker() == null) {
2184 request.result = new IllegalStateException("Phone or SST is null");
2185 notifyRequester(request);
2186 break;
2187 }
2188
2189 Pair<Integer, SignalStrengthUpdateRequest> pair =
2190 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2191 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2192 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002193 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002194 request.subId, pair.first /*callingUid*/,
2195 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002196 break;
2197 }
2198 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2199 ar = (AsyncResult) msg.obj;
2200 request = (MainThreadRequest) ar.userObj;
2201 request.result = ar.exception != null ? ar.exception : true;
2202 notifyRequester(request);
2203 break;
2204 }
Jordan Liu109698e2020-11-24 14:50:34 -08002205
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002206 case CMD_GET_SLICING_CONFIG: {
2207 request = (MainThreadRequest) msg.obj;
2208 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2209 request.phone.getSlicingConfig(onCompleted);
2210 break;
2211 }
2212 case EVENT_GET_SLICING_CONFIG_DONE: {
2213 ar = (AsyncResult) msg.obj;
2214 request = (MainThreadRequest) ar.userObj;
2215 ResultReceiver result = (ResultReceiver) request.argument;
2216
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 Bundle bundle = new Bundle();
2219 int resultCode = 0;
2220 if (ar.exception != null) {
2221 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2222 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002223 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002224 } else if (ar.result == null) {
2225 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002226 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002227 } else {
2228 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002229 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2230 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002231 }
2232
2233 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002234 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002235 }
2236 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2237 result.send(resultCode, bundle);
2238 notifyRequester(request);
2239 break;
2240 }
2241
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 request = (MainThreadRequest) msg.obj;
2244 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 PurchasePremiumCapabilityArgument arg =
2246 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002247 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2248 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 ar = (AsyncResult) msg.obj;
2254 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 PurchasePremiumCapabilityArgument arg =
2256 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 try {
2258 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002260 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002261 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002262 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263 + TelephonyManager.convertPurchaseResultToString(result));
2264 } catch (RemoteException e) {
2265 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002266 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002267 + " failed: " + e;
2268 if (DBG) log(logStr);
2269 AnomalyReporter.reportAnomaly(
2270 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2271 }
2272 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002273 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002274
Michele Berionne5e411512020-11-13 02:36:59 +00002275 case CMD_PREPARE_UNATTENDED_REBOOT:
2276 request = (MainThreadRequest) msg.obj;
2277 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002278 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002279 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002280 notifyRequester(request);
2281 break;
2282
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 default:
2284 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2285 break;
2286 }
2287 }
Jake Hambye994d462014-02-03 13:10:13 -08002288
Pengquan Menga1bb6272018-09-06 09:59:22 -07002289 private void notifyRequester(MainThreadRequest request) {
2290 synchronized (request) {
2291 request.notifyAll();
2292 }
2293 }
2294
Jake Hambye994d462014-02-03 13:10:13 -08002295 private void handleNullReturnEvent(Message msg, String command) {
2296 AsyncResult ar = (AsyncResult) msg.obj;
2297 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2298 if (ar.exception == null) {
2299 request.result = true;
2300 } else {
2301 request.result = false;
2302 if (ar.exception instanceof CommandException) {
2303 loge(command + ": CommandException: " + ar.exception);
2304 } else {
2305 loge(command + ": Unknown exception");
2306 }
2307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002308 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
2311
2312 /**
2313 * Posts the specified command to be executed on the main thread,
2314 * waits for the request to complete, and returns the result.
2315 * @see #sendRequestAsync
2316 */
2317 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002318 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2319 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002320 }
2321
2322 /**
2323 * Posts the specified command to be executed on the main thread,
2324 * waits for the request to complete, and returns the result.
2325 * @see #sendRequestAsync
2326 */
2327 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2328 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
2331
2332 /**
2333 * Posts the specified command to be executed on the main thread,
2334 * waits for the request to complete, and returns the result.
2335 * @see #sendRequestAsync
2336 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002337 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002338 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2339 }
2340
2341 /**
2342 * Posts the specified command to be executed on the main thread,
2343 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2344 * if not timeout or null otherwise.
2345 * @see #sendRequestAsync
2346 */
2347 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2348 long timeoutInMs) {
2349 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002350 }
2351
2352 /**
2353 * Posts the specified command to be executed on the main thread,
2354 * waits for the request to complete, and returns the result.
2355 * @see #sendRequestAsync
2356 */
Nathan Harold92bed182018-10-12 18:16:49 -07002357 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002359 }
2360
2361 /**
2362 * Posts the specified command to be executed on the main thread,
2363 * waits for the request to complete, and returns the result.
2364 * @see #sendRequestAsync
2365 */
2366 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002367 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2368 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002369 }
2370
2371 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002372 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2373 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2374 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002375 * @see #sendRequestAsync
2376 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002377 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2378 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2380 throw new RuntimeException("This method will deadlock if called from the main thread.");
2381 }
2382
Nathan Harold92bed182018-10-12 18:16:49 -07002383 MainThreadRequest request = null;
2384 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2385 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2386 } else if (phone != null) {
2387 request = new MainThreadRequest(argument, phone, workSource);
2388 } else {
2389 request = new MainThreadRequest(argument, subId, workSource);
2390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 Message msg = mMainThreadHandler.obtainMessage(command, request);
2393 msg.sendToTarget();
2394
Rambo Wang0f050d82021-02-12 11:43:36 -08002395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002397 if (timeoutInMs >= 0) {
2398 // Wait for at least timeoutInMs before returning null request result
2399 long now = SystemClock.elapsedRealtime();
2400 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002401 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002402 try {
2403 request.wait(deadline - now);
2404 } catch (InterruptedException e) {
2405 // Do nothing, go back and check if request is completed or timeout
2406 } finally {
2407 now = SystemClock.elapsedRealtime();
2408 }
2409 }
2410 } else {
2411 // Wait for the request to complete
2412 while (request.result == null) {
2413 try {
2414 request.wait();
2415 } catch (InterruptedException e) {
2416 // Do nothing, go back and wait until the request is complete
2417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419 }
2420 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002421 if (request.result == null) {
2422 Log.wtf(LOG_TAG,
2423 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 return request.result;
2426 }
2427
2428 /**
2429 * Asynchronous ("fire and forget") version of sendRequest():
2430 * Posts the specified command to be executed on the main thread, and
2431 * returns immediately.
2432 * @see #sendRequest
2433 */
2434 private void sendRequestAsync(int command) {
2435 mMainThreadHandler.sendEmptyMessage(command);
2436 }
2437
2438 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002440 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002441 */
2442 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002443 sendRequestAsync(command, argument, null, null);
2444 }
2445
2446 /**
2447 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2448 * @see {@link #sendRequest(int,Object)}
2449 */
2450 private void sendRequestAsync(
2451 int command, Object argument, Phone phone, WorkSource workSource) {
2452 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002453 Message msg = mMainThreadHandler.obtainMessage(command, request);
2454 msg.sendToTarget();
2455 }
2456
2457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 * Initialize the singleton PhoneInterfaceManager instance.
2459 * This is only done once, at startup, from PhoneApp.onCreate().
2460 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002461 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 synchronized (PhoneInterfaceManager.class) {
2463 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 } else {
2466 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2467 }
2468 return sInstance;
2469 }
2470 }
2471
2472 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002473 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002475 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002476 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002478 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002479 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002480 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2482 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002483 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002484 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002485 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002486 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002487 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002488 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002489 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2490 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002491 mVendorApiLevel = SystemProperties.getInt(
2492 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2493
Tyler Gunn64144d92022-03-17 14:16:41 -07002494 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 publish();
arunvoddud7401012022-12-15 16:08:12 +00002496 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002497
2498 // Create the SatelliteEntitlementController singleton, for using the get the
2499 // entitlementStatus for satellite service.
2500 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002503 @VisibleForTesting
2504 public SharedPreferences getSharedPreferences() {
2505 return mTelephonySharedPreferences;
2506 }
2507
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002508 /**
2509 * Get the default phone for this device.
2510 */
2511 @VisibleForTesting
2512 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002513 Phone thePhone = getPhone(getDefaultSubscription());
2514 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2515 }
2516
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 private void publish() {
2518 if (DBG) log("publish: " + this);
2519
Peter Wangc035ce42020-01-08 21:00:22 -08002520 TelephonyFrameworkInitializer
2521 .getTelephonyServiceManager()
2522 .getTelephonyServiceRegisterer()
2523 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
Stuart Scott584921c2015-01-15 17:10:34 -08002526 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002527 if (request.phone != null) {
2528 return request.phone;
2529 } else {
2530 return getPhoneFromSubId(request.subId);
2531 }
2532 }
2533
2534 private Phone getPhoneFromSubId(int subId) {
2535 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2536 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002537 }
2538
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002539 /**
2540 * Get phone object associated with a subscription.
2541 * Return default phone if phone object associated with subscription is null
2542 * @param subId - subscriptionId
2543 * @return phone object associated with a subscription or default phone if null.
2544 */
Ling Mac28f0212023-03-24 16:07:15 -07002545 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002546 Phone phone = getPhoneFromSubId(subId);
2547 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002548 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002549 phone = getDefaultPhone();
2550 }
2551 return phone;
2552 }
2553
Rambo Wange53e07d2022-05-10 13:01:13 -07002554 @Nullable
2555 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002556 Phone phone = getPhoneFromRequest(request);
2557 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002558 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002559 }
2560
Ling Mac28f0212023-03-24 16:07:15 -07002561 /**
2562 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2563 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2564 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2565 * @return The Phone associated the sub Id
2566 */
2567 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002568 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570
Kai Shif70f46f2021-03-03 13:59:46 -08002571 private void sendEraseModemConfig(@NonNull Phone phone) {
2572 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2573 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2574 }
2575
2576 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2577 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2578 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002579 }
2580
Peter Wang44b186e2020-01-13 23:33:09 -08002581 private boolean isImsAvailableOnDevice() {
2582 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2583 if (pm == null) {
2584 // For some reason package manger is not available.. This will fail internally anyway,
2585 // so do not throw error and allow.
2586 return true;
2587 }
2588 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2589 }
2590
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002592 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2593 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2594
Wink Savilleadd7cc52014-09-08 14:23:09 -07002595 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
Wink Savilleb564aae2014-10-23 10:18:09 -07002598 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 if (DBG) log("dial: " + number);
2600 // No permission check needed here: This is just a wrapper around the
2601 // ACTION_DIAL intent, which is available to any app since it puts up
2602 // the UI before it does anything.
2603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 String url = createTelUrl(number);
2607 if (url == null) {
2608 return;
2609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 // PENDING: should we just silently fail if phone is offhook or ringing?
2612 PhoneConstants.State state = mCM.getState(subId);
2613 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2614 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2615 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002616 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 }
2621 }
2622
2623 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002624 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002625 }
2626
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 if (DBG) log("call: " + number);
2629
2630 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002631 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 // from the context of the phone app.
2633 enforceCallPermission();
2634
Jordan Liu1617b712019-07-10 15:06:26 -07002635 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 != AppOpsManager.MODE_ALLOWED) {
2637 return;
2638 }
2639
joonhunshin4ac60942023-11-15 15:23:39 +00002640 enforceTelephonyFeatureWithException(callingPackage,
2641 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 String url = createTelUrl(number);
2646 if (url == null) {
2647 return;
2648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 boolean isValid = false;
2651 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2652 if (slist != null) {
2653 for (SubscriptionInfo subInfoRecord : slist) {
2654 if (subInfoRecord.getSubscriptionId() == subId) {
2655 isValid = true;
2656 break;
2657 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002658 }
Wink Saville08874612014-08-31 19:19:58 -07002659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 if (!isValid) {
2661 return;
2662 }
Wink Saville08874612014-08-31 19:19:58 -07002663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2665 intent.putExtra(SUBSCRIPTION_KEY, subId);
2666 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002667 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
Wink Savilleb564aae2014-10-23 10:18:09 -07002673 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002674 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002675 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2676 }
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002680 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2681 }
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
joonhunshin4ac60942023-11-15 15:23:39 +00002686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2687 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2688 "supplyPinReportResultForSubscriber");
2689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 final long identity = Binder.clearCallingIdentity();
2691 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002692 Phone phone = getPhone(subId);
2693 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 checkSimPin.start();
2695 return checkSimPin.unlockSim(null, pin);
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
2698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
Wink Savilleb564aae2014-10-23 10:18:09 -07002701 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
joonhunshin4ac60942023-11-15 15:23:39 +00002704 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2705 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002709 Phone phone = getPhone(subId);
2710 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711 checkSimPuk.start();
2712 return checkSimPuk.unlockSim(puk, pin);
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
2718 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002719 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 * a synchronous one.
2721 */
2722 private static class UnlockSim extends Thread {
2723
2724 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002725 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726
2727 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002728 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2729 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730
2731 // For replies from SimCard interface
2732 private Handler mHandler;
2733
2734 // For async handler to identify request type
2735 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002736 private static final int SUPPLY_PIN_DELAYED = 101;
2737 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2738 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2739 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740
Michele Berionne5e411512020-11-13 02:36:59 +00002741 UnlockSim(int phoneId, IccCard simCard) {
2742 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 mSimCard = simCard;
2744 }
2745
2746 @Override
2747 public void run() {
2748 Looper.prepare();
2749 synchronized (UnlockSim.this) {
2750 mHandler = new Handler() {
2751 @Override
2752 public void handleMessage(Message msg) {
2753 AsyncResult ar = (AsyncResult) msg.obj;
2754 switch (msg.what) {
2755 case SUPPLY_PIN_COMPLETE:
2756 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2757 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002758 mRetryCount = msg.arg1;
2759 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002760 CommandException.Error error = null;
2761 if (ar.exception instanceof CommandException) {
2762 error = ((CommandException) (ar.exception))
2763 .getCommandError();
2764 }
2765 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002766 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002767 } else if (error == CommandException.Error.ABORTED) {
2768 /* When UiccCardApp dispose, handle message and return
2769 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002770 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002771 } else {
2772 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2773 }
2774 } else {
2775 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002778 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 UnlockSim.this.notifyAll();
2780 }
2781 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002782 case SUPPLY_PIN_DELAYED:
2783 if(!mDone) {
2784 String logStr = "Delay in receiving SIM PIN response ";
2785 if (DBG) log(logStr);
2786 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2787 }
2788 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790 }
2791 };
2792 UnlockSim.this.notifyAll();
2793 }
2794 Looper.loop();
2795 }
2796
2797 /*
2798 * Use PIN or PUK to unlock SIM card
2799 *
2800 * If PUK is null, unlock SIM card with PIN
2801 *
2802 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302803 *
2804 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2805 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 */
Wink Saville9de0f752013-10-22 19:04:03 -07002807 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808
2809 while (mHandler == null) {
2810 try {
2811 wait();
2812 } catch (InterruptedException e) {
2813 Thread.currentThread().interrupt();
2814 }
2815 }
2816 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2817
2818 if (puk == null) {
2819 mSimCard.supplyPin(pin, callback);
2820 } else {
2821 mSimCard.supplyPuk(puk, pin, callback);
2822 }
2823
2824 while (!mDone) {
2825 try {
2826 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002827 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2828 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 wait();
2830 } catch (InterruptedException e) {
2831 // Restore the interrupted status
2832 Thread.currentThread().interrupt();
2833 }
2834 }
2835 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002836 int[] resultArray = new int[2];
2837 resultArray[0] = mResult;
2838 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002839
2840 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002841 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002842 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302843 // This instance is no longer reused, so quit its thread's looper.
2844 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002845
Wink Saville9de0f752013-10-22 19:04:03 -07002846 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848 }
2849
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002850 /**
2851 * This method has been removed due to privacy and stability concerns.
2852 */
2853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002855 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2856 return;
Wink Saville36469e72014-06-11 15:17:00 -07002857 }
2858
Nathan Harold1f889d82020-06-04 17:05:26 -07002859 @Override
2860 public void updateServiceLocationWithPackageName(String callingPackage) {
2861 mApp.getSystemService(AppOpsManager.class)
2862 .checkPackage(Binder.getCallingUid(), callingPackage);
2863
Nathan Haroldf096d982020-11-18 17:18:06 -08002864 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002865 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2866 // Callers targeting S have no business invoking this method.
2867 return;
2868 }
2869
2870 LocationAccessPolicy.LocationPermissionResult locationResult =
2871 LocationAccessPolicy.checkLocationPermission(mApp,
2872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2873 .setCallingPackage(callingPackage)
2874 .setCallingFeatureId(null)
2875 .setCallingPid(Binder.getCallingPid())
2876 .setCallingUid(Binder.getCallingUid())
2877 .setMethod("updateServiceLocation")
2878 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2879 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2880 .build());
2881 // Apps that lack location permission have no business calling this method;
2882 // however, because no permission was declared in the public API, denials must
2883 // all be "soft".
2884 switch (locationResult) {
2885 case DENIED_HARD: /* fall through */
2886 case DENIED_SOFT:
2887 return;
2888 }
2889
2890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
Ling Mac28f0212023-03-24 16:07:15 -07002893 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002899 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002900 @Override
2901 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002902 return isRadioOnWithFeature(callingPackage, null);
2903 }
2904
2905
2906 @Override
2907 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2908 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2909 callingFeatureId);
2910 }
2911
2912 @Deprecated
2913 @Override
2914 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2915 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002919 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002922 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002923 return false;
2924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925
joonhunshin4ac60942023-11-15 15:23:39 +00002926 enforceTelephonyFeatureWithException(callingPackage,
2927 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 return isRadioOnForSubscriber(subId);
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002935 }
2936
2937 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
2941 if (phone != null) {
2942 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2943 } else {
2944 return false;
2945 }
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
2951 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002952 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
Wink Saville36469e72014-06-11 15:17:00 -07002954
Wink Savilleb564aae2014-10-23 10:18:09 -07002955 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
joonhunshin4ac60942023-11-15 15:23:39 +00002958 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2959 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = getPhone(subId);
2964 if (phone != null) {
2965 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2966 }
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 }
Wink Saville36469e72014-06-11 15:17:00 -07002970 }
2971
2972 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002973 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002974 }
2975
Wink Savilleb564aae2014-10-23 10:18:09 -07002976 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002977 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 final Phone phone = getPhone(subId);
2982 if (phone == null) {
2983 return false;
2984 }
2985 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2986 toggleRadioOnOffForSubscriber(subId);
2987 }
2988 return true;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
Wink Saville36469e72014-06-11 15:17:00 -07002993
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002994 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002995 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002996
2997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2998 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2999
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003000 /*
3001 * If any of the Radios are available, it will need to be
3002 * shutdown. So return true if any Radio is available.
3003 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3007 Phone phone = PhoneFactory.getPhone(i);
3008 if (phone != null && phone.isRadioAvailable()) return true;
3009 }
3010 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3011 return false;
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003015 }
3016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003018 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 enforceModifyPermission();
3020
joonhunshin4ac60942023-11-15 15:23:39 +00003021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3022 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3027 logv("Shutting down Phone " + i);
3028 shutdownRadioUsingPhoneId(i);
3029 }
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003032 }
3033 }
3034
3035 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003036 Phone phone = PhoneFactory.getPhone(phoneId);
3037 if (phone != null && phone.isRadioAvailable()) {
3038 phone.shutdownRadio();
3039 }
3040 }
3041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
Ling Ma83dc5ea2023-01-12 15:06:04 -08003045 if (!turnOn) {
3046 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3047 }
3048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3052 if (defaultPhone != null) {
3053 defaultPhone.setRadioPower(turnOn);
3054 return true;
3055 } else {
3056 loge("There's no default phone.");
3057 return false;
3058 }
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003061 }
Wink Saville36469e72014-06-11 15:17:00 -07003062 }
3063
Wink Savilleb564aae2014-10-23 10:18:09 -07003064 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066
Ling Ma83dc5ea2023-01-12 15:06:04 -08003067 if (!turnOn) {
3068 log("setRadioPowerForSubscriber off: subId=" + subId
3069 + ",callingPackage=" + getCurrentPackageName());
3070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone phone = getPhone(subId);
3074 if (phone != null) {
3075 phone.setRadioPower(turnOn);
3076 return true;
3077 } else {
3078 return false;
3079 }
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083 }
3084
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003085 /**
3086 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3087 * no reason to power it off. When any of the voters want to power it off, it will be turned
3088 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3089 * powering it off, and these radio off votes will be cleared.
3090 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3091 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3092 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3093 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3094 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3095 * check its vote.
3096 *
3097 * @param subId The subscription ID.
3098 * @param reason The reason for powering off radio.
3099 * @return true on success and false on failure.
3100 */
3101 public boolean requestRadioPowerOffForReason(int subId,
3102 @TelephonyManager.RadioPowerReason int reason) {
3103 enforceModifyPermission();
3104
joonhunshin4ac60942023-11-15 15:23:39 +00003105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3106 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3107
Ling Ma83dc5ea2023-01-12 15:06:04 -08003108 log("requestRadioPowerOffForReason: subId=" + subId
3109 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003110 final long identity = Binder.clearCallingIdentity();
3111 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003112 boolean result = false;
3113 for (Phone phone : PhoneFactory.getPhones()) {
3114 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003116 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003117 if (!result) {
3118 loge("requestRadioPowerOffForReason: no phone exists");
3119 }
3120 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
3126 /**
3127 * Remove the vote on powering off the radio for a reason, as requested by
3128 * {@link requestRadioPowerOffForReason}.
3129 *
3130 * @param subId The subscription ID.
3131 * @param reason The reason for powering off radio.
3132 * @return true on success and false on failure.
3133 */
3134 public boolean clearRadioPowerOffForReason(int subId,
3135 @TelephonyManager.RadioPowerReason int reason) {
3136 enforceModifyPermission();
3137
joonhunshin4ac60942023-11-15 15:23:39 +00003138 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3139 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3140
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003141 final long identity = Binder.clearCallingIdentity();
3142 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003143 boolean result = false;
3144 for (Phone phone : PhoneFactory.getPhones()) {
3145 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003146 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003147 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003148 if (!result) {
3149 loge("clearRadioPowerOffForReason: no phone exists");
3150 }
3151 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
3155 }
3156
3157 /**
3158 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3159 *
3160 * @param subId The subscription ID.
3161 * @param callingPackage The package making the call.
3162 * @param callingFeatureId The feature in the package.
3163 * @return List of reasons for powering off radio.
3164 */
3165 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3166 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3167
joonhunshin4ac60942023-11-15 15:23:39 +00003168 enforceTelephonyFeatureWithException(callingPackage,
3169 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3170
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003171 final long identity = Binder.clearCallingIdentity();
3172 List result = new ArrayList();
3173 try {
3174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3175 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3176 return result;
3177 }
3178
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003179 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003180 if (phone != null) {
3181 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003182 } else {
3183 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003184 }
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
3188 return result;
3189 }
3190
Wink Saville36469e72014-06-11 15:17:00 -07003191 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003193 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195
joonhunshin4ac60942023-11-15 15:23:39 +00003196 enforceTelephonyFeatureWithException(callingPackage,
3197 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
Jack Yu285100e2022-12-02 22:48:35 -08003201 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003203 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003204 phone.getDataSettingsManager().setDataEnabled(
3205 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 return true;
3207 } else {
3208 return false;
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 }
3214
Wink Saville36469e72014-06-11 15:17:00 -07003215 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003217 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219
joonhunshin4ac60942023-11-15 15:23:39 +00003220 enforceTelephonyFeatureWithException(callingPackage,
3221 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
Jack Yu285100e2022-12-02 22:48:35 -08003225 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003227 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003228 phone.getDataSettingsManager().setDataEnabled(
3229 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 return true;
3231 } else {
3232 return false;
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 }
3238
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003240 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3242 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 final Phone phone = getPhone(subId);
3247 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003248 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 } else {
3250 return false;
3251 }
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003255 }
3256
3257 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003258 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003259 }
3260
pkanwarae03a6b2016-11-06 20:37:09 -08003261 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 enforceCallPermission();
3263
joonhunshin4ac60942023-11-15 15:23:39 +00003264 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3265 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3270 return;
3271 }
3272 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3273 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
pkanwar32d516d2016-10-14 19:37:38 -07003277 };
3278
Wink Savilleb564aae2014-10-23 10:18:09 -07003279 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
joonhunshin4ac60942023-11-15 15:23:39 +00003282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3283 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3288 return false;
3289 }
3290 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 }
3295
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003296 /**
3297 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3298 * tag on getCallState Binder call.
3299 */
3300 @Deprecated
3301 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003303 if (CompatChanges.isChangeEnabled(
3304 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3305 Binder.getCallingUid())) {
3306 // Do not allow this API to be called on API version 31+, it should only be
3307 // called on old apps using this Binder call directly.
3308 throw new SecurityException("This method can only be used for applications "
3309 + "targeting API version 30 or less.");
3310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
Ling Mac28f0212023-03-24 16:07:15 -07003313 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3314 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
3321 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3322 if (CompatChanges.isChangeEnabled(
3323 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3324 Binder.getCallingUid())) {
3325 // Check READ_PHONE_STATE for API version 31+
3326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3327 featureId, "getCallStateForSubscription")) {
3328 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3329 + "targeting API level 31+.");
3330 }
3331 }
joonhunshin4ac60942023-11-15 15:23:39 +00003332
3333 enforceTelephonyFeatureWithException(callingPackage,
3334 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3335
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3340 PhoneConstantConversions.convertCallState(phone.getState());
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 }
3345
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003347 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003348 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003349 }
3350
3351 @Override
3352 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003353 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3354 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 final long identity = Binder.clearCallingIdentity();
3357 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003358 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003360 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 } else {
3362 return PhoneConstantConversions.convertDataState(
3363 PhoneConstants.DataState.DISCONNECTED);
3364 }
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
Sanket Padawe356d7632015-06-22 14:03:32 -07003370 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003371 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003372 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003373 }
3374
3375 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003376 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003377 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3378 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 final long identity = Binder.clearCallingIdentity();
3381 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003382 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003384 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385 } else {
3386 return TelephonyManager.DATA_ACTIVITY_NONE;
3387 }
3388 } finally {
3389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 }
3392
3393 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003394 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003396 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003397
3398 LocationAccessPolicy.LocationPermissionResult locationResult =
3399 LocationAccessPolicy.checkLocationPermission(mApp,
3400 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3401 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003402 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003403 .setCallingPid(Binder.getCallingPid())
3404 .setCallingUid(Binder.getCallingUid())
3405 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003406 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003407 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3408 .build());
3409 switch (locationResult) {
3410 case DENIED_HARD:
3411 throw new SecurityException("Not allowed to access cell location");
3412 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003413 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3414 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 }
3416
joonhunshin4ac60942023-11-15 15:23:39 +00003417 enforceTelephonyFeatureWithException(callingPackage,
3418 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3419
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003420 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003424 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003425 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Svetoslav64fad262015-04-14 14:35:21 -07003429 }
3430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003432 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003433 if (!mApp.getResources().getBoolean(
3434 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3436 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3437 }
joonhunshin4ac60942023-11-15 15:23:39 +00003438
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003439 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3440 // registered cell info, so return a NULL country instead.
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003443 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3444 // Get default phone in this case.
3445 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3446 }
Jack Yu285100e2022-12-02 22:48:35 -08003447 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003449 if (phone == null) return "";
3450 ServiceStateTracker sst = phone.getServiceStateTracker();
3451 if (sst == null) return "";
3452 LocaleTracker lt = sst.getLocaleTracker();
3453 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003454 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003458 }
3459
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003460 /**
3461 * This method was removed due to potential issues caused by performing partial
3462 * updates of service state, and lack of a credible use case.
3463 *
3464 * This has the ability to break the telephony implementation by disabling notification of
3465 * changes in device connectivity. DO NOT USE THIS!
3466 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003467 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 public void enableLocationUpdates() {
3469 mApp.enforceCallingOrSelfPermission(
3470 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 }
3472
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003473 /**
3474 * This method was removed due to potential issues caused by performing partial
3475 * updates of service state, and lack of a credible use case.
3476 *
3477 * This has the ability to break the telephony implementation by disabling notification of
3478 * changes in device connectivity. DO NOT USE THIS!
3479 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480 @Override
3481 public void disableLocationUpdates() {
3482 mApp.enforceCallingOrSelfPermission(
3483 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 }
3485
3486 @Override
3487 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003488 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3489 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003490 try {
3491 mApp.getSystemService(AppOpsManager.class)
3492 .checkPackage(Binder.getCallingUid(), callingPackage);
3493 } catch (SecurityException e) {
3494 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3495 throw e;
3496 }
3497
Nathan Haroldf096d982020-11-18 17:18:06 -08003498 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003499 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3500 throw new SecurityException(
3501 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3502 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003503
Jordan Liu1617b712019-07-10 15:06:26 -07003504 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3506 return null;
3507 }
Svetoslav64fad262015-04-14 14:35:21 -07003508
joonhunshin4ac60942023-11-15 15:23:39 +00003509 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3510 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3511
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003512 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003514 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003515 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516
Nathan Haroldf180aac2018-06-01 18:43:55 -07003517 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3518 for (CellInfo ci : info) {
3519 if (ci instanceof CellInfoGsm) {
3520 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3521 } else if (ci instanceof CellInfoWcdma) {
3522 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003525 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003528 private List<CellInfo> getCachedCellInfo() {
3529 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3530 for (Phone phone : PhoneFactory.getPhones()) {
3531 List<CellInfo> info = phone.getAllCellInfo();
3532 if (info != null) cellInfos.addAll(info);
3533 }
3534 return cellInfos;
3535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536
3537 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003538 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003540 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003541
3542 LocationAccessPolicy.LocationPermissionResult locationResult =
3543 LocationAccessPolicy.checkLocationPermission(mApp,
3544 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3545 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003546 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003547 .setCallingPid(Binder.getCallingPid())
3548 .setCallingUid(Binder.getCallingUid())
3549 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003550 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003551 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3552 .build());
3553 switch (locationResult) {
3554 case DENIED_HARD:
3555 throw new SecurityException("Not allowed to access cell info");
3556 case DENIED_SOFT:
3557 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
Nathan Haroldf096d982020-11-18 17:18:06 -08003560 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003561 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3562 return getCachedCellInfo();
3563 }
3564
joonhunshin4ac60942023-11-15 15:23:39 +00003565 enforceTelephonyFeatureWithException(callingPackage,
3566 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3567
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003568 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3573 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003574 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003575 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 if (info != null) cellInfos.addAll(info);
3577 }
3578 return cellInfos;
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003581 }
3582 }
3583
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003584 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003585 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3586 String callingFeatureId) {
3587 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3588 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003589 }
3590
3591 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003592 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3593 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003594 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003595 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003596 }
3597
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003598 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3599 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003600 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003601 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003602
3603 LocationAccessPolicy.LocationPermissionResult locationResult =
3604 LocationAccessPolicy.checkLocationPermission(mApp,
3605 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3606 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003607 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003608 .setCallingPid(Binder.getCallingPid())
3609 .setCallingUid(Binder.getCallingUid())
3610 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003611 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3612 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003613 .build());
3614 switch (locationResult) {
3615 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003616 if (TelephonyPermissions
3617 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003618 // Safetynet logging for b/154934934
3619 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3620 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003621 throw new SecurityException("Not allowed to access cell info");
3622 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003623 if (TelephonyPermissions
3624 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003625 // Safetynet logging for b/154934934
3626 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3627 }
Nathan Harold5320c422019-05-09 10:26:08 -07003628 try {
3629 cb.onCellInfo(new ArrayList<CellInfo>());
3630 } catch (RemoteException re) {
3631 // Drop without consequences
3632 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003633 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003634 }
3635
joonhunshin4ac60942023-11-15 15:23:39 +00003636 enforceTelephonyFeatureWithException(callingPackage,
3637 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003638
3639 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003640 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3641
3642 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3643 }
3644
3645 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003646 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003647 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003648 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003652 Phone phone = getPhone(subId);
3653 if (phone == null) {
3654 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3655 } else {
3656 phone.setCellInfoListRate(rateInMillis, workSource);
3657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003661 }
3662
Shishir Agrawala9f32182016-04-12 12:00:16 -07003663 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003664 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003665 Phone phone = PhoneFactory.getPhone(slotIndex);
3666 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003667 return null;
3668 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003669 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003670 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003671 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003672 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003673 return null;
3674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675
joonhunshin4ac60942023-11-15 15:23:39 +00003676 enforceTelephonyFeatureWithException(callingPackage,
3677 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 return phone.getImei();
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003685 }
3686
3687 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003688 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3689 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3690 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3691 callingFeatureId, "getPrimaryImei")) {
3692 throw new SecurityException("Caller does not have permission");
3693 }
joonhunshin4ac60942023-11-15 15:23:39 +00003694
3695 enforceTelephonyFeatureWithException(callingPackage,
3696 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3697
arunvoddud5c6ce02022-12-11 06:03:12 +00003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 for (Phone phone : PhoneFactory.getPhones()) {
3701 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3702 return phone.getImei();
3703 }
3704 }
3705 throw new UnsupportedOperationException("Operation not supported");
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
3711 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003712 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003713 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3714 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3715
David Kelly5e06a7f2018-03-12 14:10:59 +00003716 Phone phone = PhoneFactory.getPhone(slotIndex);
3717 String tac = null;
3718 if (phone != null) {
3719 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003720 try {
3721 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3722 } catch (IndexOutOfBoundsException e) {
3723 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3724 return null;
3725 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003726 }
3727 return tac;
3728 }
3729
3730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003731 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003732 try {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3734 } catch (SecurityException se) {
3735 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3736 throw new SecurityException("Package " + callingPackage + " does not belong to "
3737 + Binder.getCallingUid());
3738 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003739 Phone phone = PhoneFactory.getPhone(slotIndex);
3740 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003741 return null;
3742 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743
Jeff Davidson913390f2018-02-23 17:11:49 -08003744 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003745 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003746 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003747 return null;
3748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
joonhunshin4ac60942023-11-15 15:23:39 +00003750 enforceTelephonyFeatureWithException(callingPackage,
3751 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 return phone.getMeid();
3756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
Jack Yu2af8d712017-03-15 17:14:14 -07003759 }
3760
3761 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003762 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003763 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3764 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3765
David Kelly5e06a7f2018-03-12 14:10:59 +00003766 Phone phone = PhoneFactory.getPhone(slotIndex);
3767 String manufacturerCode = null;
3768 if (phone != null) {
3769 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003770 try {
3771 manufacturerCode =
3772 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3773 } catch (IndexOutOfBoundsException e) {
3774 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3775 return null;
3776 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003777 }
3778 return manufacturerCode;
3779 }
3780
3781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003782 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3783 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003784 Phone phone = PhoneFactory.getPhone(slotIndex);
3785 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 return null;
3787 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003788 int subId = phone.getSubId();
3789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003790 mApp, subId, callingPackage, callingFeatureId,
3791 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003792 return null;
3793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
joonhunshin4ac60942023-11-15 15:23:39 +00003795 enforceTelephonyFeatureWithException(callingPackage,
3796 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 return phone.getDeviceSvn();
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003804 }
3805
fionaxu43304da2017-11-27 22:51:16 -08003806 @Override
3807 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003808 if (!mApp.getResources().getBoolean(
3809 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3811 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3812 }
joonhunshin4ac60942023-11-15 15:23:39 +00003813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
fionaxu43304da2017-11-27 22:51:16 -08003821 }
3822
3823 @Override
3824 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3826 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 final Phone phone = getPhone(subId);
3831 return phone == null ? null : phone.getCarrierName();
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
fionaxu43304da2017-11-27 22:51:16 -08003835 }
3836
calvinpanffe225e2018-11-01 19:43:06 +08003837 @Override
chen xu0026ca62019-03-06 15:28:50 -08003838 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3840 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3841
chen xu25637222018-11-04 17:17:00 -08003842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 final Phone phone = getPhone(subId);
3845 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003846 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
3850 }
3851
3852 @Override
chen xu0026ca62019-03-06 15:28:50 -08003853 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003854 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3855 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3856 "getSubscriptionSpecificCarrierName");
3857
chen xu25637222018-11-04 17:17:00 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003861 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
3865 }
3866
chen xu651eec72018-11-11 19:03:44 -08003867 @Override
chen xu864e11c2018-12-06 22:10:03 -08003868 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3869 if (!isSubscriptionMccMnc) {
3870 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3871 }
chen xu651eec72018-11-11 19:03:44 -08003872 final Phone phone = PhoneFactory.getPhone(slotIndex);
3873 if (phone == null) {
3874 return TelephonyManager.UNKNOWN_CARRIER_ID;
3875 }
joonhunshin4ac60942023-11-15 15:23:39 +00003876
3877 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3878 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3879
chen xu651eec72018-11-11 19:03:44 -08003880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
3885 }
3886 }
3887
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003888 //
3889 // Internal helper methods.
3890 //
3891
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003892 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003893 * Make sure the caller is the calling package itself
3894 *
3895 * @throws SecurityException if the caller is not the calling package
3896 */
3897 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3898 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003899 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3900 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003901 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003902 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003903 } catch (PackageManager.NameNotFoundException e) {
3904 // packageUid is -1
3905 }
3906 if (packageUid != callingUid) {
3907 throw new SecurityException(message + ": Package " + callingPackage
3908 + " does not belong to " + callingUid);
3909 }
3910 }
3911
3912 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003913 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3914 *
3915 * @throws SecurityException if the caller does not have the required permission
3916 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003917 @VisibleForTesting
3918 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003919 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3920 }
3921
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003922 /**
arunvoddud7401012022-12-15 16:08:12 +00003923 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003924 *
3925 * @throws SecurityException if the caller does not have the required permission
3926 */
3927 @VisibleForTesting
3928 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003929 enforceReadPermission(null);
3930 }
3931
3932 /**
3933 * Make sure the caller has the READ_PHONE_STATE permissions.
3934 *
3935 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3936 */
3937 @VisibleForTesting
3938 public void enforceReadPermission(String msg) {
3939 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003940 }
3941
Shuo Qian3b6ee772019-11-13 17:43:31 -08003942 private void enforceActiveEmergencySessionPermission() {
3943 mApp.enforceCallingOrSelfPermission(
3944 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3945 }
3946
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003947 /**
3948 * Make sure the caller has the CALL_PHONE permission.
3949 *
3950 * @throws SecurityException if the caller does not have the required permission
3951 */
3952 private void enforceCallPermission() {
3953 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3954 }
3955
paulhu5a773602019-08-23 19:17:33 +08003956 private void enforceSettingsPermission() {
3957 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003958 }
3959
Michele Berionne5e411512020-11-13 02:36:59 +00003960 private void enforceRebootPermission() {
3961 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3962 }
3963
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003964 /**
3965 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3966 * @param message - log message to print.
3967 * @throws SecurityException if the caller does not have the required permission
3968 */
3969 private void enforceSatelliteCommunicationPermission(String message) {
3970 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3971 }
3972
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003973 /**
3974 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3975 * @param message - log message to print.
3976 * @throws SecurityException if the caller does not have the required permission
3977 */
3978 private void enforcePackageUsageStatsPermission(String message) {
3979 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3980 }
3981
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003982 private String createTelUrl(String number) {
3983 if (TextUtils.isEmpty(number)) {
3984 return null;
3985 }
3986
Jake Hambye994d462014-02-03 13:10:13 -08003987 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003988 }
3989
Ihab Awadf9e92732013-12-05 18:02:52 -08003990 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003991 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003992 }
3993
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003994 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003995 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003996 }
3997
Ihab Awadf9e92732013-12-05 18:02:52 -08003998 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003999 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004000 }
4001
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004002 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004003 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004004 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004005 }
4006
Sanket Padawe356d7632015-06-22 14:03:32 -07004007 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004008 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004009 if (!mApp.getResources().getBoolean(
4010 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4011 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4012 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4013 }
joonhunshin4ac60942023-11-15 15:23:39 +00004014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 final Phone phone = PhoneFactory.getPhone(slotIndex);
4018 if (phone == null) {
4019 return PhoneConstants.PHONE_TYPE_NONE;
4020 } else {
4021 return phone.getPhoneType();
4022 }
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004026 }
4027
4028 /**
4029 * Returns the CDMA ERI icon index to display
4030 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004032 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4033 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4034 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004035 }
4036
Sanket Padawe356d7632015-06-22 14:03:32 -07004037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004038 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4039 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004041 mApp, subId, callingPackage, callingFeatureId,
4042 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004043 return -1;
4044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045
joonhunshin4ac60942023-11-15 15:23:39 +00004046 enforceTelephonyFeatureWithException(callingPackage,
4047 PackageManager.FEATURE_TELEPHONY_CDMA,
4048 "getCdmaEriIconIndexForSubscriber");
4049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 final Phone phone = getPhone(subId);
4053 if (phone != null) {
4054 return phone.getCdmaEriIconIndex();
4055 } else {
4056 return -1;
4057 }
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004061 }
4062
4063 /**
4064 * Returns the CDMA ERI icon mode,
4065 * 0 - ON
4066 * 1 - FLASHING
4067 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004069 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4070 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4071 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004072 }
4073
Sanket Padawe356d7632015-06-22 14:03:32 -07004074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004075 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4076 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 mApp, subId, callingPackage, callingFeatureId,
4079 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004080 return -1;
4081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 final Phone phone = getPhone(subId);
4086 if (phone != null) {
4087 return phone.getCdmaEriIconMode();
4088 } else {
4089 return -1;
4090 }
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004094 }
4095
4096 /**
4097 * Returns the CDMA ERI text,
4098 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004100 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4101 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4102 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004103 }
4104
Sanket Padawe356d7632015-06-22 14:03:32 -07004105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004106 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4107 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004109 mApp, subId, callingPackage, callingFeatureId,
4110 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004111 return null;
4112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 final Phone phone = getPhone(subId);
4117 if (phone != null) {
4118 return phone.getCdmaEriText();
4119 } else {
4120 return null;
4121 }
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004125 }
4126
4127 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004128 * Returns the CDMA MDN.
4129 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004130 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004131 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4133 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134
joonhunshin4ac60942023-11-15 15:23:39 +00004135 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4136 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 return phone.getLine1Number();
4143 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004144 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 return null;
4146 }
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004149 }
4150 }
4151
4152 /**
4153 * Returns the CDMA MIN.
4154 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004155 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004156 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4158 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159
joonhunshin4ac60942023-11-15 15:23:39 +00004160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4161 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 final Phone phone = getPhone(subId);
4166 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4167 return phone.getCdmaMin();
4168 } else {
4169 return null;
4170 }
4171 } finally {
4172 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004173 }
4174 }
4175
Hall Liud892bec2018-11-30 14:51:45 -08004176 @Override
4177 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4178 INumberVerificationCallback callback, String callingPackage) {
4179 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4180 != PERMISSION_GRANTED) {
4181 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4182 }
4183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4184
4185 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4186 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004187 throw new SecurityException("Calling package must be configured in the device config: "
4188 + "calling package: " + callingPackage
4189 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004190 }
4191
joonhunshin4ac60942023-11-15 15:23:39 +00004192 enforceTelephonyFeatureWithException(callingPackage,
4193 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4194
Hall Liud892bec2018-11-30 14:51:45 -08004195 if (range == null) {
4196 throw new NullPointerException("Range must be non-null");
4197 }
4198
4199 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004200 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004201
4202 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4203 }
4204
Junda Liuca05d5d2014-08-14 22:36:34 -07004205 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004206 * Returns true if CDMA provisioning needs to run.
4207 */
4208 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4210 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004214 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004218 }
4219
4220 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004221 * Sets the voice mail number of a given subId.
4222 */
4223 @Override
4224 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004225 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4226 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227
joonhunshin4ac60942023-11-15 15:23:39 +00004228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4229 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4234 new Pair<String, String>(alphaTag, number), new Integer(subId));
4235 return success;
4236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004239 }
4240
Ta-wei Yen87c49842016-05-13 21:19:52 -07004241 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004242 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004244 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4245 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004246 if (!TextUtils.equals(callingPackage, systemDialer)) {
4247 throw new SecurityException("caller must be system dialer");
4248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249
joonhunshin4ac60942023-11-15 15:23:39 +00004250 enforceTelephonyFeatureWithException(callingPackage,
4251 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4256 if (phoneAccountHandle == null) {
4257 return null;
4258 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004259 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004262 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004263 }
4264
4265 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004266 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4267 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004270 mApp, subId, callingPackage, callingFeatureId,
4271 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004272 return null;
4273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274
joonhunshin4ac60942023-11-15 15:23:39 +00004275 enforceTelephonyFeatureWithException(callingPackage,
4276 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4277
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004278 final long identity = Binder.clearCallingIdentity();
4279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004280 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004284 }
4285
4286 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004287 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4288 VisualVoicemailSmsFilterSettings settings) {
4289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004290 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004291 enforceTelephonyFeatureWithException(callingPackage,
4292 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004296 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004300 }
4301
4302 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004303 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4304 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004305 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004306 enforceTelephonyFeatureWithException(callingPackage,
4307 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004312 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004316 }
4317
4318 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004319 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4320 String callingPackage, int subId) {
4321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004326 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004330 }
4331
4332 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004333 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004339 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004343 }
4344
4345 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004346 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4347 String callingAttributionTag, int subId, String number, int port, String text,
4348 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004350 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004351 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004352
4353 enforceTelephonyFeatureWithException(callingPackage,
4354 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4355
Amit Mahajandccb3f12019-05-13 13:48:32 -07004356 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004357 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4358 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4359 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004360 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004361
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004362 /**
fionaxu0152e512016-11-14 13:36:14 -08004363 * Sets the voice activation state of a given subId.
4364 */
4365 @Override
4366 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4368 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369
joonhunshin4ac60942023-11-15 15:23:39 +00004370 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4371 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 final Phone phone = getPhone(subId);
4376 if (phone != null) {
4377 phone.setVoiceActivationState(activationState);
4378 } else {
4379 loge("setVoiceActivationState fails with invalid subId: " + subId);
4380 }
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004383 }
4384 }
4385
4386 /**
4387 * Sets the data activation state of a given subId.
4388 */
4389 @Override
4390 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4392 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393
joonhunshin4ac60942023-11-15 15:23:39 +00004394 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4395 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 final Phone phone = getPhone(subId);
4400 if (phone != null) {
4401 phone.setDataActivationState(activationState);
4402 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004403 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 }
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004407 }
4408 }
4409
4410 /**
4411 * Returns the voice activation state of a given subId.
4412 */
4413 @Override
4414 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416
joonhunshin4ac60942023-11-15 15:23:39 +00004417 enforceTelephonyFeatureWithException(callingPackage,
4418 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4419
fionaxu0152e512016-11-14 13:36:14 -08004420 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 if (phone != null) {
4424 return phone.getVoiceActivationState();
4425 } else {
4426 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4427 }
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004430 }
4431 }
4432
4433 /**
4434 * Returns the data activation state of a given subId.
4435 */
4436 @Override
4437 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439
joonhunshin4ac60942023-11-15 15:23:39 +00004440 enforceTelephonyFeatureWithException(callingPackage,
4441 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4442
fionaxu0152e512016-11-14 13:36:14 -08004443 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 if (phone != null) {
4447 return phone.getDataActivationState();
4448 } else {
4449 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4450 }
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004453 }
4454 }
4455
4456 /**
Wink Saville36469e72014-06-11 15:17:00 -07004457 * Returns the unread count of voicemails for a subId
4458 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004460 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4461 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004463 mApp, subId, callingPackage, callingFeatureId,
4464 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004465 return 0;
4466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 final Phone phone = getPhone(subId);
4470 if (phone != null) {
4471 return phone.getVoiceMessageCount();
4472 } else {
4473 return 0;
4474 }
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004478 }
4479
4480 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004481 * returns true, if the device is in a state where both voice and data
4482 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004483 */
4484 @Override
4485 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004486 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4487 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 final long identity = Binder.clearCallingIdentity();
4490 try {
Ling Mac28f0212023-03-24 16:07:15 -07004491 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004495 }
4496
4497 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004498 * Send the dialer code if called from the current default dialer or the caller has
4499 * carrier privilege.
4500 * @param inputCode The dialer code to send
4501 */
4502 @Override
4503 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004504 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004505 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004506 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4507 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004508 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004509 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004510 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512
joonhunshin4ac60942023-11-15 15:23:39 +00004513 enforceTelephonyFeatureWithException(callingPackage,
4514 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004518 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
fionaxu235cc5e2017-03-06 22:25:57 -08004522 }
4523
Pengquan Menga1bb6272018-09-06 09:59:22 -07004524 @Override
4525 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004526 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004527 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4528 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004529
4530 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4531 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4532
shilufc958392020-01-20 11:36:01 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 if (!isActiveSubscription(subId)) {
4536 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4537 }
4538 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4539 } finally {
4540 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004542 }
4543
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004545 public boolean isInEmergencySmsMode() {
4546 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004547
4548 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4549 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4550
Brad Ebingerb2b65522019-03-15 13:48:47 -07004551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 for (Phone phone : PhoneFactory.getPhones()) {
4554 if (phone.isInEmergencySmsMode()) {
4555 return true;
4556 }
4557 }
4558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
4561 return false;
4562 }
4563
shilu366312e2019-12-17 09:28:10 -08004564 /**
4565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4566 * @param subId The subscription to use to check the configuration.
4567 * @param c The callback that will be used to send the result.
4568 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004569 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004570 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4571 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004572 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004573 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004574
4575 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4577 "IMS not available on device.");
4578 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 final long token = Binder.clearCallingIdentity();
4580 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004581 int slotId = getSlotIndexOrException(subId);
4582 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004583
4584 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4585 if (controller != null) {
4586 ImsManager imsManager = controller.getImsManager(subId);
4587 if (imsManager != null) {
4588 imsManager.addRegistrationCallbackForSubscription(c, subId);
4589 } else {
4590 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4591 }
4592 } else {
4593 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4594 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004595 } catch (ImsException e) {
4596 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004597 } finally {
4598 Binder.restoreCallingIdentity(token);
4599 }
4600 }
4601
shilu366312e2019-12-17 09:28:10 -08004602 /**
4603 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4604 * @param subId The subscription to use to check the configuration.
4605 * @param c The callback that will be used to send the result.
4606 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004608 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004609 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004610 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4612 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4613 }
Meng Wangafbc5852019-09-19 17:37:13 -07004614 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004615
Meng Wangafbc5852019-09-19 17:37:13 -07004616 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004617 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4618 if (controller != null) {
4619 ImsManager imsManager = controller.getImsManager(subId);
4620 if (imsManager != null) {
4621 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4622 } else {
4623 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4624 + "is inactive, ignoring unregister.");
4625 // If the ImsManager is not valid, just return, since the callback
4626 // will already have been removed internally.
4627 }
4628 }
Meng Wangafbc5852019-09-19 17:37:13 -07004629 } finally {
4630 Binder.restoreCallingIdentity(token);
4631 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 }
4633
Brad Ebingera34a6c22019-10-22 17:36:18 -07004634 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004635 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4636 * @param subId The subscription to use to check the configuration.
4637 * @param c The callback that will be used to send the result.
4638 */
4639 @Override
4640 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4641 throws RemoteException {
4642 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4643 mApp, subId, "registerImsEmergencyRegistrationCallback");
4644
4645 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4647 "IMS not available on device.");
4648 }
4649 final long token = Binder.clearCallingIdentity();
4650 try {
4651 int slotId = getSlotIndexOrException(subId);
4652 verifyImsMmTelConfiguredOrThrow(slotId);
4653
4654 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4655 if (controller != null) {
4656 ImsManager imsManager = controller.getImsManager(subId);
4657 if (imsManager != null) {
4658 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4659 } else {
4660 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4661 }
4662 } else {
4663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4664 }
4665 } catch (ImsException e) {
4666 throw new ServiceSpecificException(e.getCode());
4667 } finally {
4668 Binder.restoreCallingIdentity(token);
4669 }
4670 }
4671
4672 /**
4673 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4674 * @param subId The subscription to use to check the configuration.
4675 * @param c The callback that will be used to send the result.
4676 */
4677 @Override
4678 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4679 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4680 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4681 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4682 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4683 }
4684 final long token = Binder.clearCallingIdentity();
4685
4686 try {
4687 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4688 if (controller != null) {
4689 ImsManager imsManager = controller.getImsManager(subId);
4690 if (imsManager != null) {
4691 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4692 } else {
4693 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4694 + "is inactive, ignoring unregister.");
4695 // If the ImsManager is not valid, just return, since the callback
4696 // will already have been removed internally.
4697 }
4698 }
4699 } finally {
4700 Binder.restoreCallingIdentity(token);
4701 }
4702 }
4703
4704 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004705 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4706 */
4707 @Override
4708 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4709 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4710 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4712 "IMS not available on device.");
4713 }
4714 final long token = Binder.clearCallingIdentity();
4715 try {
4716 Phone phone = getPhone(subId);
4717 if (phone == null) {
4718 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4719 + subId + "'");
4720 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4721 }
4722 phone.getImsRegistrationState(regState -> {
4723 try {
4724 consumer.accept((regState == null)
4725 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4726 } catch (RemoteException e) {
4727 // Ignore if the remote process is no longer available to call back.
4728 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4729 }
4730 });
4731 } finally {
4732 Binder.restoreCallingIdentity(token);
4733 }
4734 }
4735
4736 /**
4737 * Get the transport type for the IMS service registration state.
4738 */
4739 @Override
4740 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004742 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004743 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4744 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4745 "IMS not available on device.");
4746 }
4747 final long token = Binder.clearCallingIdentity();
4748 try {
4749 Phone phone = getPhone(subId);
4750 if (phone == null) {
4751 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4752 + subId + "'");
4753 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4754 }
4755 phone.getImsRegistrationTech(regTech -> {
4756 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4757 int regTechConverted = (regTech == null)
4758 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4759 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4760 regTechConverted);
4761 try {
4762 consumer.accept(regTechConverted);
4763 } catch (RemoteException e) {
4764 // Ignore if the remote process is no longer available to call back.
4765 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4766 }
4767 });
4768 } finally {
4769 Binder.restoreCallingIdentity(token);
4770 }
4771 }
4772
shilu366312e2019-12-17 09:28:10 -08004773 /**
4774 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4775 * @param subId The subscription to use to check the configuration.
4776 * @param c The callback that will be used to send the result.
4777 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004779 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4780 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004782 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004783 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4785 "IMS not available on device.");
4786 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 final long token = Binder.clearCallingIdentity();
4788 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004789 int slotId = getSlotIndexOrException(subId);
4790 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004791
4792 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4793 if (controller != null) {
4794 ImsManager imsManager = controller.getImsManager(subId);
4795 if (imsManager != null) {
4796 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4797 } else {
4798 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4799 }
4800 } else {
4801 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4802 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004803 } catch (ImsException e) {
4804 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 } finally {
4806 Binder.restoreCallingIdentity(token);
4807 }
4808 }
4809
shilu366312e2019-12-17 09:28:10 -08004810 /**
4811 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4812 * @param subId The subscription to use to check the configuration.
4813 * @param c The callback that will be used to send the result.
4814 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004815 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004816 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004817 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004818 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4820 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4821 }
Meng Wangafbc5852019-09-19 17:37:13 -07004822
4823 final long token = Binder.clearCallingIdentity();
4824 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004825 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4826 if (controller != null) {
4827 ImsManager imsManager = controller.getImsManager(subId);
4828 if (imsManager != null) {
4829 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4830 } else {
4831 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4832 + " is inactive, ignoring unregister.");
4833 // If the ImsManager is not valid, just return, since the callback
4834 // will already have been removed internally.
4835 }
4836 }
Meng Wangafbc5852019-09-19 17:37:13 -07004837 } finally {
4838 Binder.restoreCallingIdentity(token);
4839 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 }
4841
4842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004843 public boolean isCapable(int subId, int capability, int regTech) {
4844 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004845
4846 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4847 FEATURE_TELEPHONY_IMS, "isCapable");
4848
Brad Ebinger35c841c2018-10-01 10:40:55 -07004849 final long token = Binder.clearCallingIdentity();
4850 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004851 int slotId = getSlotIndexOrException(subId);
4852 verifyImsMmTelConfiguredOrThrow(slotId);
4853 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4854 } catch (com.android.ims.ImsException e) {
4855 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4856 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004857 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004858 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4859 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 } finally {
4861 Binder.restoreCallingIdentity(token);
4862 }
4863 }
4864
4865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004866 public boolean isAvailable(int subId, int capability, int regTech) {
4867 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004868
4869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4870 FEATURE_TELEPHONY_IMS, "isAvailable");
4871
Brad Ebinger35c841c2018-10-01 10:40:55 -07004872 final long token = Binder.clearCallingIdentity();
4873 try {
4874 Phone phone = getPhone(subId);
4875 if (phone == null) return false;
4876 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004877 } catch (com.android.ims.ImsException e) {
4878 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4879 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 } finally {
4881 Binder.restoreCallingIdentity(token);
4882 }
4883 }
4884
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004885 /**
4886 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4887 * subscription.
4888 * @param subId The subscription to use to check the configuration.
4889 * @param callback The callback that will be used to send the result.
4890 * @param capability The MmTelFeature capability that will be used to send the result.
4891 * @param transportType The transport type of the MmTelFeature capability.
4892 */
4893 @Override
4894 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4895 int transportType) {
4896 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004897 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4898 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4899 "IMS not available on device.");
4900 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004901 final long token = Binder.clearCallingIdentity();
4902 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004903 int slotId = getSlotIndex(subId);
4904 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4905 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4906 + subId + "'");
4907 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4908 }
4909 verifyImsMmTelConfiguredOrThrow(slotId);
4910 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4911 transportType, aBoolean -> {
4912 try {
4913 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4914 } catch (RemoteException e) {
4915 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4916 + "running. Ignore");
4917 }
4918 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 } catch (ImsException e) {
4920 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004921 } finally {
4922 Binder.restoreCallingIdentity(token);
4923 }
4924 }
4925
shilu366312e2019-12-17 09:28:10 -08004926 /**
4927 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4928 * @param subId The subscription to use to check the configuration.
4929 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004930 @Override
4931 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004932 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004933 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004934
joonhunshin4ac60942023-11-15 15:23:39 +00004935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4936 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4937
Brad Ebinger35c841c2018-10-01 10:40:55 -07004938 final long token = Binder.clearCallingIdentity();
4939 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004941 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004942 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (ImsException e) {
4944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004945 } finally {
4946 Binder.restoreCallingIdentity(token);
4947 }
4948 }
4949
4950 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004951 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004953 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004954
4955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4956 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4957
Brad Ebinger35c841c2018-10-01 10:40:55 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004960 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004961 // This setting doesn't require an active ImsService connection, so do not verify. The
4962 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004964 } catch (ImsException e) {
4965 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
shilu366312e2019-12-17 09:28:10 -08004971 /**
4972 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4973 * @param subId The subscription to use to check the configuration.
4974 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004975 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004976 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004978 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004979
4980 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4981 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4982
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004986 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004988 } catch (ImsException e) {
4989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
4993 }
4994
4995 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004996 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004998 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004999
5000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5001 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5002
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 final long identity = Binder.clearCallingIdentity();
5004 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005005 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005006 // This setting doesn't require an active ImsService connection, so do not verify. The
5007 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005008 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005009 } catch (ImsException e) {
5010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
5014 }
5015
shilu366312e2019-12-17 09:28:10 -08005016 /**
5017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5018 * @param subId The subscription to use to check the configuration.
5019 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005020 @Override
5021 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005022 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005023 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005024
5025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5026 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5027
Brad Ebinger35c841c2018-10-01 10:40:55 -07005028 final long identity = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005031 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005033 } catch (ImsException e) {
5034 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
5038 }
5039
5040 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005041 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005043 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005044
5045 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5046 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5047
Brad Ebinger35c841c2018-10-01 10:40:55 -07005048 final long identity = Binder.clearCallingIdentity();
5049 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005050 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005051 // This setting doesn't require an active ImsService connection, so do not verify. The
5052 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005053 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 } catch (ImsException e) {
5055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005056 } finally {
5057 Binder.restoreCallingIdentity(identity);
5058 }
5059 }
5060
shilu366312e2019-12-17 09:28:10 -08005061 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005062 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5064 * @param subId The subscription to use to check the configuration.
5065 */
5066 @Override
5067 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005068 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005069 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005070
5071 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5072 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5073
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005076 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005077 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005078 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005079 } catch (ImsException e) {
5080 throw new ServiceSpecificException(e.getCode());
5081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
5084 }
5085
5086 /**
5087 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5088 * Requires MODIFY_PHONE_STATE permission.
5089 * @param subId The subscription to use to check the configuration.
5090 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5091 * false otherwise
5092 */
5093 @Override
5094 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5096 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005097
5098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5099 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5100
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005103 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005104 // This setting doesn't require an active ImsService connection, so do not verify. The
5105 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005106 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005107 } catch (ImsException e) {
5108 throw new ServiceSpecificException(e.getCode());
5109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
5112 }
5113
5114 /**
shilu366312e2019-12-17 09:28:10 -08005115 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5116 * @param subId The subscription to use to check the configuration.
5117 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005119
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005121 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005122 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005123
5124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5125 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5126
Brad Ebinger35c841c2018-10-01 10:40:55 -07005127 final long identity = Binder.clearCallingIdentity();
5128 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005130 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005132 } catch (ImsException e) {
5133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
5137 }
5138
5139 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005140 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005142 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005143
5144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5145 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5146
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005150 // This setting doesn't require an active ImsService connection, so do not verify. The
5151 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005152 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005153 } catch (ImsException e) {
5154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
5160 @Override
5161 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5163 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005164
5165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5166 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5167
Brad Ebinger35c841c2018-10-01 10:40:55 -07005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005171 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005172 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005173 } catch (ImsException e) {
5174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
5178 }
5179
shilu366312e2019-12-17 09:28:10 -08005180 /**
5181 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5182 * @param subId The subscription to use to check the configuration.
5183 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 @Override
5185 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005186 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005187 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005188
5189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5190 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5191
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005195 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005196 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005197 } catch (ImsException e) {
5198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 @Override
5205 public void setVoWiFiModeSetting(int subId, int mode) {
5206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5207 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005208
5209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5210 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5211
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 final long identity = Binder.clearCallingIdentity();
5213 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005214 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005215 // This setting doesn't require an active ImsService connection, so do not verify. The
5216 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005217 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005218 } catch (ImsException e) {
5219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
5223 }
5224
5225 @Override
5226 public int getVoWiFiRoamingModeSetting(int subId) {
5227 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005228
5229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5230 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5231
Brad Ebinger35c841c2018-10-01 10:40:55 -07005232 final long identity = Binder.clearCallingIdentity();
5233 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005235 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005236 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005237 } catch (ImsException e) {
5238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
5242 }
5243
5244 @Override
5245 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5247 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005248
5249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5250 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5251
Brad Ebinger35c841c2018-10-01 10:40:55 -07005252 final long identity = Binder.clearCallingIdentity();
5253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005255 // This setting doesn't require an active ImsService connection, so do not verify. The
5256 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005257 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005258 } catch (ImsException e) {
5259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
5264
5265 @Override
5266 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5268 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005269
5270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5271 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5272
Brad Ebinger35c841c2018-10-01 10:40:55 -07005273 final long identity = Binder.clearCallingIdentity();
5274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005276 // This setting doesn't require an active ImsService connection, so do not verify. The
5277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005278 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005279 } catch (ImsException e) {
5280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
shilu366312e2019-12-17 09:28:10 -08005286 /**
5287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5288 * @param subId The subscription to use to check the configuration.
5289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005290 @Override
5291 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005293 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005294
5295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5296 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5297
Brad Ebinger35c841c2018-10-01 10:40:55 -07005298 final long identity = Binder.clearCallingIdentity();
5299 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005300 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005301 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005302 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005303 } catch (ImsException e) {
5304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
5308 }
5309
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005310 @Override
5311 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5312 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005313
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005314 final long identity = Binder.clearCallingIdentity();
5315 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005316 if (!isImsAvailableOnDevice()) {
5317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5318 "IMS not available on device.");
5319 }
5320 int slotId = getSlotIndexOrException(subId);
5321 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005322
5323 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5324 if (controller != null) {
5325 ImsManager imsManager = controller.getImsManager(subId);
5326 if (imsManager != null) {
5327 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5328 } else {
5329 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5330 }
5331 } else {
5332 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5333 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005334 } catch (ImsException e) {
5335 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
5339 }
5340
5341 @Override
5342 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5343 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005344
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005345 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5348 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005349 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005350 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5351 if (controller != null) {
5352 ImsManager imsManager = controller.getImsManager(subId);
5353 if (imsManager != null) {
5354 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5355 } else {
5356 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5357 + " is inactive, ignoring unregister.");
5358 // If the ImsManager is not valid, just return, since the callback will already
5359 // have been removed internally.
5360 }
5361 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
5365 }
5366
joonhunshincffb7fc2021-11-28 07:32:01 +00005367 @Override
5368 public void registerFeatureProvisioningChangedCallback(int subId,
5369 IFeatureProvisioningCallback callback) {
5370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5371 mApp, subId, "registerFeatureProvisioningChangedCallback");
5372
5373 final long identity = Binder.clearCallingIdentity();
5374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5375 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5376 }
5377
joonhunshin91bc1952022-04-29 08:47:15 +00005378 try {
5379 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5380 if (controller == null) {
5381 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5382 "Device does not support IMS");
5383 }
5384 controller.addFeatureProvisioningChangedCallback(subId, callback);
5385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005388 }
5389
5390 @Override
5391 public void unregisterFeatureProvisioningChangedCallback(int subId,
5392 IFeatureProvisioningCallback callback) {
5393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5394 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5395
5396 final long identity = Binder.clearCallingIdentity();
5397 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5398 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5399 }
5400
joonhunshin91bc1952022-04-29 08:47:15 +00005401 try {
5402 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5403 if (controller == null) {
5404 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5405 return;
5406 }
5407 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005411 }
allenwtsu99c623b2020-01-03 18:24:23 +08005412
5413 private void checkModifyPhoneStatePermission(int subId, String message) {
5414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5415 message);
5416 }
5417
allenwtsu99c623b2020-01-03 18:24:23 +08005418 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005419 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005420 boolean isProvisioned) {
5421 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5422
joonhunshin4ac60942023-11-15 15:23:39 +00005423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5424 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5425
allenwtsu99c623b2020-01-03 18:24:23 +08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005428 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5429 if (controller == null) {
5430 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5431 return;
5432 }
5433 controller.setRcsProvisioningStatusForCapability(
5434 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
allenwtsu99c623b2020-01-03 18:24:23 +08005438 }
5439
5440
5441 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005442 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5444 mApp, subId, "getRcsProvisioningStatusForCapability");
5445
joonhunshin4ac60942023-11-15 15:23:39 +00005446 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5447 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5448
allenwtsu99c623b2020-01-03 18:24:23 +08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005451 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5452 if (controller == null) {
5453 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5454
5455 // device does not support IMS, this method will return true always.
5456 return true;
5457 }
5458 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
5462 }
5463
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005464 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005465 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5466 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005467 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005468
joonhunshin4ac60942023-11-15 15:23:39 +00005469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5470 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5471
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005472 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005473 final long identity = Binder.clearCallingIdentity();
5474 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005475 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5476 if (controller == null) {
5477 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5478 return;
5479 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005480 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005481 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
5484 }
5485 }
5486
5487 @Override
5488 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5490 mApp, subId, "getProvisioningStatusForCapability");
5491
joonhunshin4ac60942023-11-15 15:23:39 +00005492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5493 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5494
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005495 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496 final long identity = Binder.clearCallingIdentity();
5497 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005498 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5499 if (controller == null) {
5500 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005501
joonhunshin91bc1952022-04-29 08:47:15 +00005502 // device does not support IMS, this method will return true always.
5503 return true;
5504 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005505 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5506 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
5510 }
5511
5512 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005513 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5515 mApp, subId, "isProvisioningRequiredForCapability");
5516
joonhunshin4ac60942023-11-15 15:23:39 +00005517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5518 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5519
joonhunshincffb7fc2021-11-28 07:32:01 +00005520 final long identity = Binder.clearCallingIdentity();
5521 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005522 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5523 if (controller == null) {
5524 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5525
5526 // device does not support IMS, this method will return false
5527 return false;
5528 }
5529 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533 }
5534
5535 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005536 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5537 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5538 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005539
joonhunshin4ac60942023-11-15 15:23:39 +00005540 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5541 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5542
joonhunshincffb7fc2021-11-28 07:32:01 +00005543 final long identity = Binder.clearCallingIdentity();
5544 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005545 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5546 if (controller == null) {
5547 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5548
5549 // device does not support IMS, this method will return false
5550 return false;
5551 }
5552 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005556 }
5557
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005558 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005559 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5561 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5562 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005563 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5564 mApp, subId, "getImsProvisioningInt");
5565
joonhunshin4ac60942023-11-15 15:23:39 +00005566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5567 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5568
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005569 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005573 int slotId = getSlotIndex(subId);
5574 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5575 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5576 + subId + "' for key:" + key);
5577 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5578 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005579
joonhunshin91bc1952022-04-29 08:47:15 +00005580 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5581 if (controller == null) {
5582 loge("getImsProvisioningInt: Device does not support IMS");
5583
5584 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5585 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5586 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005587 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5588 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005589 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5590 return retVal;
5591 }
5592
calvinpanb5a34062021-02-08 19:59:36 +08005593 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005594 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005595 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5596 + subId + "' for key:" + key);
5597 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
5601 }
5602
5603 @Override
5604 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5606 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5607 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5609 mApp, subId, "getImsProvisioningString");
5610
joonhunshin4ac60942023-11-15 15:23:39 +00005611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5612 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5613
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005617 int slotId = getSlotIndex(subId);
5618 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5619 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5620 + subId + "' for key:" + key);
5621 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5622 }
calvinpanb5a34062021-02-08 19:59:36 +08005623 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005624 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005625 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5626 + subId + "' for key:" + key);
5627 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
5631 }
5632
5633 @Override
5634 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5636 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5637 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5639 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005640
joonhunshin4ac60942023-11-15 15:23:39 +00005641 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5642 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5643
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005644 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005648 int slotId = getSlotIndex(subId);
5649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5650 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5651 + subId + "' for key:" + key);
5652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5653 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005654
joonhunshin91bc1952022-04-29 08:47:15 +00005655 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5656 if (controller == null) {
5657 loge("setImsProvisioningInt: Device does not support IMS");
5658
5659 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5660 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5661 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005662 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5663 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005664 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5665 return retVal;
5666 }
5667
calvinpanb5a34062021-02-08 19:59:36 +08005668 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5669 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005670 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005671 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005672 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
5676 }
5677
5678 @Override
5679 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5681 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5682 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5684 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005685
5686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5687 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5688
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005692 int slotId = getSlotIndex(subId);
5693 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5694 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5695 + subId + "' for key:" + key);
5696 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5697 }
calvinpanb5a34062021-02-08 19:59:36 +08005698 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5699 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005700 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005701 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005702 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
5706 }
5707
Brad Ebinger919631e2021-06-02 17:46:35 -07005708 /**
5709 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5710 * for the given slot ID or no ImsResolver instance has been created.
5711 * @param slotId The slot ID that the IMS service is created for.
5712 * @throws ImsException If there is no ImsService configured for this slot.
5713 */
5714 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5715 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5716 ImsFeature.FEATURE_MMTEL)) {
5717 throw new ImsException("This subscription does not support MMTEL over IMS",
5718 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5719 }
5720 }
5721
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005722 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005723 int slotId = SubscriptionManager.getSlotIndex(subId);
5724 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005725 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5726 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005727 }
5728 return slotId;
5729 }
5730
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005731 private int getSlotIndex(int subId) {
5732 int slotId = SubscriptionManager.getSlotIndex(subId);
5733 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5734 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5735 }
5736 return slotId;
5737 }
5738
Wink Saville36469e72014-06-11 15:17:00 -07005739 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005740 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005741 */
5742 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005743 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5744 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005745 try {
5746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5747 } catch (SecurityException se) {
5748 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5749 throw new SecurityException("Package " + callingPackage + " does not belong to "
5750 + Binder.getCallingUid());
5751 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005752 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005753 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005754 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005755 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005756 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005757 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005758 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5760 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005761
joonhunshin4ac60942023-11-15 15:23:39 +00005762 enforceTelephonyFeatureWithException(callingPackage,
5763 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 final Phone phone = getPhone(subId);
5768 if (phone != null) {
5769 return phone.getServiceState().getDataNetworkType();
5770 } else {
5771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5772 }
5773 } finally {
5774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005776 }
5777
5778 /**
5779 * Returns the data network type
5780 */
5781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005783 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005784 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005785 }
5786
5787 /**
5788 * Returns the data network type for a subId
5789 */
5790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005791 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5792 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005793 String functionName = "getDataNetworkTypeForSubscriber";
5794 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5795 mApp, functionName)) {
5796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5797 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5798 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5799 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005800 }
5801
joonhunshin4ac60942023-11-15 15:23:39 +00005802 enforceTelephonyFeatureWithException(callingPackage,
5803 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 final Phone phone = getPhone(subId);
5808 if (phone != null) {
5809 return phone.getServiceState().getDataNetworkType();
5810 } else {
5811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5812 }
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005816 }
5817
5818 /**
Wink Saville36469e72014-06-11 15:17:00 -07005819 * Returns the Voice network type for a subId
5820 */
5821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005822 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5823 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005824 String functionName = "getVoiceNetworkTypeForSubscriber";
5825 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5826 mApp, functionName)) {
5827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5828 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5829 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5830 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005831 }
5832
joonhunshin4ac60942023-11-15 15:23:39 +00005833 enforceTelephonyFeatureWithException(callingPackage,
5834 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 final long identity = Binder.clearCallingIdentity();
5837 try {
5838 final Phone phone = getPhone(subId);
5839 if (phone != null) {
5840 return phone.getServiceState().getVoiceNetworkType();
5841 } else {
5842 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5843 }
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005847 }
5848
5849 /**
5850 * @return true if a ICC card is present
5851 */
5852 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005853 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005854 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005855 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005856 }
5857
5858 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005859 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005860 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005861 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005862 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005863 if (!mApp.getResources().getBoolean(
5864 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5865 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5866 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5867 }
joonhunshin4ac60942023-11-15 15:23:39 +00005868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 final Phone phone = PhoneFactory.getPhone(slotIndex);
5872 if (phone != null) {
5873 return phone.getIccCard().hasIccCard();
5874 } else {
5875 return false;
5876 }
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005880 }
5881
5882 /**
5883 * Return if the current radio is LTE on CDMA. This
5884 * is a tri-state return value as for a period of time
5885 * the mode may be unknown.
5886 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005887 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005888 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005889 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005890 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005892 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5893 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5894 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005895 }
5896
Sanket Padawe356d7632015-06-22 14:03:32 -07005897 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005898 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5899 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005900 try {
5901 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5902 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005903 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5904 }
5905
joonhunshin4ac60942023-11-15 15:23:39 +00005906 enforceTelephonyFeatureWithException(callingPackage,
5907 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 final Phone phone = getPhone(subId);
5912 if (phone == null) {
5913 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5914 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005915 return TelephonyProperties.lte_on_cdma_device()
5916 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 }
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005920 }
Wink Saville36469e72014-06-11 15:17:00 -07005921 }
5922
Wink Saville36469e72014-06-11 15:17:00 -07005923 /**
5924 * {@hide}
5925 * Returns Default subId, 0 in the case of single standby.
5926 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005927 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005928 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005929 }
5930
Shishir Agrawala9f32182016-04-12 12:00:16 -07005931 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005932 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005933 }
5934
Wink Savilleb564aae2014-10-23 10:18:09 -07005935 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005936 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005937 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005938
Pengquan Menge92a50d2018-09-21 15:54:48 -07005939 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005940 return getSubscriptionManagerService().isActiveSubId(subId,
5941 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005942 }
5943
Ihab Awadf2177b72013-11-25 13:33:23 -08005944 /**
5945 * @see android.telephony.TelephonyManager.WifiCallingChoices
5946 */
5947 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005950 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5952 getWhenToMakeWifiCallsDefaultPreference());
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005956 }
5957
5958 /**
5959 * @see android.telephony.TelephonyManager.WifiCallingChoices
5960 */
5961 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005965 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005970 }
5971
Sailesh Nepald1e68152013-12-12 19:08:02 -08005972 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005973 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005974 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005975 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005976
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005977 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5978 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5979 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005980 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005981 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005982 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005983 }
5984 return PhoneFactory.getPhone(phoneId);
5985 }
5986
Shishir Agrawal566b7612013-10-28 14:41:00 -07005987 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005988 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005989 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005990
Rambo Wanga1782702021-11-10 20:15:19 -08005991 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5992 /*message=*/ "iccOpenLogicalChannel");
5993
5994 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5995 // Verify that the callingPackage in the request belongs to the calling UID
5996 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5997
joonhunshin4ac60942023-11-15 15:23:39 +00005998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5999 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6000
Rambo Wanga1782702021-11-10 20:15:19 -08006001 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006002 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006003
Rambo Wanga1782702021-11-10 20:15:19 -08006004 private Phone getPhoneFromValidIccLogicalChannelRequest(
6005 @NonNull IccLogicalChannelRequest request, String message) {
6006 Phone phone;
6007 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, request.subId, message);
6010 phone = getPhoneFromSubId(request.subId);
6011 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6012 enforceModifyPermission();
6013 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6014 } else {
6015 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006016 }
Rambo Wanga1782702021-11-10 20:15:19 -08006017 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006018 }
6019
6020 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006021 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 final long identity = Binder.clearCallingIdentity();
6023 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006024 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6027 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006028 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6029 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 loge("The calling package is not allowed to access ISD-R.");
6031 throw new SecurityException(
6032 "The calling package is not allowed to access ISD-R.");
6033 }
Derek Tan740e1672017-06-27 14:56:27 -07006034 }
Derek Tan740e1672017-06-27 14:56:27 -07006035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006037 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6038 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 return response;
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006043 }
6044
6045 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006046 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6048 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6049
Rambo Wanga1782702021-11-10 20:15:19 -08006050 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6051 /*message=*/"iccCloseLogicalChannel");
6052
6053 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6054
6055 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006056 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006057
Rambo Wanga1782702021-11-10 20:15:19 -08006058 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6059 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006060 // before this feature is enabled, this API should only return false if
6061 // the operation fails instead of throwing runtime exception for
6062 // backward-compatibility.
6063 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6064 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006067 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006068 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 }
Chen Xue9d737e2022-01-01 23:41:31 -08006070 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006071 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006072 Boolean success = false;
6073 if (result instanceof RuntimeException) {
6074 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006075 if (shouldThrowExceptionOnFailure) {
6076 throw (RuntimeException) result;
6077 } else {
6078 return false;
6079 }
Chen Xue9d737e2022-01-01 23:41:31 -08006080 } else if (result instanceof Boolean) {
6081 success = (Boolean) result;
6082 } else {
6083 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6084 }
Rambo Wanga1782702021-11-10 20:15:19 -08006085 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 return success;
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090 }
6091
6092 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006093 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006094 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6096 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006097
6098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6099 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6100
Jordan Liu4c733742019-02-28 12:03:40 -08006101 if (DBG) {
6102 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6103 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6104 + p3 + " data=" + data);
6105 }
6106 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6107 command, p1, p2, p3, data);
6108 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006109
Jordan Liu4c733742019-02-28 12:03:40 -08006110 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006111 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006112 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006113 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006114
6115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6117 "iccTransmitApduLogicalChannelBySlot");
6118
Jordan Liu4c733742019-02-28 12:03:40 -08006119 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006120 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006121 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6122 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006123 }
6124 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006125 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6126 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006127 }
6128
6129 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6130 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 final long identity = Binder.clearCallingIdentity();
6132 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006133 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 return "";
6135 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006138 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6139 null /* workSource */);
6140 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 // Append the returned status code to the end of the response payload.
6143 String s = Integer.toHexString(
6144 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6145 if (response.payload != null) {
6146 s = IccUtils.bytesToHexString(response.payload) + s;
6147 }
6148 return s;
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006151 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006152 }
Jake Hambye994d462014-02-03 13:10:13 -08006153
Evan Charltonc66da362014-05-16 14:06:40 -07006154 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006155 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6156 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006160
6161 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6162 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6163
Jordan Liu4c733742019-02-28 12:03:40 -08006164 if (DBG) {
6165 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6166 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6167 }
6168 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6169 cla, command, p1, p2, p3, data);
6170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006171
Jordan Liu4c733742019-02-28 12:03:40 -08006172 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006173 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006174 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006175 enforceModifyPermission();
6176 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006177
6178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6179 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6180
Jordan Liu4c733742019-02-28 12:03:40 -08006181 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006182 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006183 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6184 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006185 }
6186
6187 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006188 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6189 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006190 }
6191
6192 // open APDU basic channel assuming the caller has sufficient permissions
6193 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6194 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6198 && TextUtils.equals(ISDR_AID, data)) {
6199 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006200 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6201 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 if (bestComponent == null
6203 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6204 loge("The calling package is not allowed to select ISD-R.");
6205 throw new SecurityException(
6206 "The calling package is not allowed to select ISD-R.");
6207 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006208 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006211 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6212 null /* workSource */);
6213 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 // Append the returned status code to the end of the response payload.
6216 String s = Integer.toHexString(
6217 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6218 if (response.payload != null) {
6219 s = IccUtils.bytesToHexString(response.payload) + s;
6220 }
6221 return s;
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006224 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006225 }
6226
6227 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006228 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006229 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6231 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006232
joonhunshin4ac60942023-11-15 15:23:39 +00006233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6234 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 final long identity = Binder.clearCallingIdentity();
6237 try {
6238 if (DBG) {
6239 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6240 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6241 }
6242
6243 IccIoResult response =
6244 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6245 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6246 subId);
6247
6248 if (DBG) {
6249 log("Exchange SIM_IO [R]" + response);
6250 }
6251
6252 byte[] result = null;
6253 int length = 2;
6254 if (response.payload != null) {
6255 length = 2 + response.payload.length;
6256 result = new byte[length];
6257 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6258 } else {
6259 result = new byte[length];
6260 }
6261
6262 result[length - 1] = (byte) response.sw2;
6263 result[length - 2] = (byte) response.sw1;
6264 return result;
6265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006267 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006268 }
6269
Nathan Haroldb3014052017-01-25 15:57:32 -08006270 /**
6271 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6272 * on a particular subscription
6273 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006274 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6275 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006277 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006278 return null;
6279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280
joonhunshin4ac60942023-11-15 15:23:39 +00006281 enforceTelephonyFeatureWithException(callingPackage,
6282 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 if (appType != TelephonyManager.APPTYPE_USIM
6287 && appType != TelephonyManager.APPTYPE_SIM) {
6288 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6289 return null;
6290 }
6291 Object response = sendRequest(
6292 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6293 if (response instanceof String[]) {
6294 return (String[]) response;
6295 }
yincheng zhao2737e882019-09-06 17:06:54 -07006296 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006298 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 } finally {
6300 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006301 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006302 }
6303
yincheng zhao2737e882019-09-06 17:06:54 -07006304 /**
6305 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6306 * subscription.
6307 *
6308 * @param subId the id of the subscription.
6309 * @param appType the uicc app type, must be USIM or SIM.
6310 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6311 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006312 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006313 * @return number of fplmns that is successfully written to the SIM.
6314 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006315 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6316 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6318 mApp, subId, "setForbiddenPlmns");
6319
joonhunshin4ac60942023-11-15 15:23:39 +00006320 enforceTelephonyFeatureWithException(callingPackage,
6321 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6322
yincheng zhao2737e882019-09-06 17:06:54 -07006323 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6324 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6325 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6326 }
6327 if (fplmns == null) {
6328 throw new IllegalArgumentException("Fplmn List provided is null");
6329 }
6330 for (String fplmn : fplmns) {
6331 if (!CellIdentity.isValidPlmn(fplmn)) {
6332 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6333 }
6334 }
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 Object response = sendRequest(
6338 CMD_SET_FORBIDDEN_PLMNS,
6339 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6340 subId);
6341 return (int) response;
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
6345 }
6346
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006347 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006348 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006351
joonhunshin4ac60942023-11-15 15:23:39 +00006352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6353 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6358 if (response.payload == null) {
6359 return "";
6360 }
Evan Charltonc66da362014-05-16 14:06:40 -07006361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 // Append the returned status code to the end of the response payload.
6363 String s = Integer.toHexString(
6364 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6365 s = IccUtils.bytesToHexString(response.payload) + s;
6366 return s;
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Evan Charltonc66da362014-05-16 14:06:40 -07006370 }
6371
Jake Hambye994d462014-02-03 13:10:13 -08006372 /**
6373 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6374 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6375 *
6376 * @param itemID the ID of the item to read
6377 * @return the NV item as a String, or null on error.
6378 */
6379 @Override
6380 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6383 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384
6385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006388 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6390 return value;
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Jake Hambye994d462014-02-03 13:10:13 -08006394 }
6395
6396 /**
6397 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6398 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6399 *
6400 * @param itemID the ID of the item to read
6401 * @param itemValue the value to write, as a String
6402 * @return true on success; false on any failure
6403 */
6404 @Override
6405 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6408 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6413 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006414 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6416 return success;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Jake Hambye994d462014-02-03 13:10:13 -08006420 }
6421
6422 /**
6423 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6424 * Used for device configuration by some CDMA operators.
6425 *
6426 * @param preferredRoamingList byte array containing the new PRL
6427 * @return true on success; false on any failure
6428 */
6429 @Override
6430 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6432 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433
6434 final long identity = Binder.clearCallingIdentity();
6435 try {
6436 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6437 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6438 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6439 return success;
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Jake Hambye994d462014-02-03 13:10:13 -08006443 }
6444
6445 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006446 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006447 * Used for device configuration by some CDMA operators.
6448 *
chen xu6dac5ab2018-10-26 17:39:23 -07006449 * @param slotIndex - device slot.
6450 *
Jake Hambye994d462014-02-03 13:10:13 -08006451 * @return true on success; false on any failure
6452 */
6453 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006454 public boolean resetModemConfig(int slotIndex) {
6455 Phone phone = PhoneFactory.getPhone(slotIndex);
6456 if (phone != null) {
6457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6458 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459
joonhunshin4ac60942023-11-15 15:23:39 +00006460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6461 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6462
chen xu6dac5ab2018-10-26 17:39:23 -07006463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6466 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6467 return success;
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 }
chen xu6dac5ab2018-10-26 17:39:23 -07006472 return false;
6473 }
6474
6475 /**
6476 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6477 *
6478 * @param slotIndex - device slot.
6479 *
6480 * @return true on success; false on any failure
6481 */
6482 @Override
6483 public boolean rebootModem(int slotIndex) {
6484 Phone phone = PhoneFactory.getPhone(slotIndex);
6485 if (phone != null) {
6486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6487 mApp, phone.getSubId(), "rebootModem");
6488
joonhunshin4ac60942023-11-15 15:23:39 +00006489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6490 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6491
chen xu6dac5ab2018-10-26 17:39:23 -07006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6495 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6496 return success;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006502 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006503
Brad Ebinger51f743a2017-01-23 13:50:20 -08006504 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006505 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6506 * {@link #disableIms(int)}.
6507 * @param slotIndex device slot.
6508 */
6509 public void resetIms(int slotIndex) {
6510 enforceModifyPermission();
6511
joonhunshin4ac60942023-11-15 15:23:39 +00006512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6513 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6514
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 if (mImsResolver == null) {
6518 // may happen if the does not support IMS.
6519 return;
6520 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006521 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526
6527 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006528 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6529 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006530 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006531 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533
6534 final long identity = Binder.clearCallingIdentity();
6535 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006536 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006537 // may happen if the device does not support IMS.
6538 return;
6539 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006540 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006544 }
6545
6546 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006547 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6548 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006549 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006550 public void disableIms(int slotId) {
6551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006555 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 // may happen if the device does not support IMS.
6557 return;
6558 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006559 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006563 }
6564
6565 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006566 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6567 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006568 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006569 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006570 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006575 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6577 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006578 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006579 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
6582 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006583 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006584 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006585 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6586 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006587 @Override
6588 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006589 enforceModifyPermission();
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006594 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
6598 }
6599
6600 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006601 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006602 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006603 */
6604 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006609 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006610 // may happen if the device does not support IMS.
6611 return null;
6612 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006613 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006617 }
6618
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006619 /**
6620 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006621 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006622 */
6623 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625
6626 final long identity = Binder.clearCallingIdentity();
6627 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006628 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006629 // may happen if the device does not support IMS.
6630 return null;
6631 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006632 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006636 }
6637
Brad Ebinger884c07b2018-02-15 16:17:40 -08006638 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006639 * Sets the ImsService Package Name that Telephony will bind to.
6640 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006641 * @param slotIndex the slot ID that the ImsService should bind for.
6642 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006643 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 * @param featureTypes An integer array of feature types associated with a packageName.
6645 * @param packageName The name of the package that the current configuration will be replaced
6646 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006647 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006648 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6650 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006653 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 final long identity = Binder.clearCallingIdentity();
6656 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006658 // may happen if the device does not support IMS.
6659 return false;
6660 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006661 Map<Integer, String> featureConfig = new HashMap<>();
6662 for (int featureType : featureTypes) {
6663 featureConfig.put(featureType, packageName);
6664 }
6665 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6666 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006670 }
6671
6672 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006673 * Clears any carrier ImsService overrides for the slot index specified that were previously
6674 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6675 *
6676 * This should only be used for testing.
6677 *
6678 * @param slotIndex the slot ID that the ImsService should bind for.
6679 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6680 */
6681 @Override
6682 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6684 "clearCarrierImsServiceOverride");
6685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006686 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 if (mImsResolver == null) {
6691 // may happen if the device does not support IMS.
6692 return false;
6693 }
6694 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
6698 }
6699
6700 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006701 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006702 *
6703 * @param slotId The slot that the ImsService is associated with.
6704 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6705 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006706 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006707 * @return the package name of the ImsService configuration.
6708 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006709 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6710 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006711 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6713 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006718 // may happen if the device does not support IMS.
6719 return "";
6720 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006721 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006722 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6723 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006727 }
6728
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006729 /**
6730 * Get the MmTelFeature state associated with the requested subscription id.
6731 * @param subId The subscription that the MmTelFeature is associated with.
6732 * @param callback A callback with an integer containing the
6733 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6734 */
6735 @Override
6736 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6737 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6740 "IMS not available on device.");
6741 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006742 final long token = Binder.clearCallingIdentity();
6743 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006744 int slotId = getSlotIndex(subId);
6745 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6746 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6747 + subId + "'");
6748 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6749 }
6750 verifyImsMmTelConfiguredOrThrow(slotId);
6751 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6752 try {
6753 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6754 } catch (RemoteException e) {
6755 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6756 + "Ignore");
6757 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006758 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006759 } catch (ImsException e) {
6760 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006761 } finally {
6762 Binder.restoreCallingIdentity(token);
6763 }
6764 }
6765
Daniel Brightbb5840b2021-01-12 15:48:18 -08006766 /**
6767 * Sets the ims registration state on all valid {@link Phone}s.
6768 */
6769 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006770 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771
6772 final long identity = Binder.clearCallingIdentity();
6773 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006774 // NOTE: Before S, this method only set the default phone.
6775 for (final Phone phone : PhoneFactory.getPhones()) {
6776 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6777 phone.setImsRegistrationState(registered);
6778 }
6779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
Wink Saville36469e72014-06-11 15:17:00 -07006783 }
6784
6785 /**
Stuart Scott54788802015-03-30 13:18:01 -07006786 * Set the network selection mode to automatic.
6787 *
6788 */
6789 @Override
6790 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6792 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
joonhunshin4ac60942023-11-15 15:23:39 +00006794 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6795 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
6798 try {
shilufc958392020-01-20 11:36:01 -08006799 if (!isActiveSubscription(subId)) {
6800 return;
6801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006803 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6804 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
Stuart Scott54788802015-03-30 13:18:01 -07006808 }
6809
Jack Yud10cdd42020-09-28 20:28:01 -07006810 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006811 * Ask the radio to connect to the input network and change selection mode to manual.
6812 *
6813 * @param subId the id of the subscription.
6814 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6815 * the operator to attach to.
6816 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6817 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6818 * normal network selection next time.
6819 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006820 */
6821 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006822 public boolean setNetworkSelectionModeManual(
6823 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6825 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006826
joonhunshin4ac60942023-11-15 15:23:39 +00006827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6828 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6829
Jack Yu285100e2022-12-02 22:48:35 -08006830 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006831 if (!isActiveSubscription(subId)) {
6832 return false;
6833 }
6834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006836 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006838 if (DBG) {
6839 log("setNetworkSelectionModeManual: subId: " + subId
6840 + " operator: " + operatorInfo);
6841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006846 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006847 /**
shilu84f6e8b2019-12-19 13:58:01 -08006848 * Get the manual network selection
6849 *
6850 * @param subId the id of the subscription.
6851 *
6852 * @return the previously saved user selected PLMN
6853 */
6854 @Override
6855 public String getManualNetworkSelectionPlmn(int subId) {
6856 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006857 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6858 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006859
joonhunshin4ac60942023-11-15 15:23:39 +00006860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6862
shilu84f6e8b2019-12-19 13:58:01 -08006863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006866 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006867 }
6868
6869 final Phone phone = getPhone(subId);
6870 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006871 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006872 }
6873 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6874 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006875 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006880
6881 /**
6882 * Scans for available networks.
6883 */
6884 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006885 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6886 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6888 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006889 LocationAccessPolicy.LocationPermissionResult locationResult =
6890 LocationAccessPolicy.checkLocationPermission(mApp,
6891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6892 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006893 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006894 .setCallingPid(Binder.getCallingPid())
6895 .setCallingUid(Binder.getCallingUid())
6896 .setMethod("getCellNetworkScanResults")
6897 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6899 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006900 .build());
6901 switch (locationResult) {
6902 case DENIED_HARD:
6903 throw new SecurityException("Not allowed to access scan results -- location");
6904 case DENIED_SOFT:
6905 return null;
6906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907
Pengquan Menga1bb6272018-09-06 09:59:22 -07006908 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 try {
6910 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006911 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006916 }
6917
6918 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006919 * Get the call forwarding info, given the call forwarding reason.
6920 */
6921 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006922 public void getCallForwarding(int subId, int callForwardingReason,
6923 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006924 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006925
6926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6927 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6928
Shuo Qian4a594052020-01-23 11:59:30 -08006929 long identity = Binder.clearCallingIdentity();
6930 try {
6931 if (DBG) {
6932 log("getCallForwarding: subId " + subId
6933 + " callForwardingReason" + callForwardingReason);
6934 }
Hall Liu27d24262020-09-18 19:04:59 -07006935
6936 Phone phone = getPhone(subId);
6937 if (phone == null) {
6938 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006939 callback.onError(
6940 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006941 } catch (RemoteException e) {
6942 // ignore
6943 }
6944 return;
6945 }
6946
6947 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6948 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6949 @Override
6950 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6951 try {
6952 callback.onCallForwardingInfoAvailable(info);
6953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 }
6957
6958 @Override
6959 public void onError(int error) {
6960 try {
6961 callback.onError(error);
6962 } catch (RemoteException e) {
6963 // ignore
6964 }
6965 }
6966 });
6967 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
6973 /**
6974 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6975 * reason, the number to forward, and the timeout before the forwarding is attempted.
6976 */
6977 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006978 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6979 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006980 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006981
6982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6983 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6984
Shuo Qian4a594052020-01-23 11:59:30 -08006985 long identity = Binder.clearCallingIdentity();
6986 try {
6987 if (DBG) {
6988 log("setCallForwarding: subId " + subId
6989 + " callForwardingInfo" + callForwardingInfo);
6990 }
Hall Liu27d24262020-09-18 19:04:59 -07006991
6992 Phone phone = getPhone(subId);
6993 if (phone == null) {
6994 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006995 callback.accept(
6996 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006997 } catch (RemoteException e) {
6998 // ignore
6999 }
7000 return;
7001 }
7002
7003 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7004 FunctionalUtils.ignoreRemoteException(callback::accept));
7005
7006 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 }
7011
7012 /**
Hall Liu27d24262020-09-18 19:04:59 -07007013 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007014 */
7015 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007016 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007017 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007018
7019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7020 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7021
Shuo Qian4a594052020-01-23 11:59:30 -08007022 long identity = Binder.clearCallingIdentity();
7023 try {
Hall Liu27d24262020-09-18 19:04:59 -07007024 Phone phone = getPhone(subId);
7025 if (phone == null) {
7026 try {
7027 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7028 } catch (RemoteException e) {
7029 // ignore
7030 }
7031 return;
7032 }
SongFerngWang0e767992021-03-31 22:08:45 +08007033 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7034 PersistableBundle c = configManager.getConfigForSubId(subId);
7035 boolean requireUssd = c.getBoolean(
7036 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007037
Shuo Qian4a594052020-01-23 11:59:30 -08007038 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007039 if (requireUssd) {
7040 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7041 getSubscriptionCarrierId(subId));
7042 String newUssdCommand = "";
7043 try {
7044 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007045 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007046 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7047 } catch (NullPointerException e) {
7048 loge("Failed to generate USSD number" + e);
7049 }
7050 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7051 mMainThreadHandler, callback, carrierXmlParser,
7052 CarrierXmlParser.SsEntry.SSAction.QUERY);
7053 final String ussdCommand = newUssdCommand;
7054 Executors.newSingleThreadExecutor().execute(() -> {
7055 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7056 });
7057 } else {
7058 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7059 callback::accept);
7060 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7061 }
Shuo Qian4a594052020-01-23 11:59:30 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
7065 }
7066
7067 /**
Hall Liu27d24262020-09-18 19:04:59 -07007068 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007069 */
7070 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007071 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007072 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007073
7074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7075 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7076
Shuo Qian4a594052020-01-23 11:59:30 -08007077 long identity = Binder.clearCallingIdentity();
7078 try {
Hall Liu27d24262020-09-18 19:04:59 -07007079 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7080
7081 Phone phone = getPhone(subId);
7082 if (phone == null) {
7083 try {
7084 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7085 } catch (RemoteException e) {
7086 // ignore
7087 }
7088 return;
7089 }
7090
SongFerngWang0e767992021-03-31 22:08:45 +08007091 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7092 PersistableBundle c = configManager.getConfigForSubId(subId);
7093 boolean requireUssd = c.getBoolean(
7094 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007095
SongFerngWang0e767992021-03-31 22:08:45 +08007096 if (DBG) log("getCallWaitingStatus: subId " + subId);
7097 if (requireUssd) {
7098 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7099 getSubscriptionCarrierId(subId));
7100 CarrierXmlParser.SsEntry.SSAction ssAction =
7101 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7102 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7103 String newUssdCommand = "";
7104 try {
7105 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007106 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007107 .makeCommand(ssAction, null);
7108 } catch (NullPointerException e) {
7109 loge("Failed to generate USSD number" + e);
7110 }
7111 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7112 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7113 final String ussdCommand = newUssdCommand;
7114 Executors.newSingleThreadExecutor().execute(() -> {
7115 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7116 });
7117 } else {
7118 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7119 FunctionalUtils.ignoreRemoteException(callback::accept));
7120
7121 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7122 }
Shuo Qian4a594052020-01-23 11:59:30 -08007123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
7126 }
7127
7128 /**
yinxub1bed742017-04-17 11:45:04 -07007129 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007130 *
yinxub1bed742017-04-17 11:45:04 -07007131 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007132 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7133 * location related information which will be sent if the caller already possess
7134 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007135 * @param request contains the radio access networks with bands/channels to scan
7136 * @param messenger callback messenger for scan results or errors
7137 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007138 * @return the id of the requested scan which can be used to stop the scan.
7139 */
7140 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007141 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7142 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007143 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7145 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007146 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007147 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7148 if (!renounceFineLocationAccess) {
7149 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007150 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7151 .setCallingPackage(callingPackage)
7152 .setCallingFeatureId(callingFeatureId)
7153 .setCallingPid(Binder.getCallingPid())
7154 .setCallingUid(Binder.getCallingUid())
7155 .setMethod("requestNetworkScan")
7156 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7158 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7159 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007160 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007162 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7163 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007164 if (e != null) {
7165 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7166 throw e;
7167 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007168 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007169 return TelephonyScanManager.INVALID_SCAN_ID;
7170 }
7171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 }
joonhunshin4ac60942023-11-15 15:23:39 +00007173
7174 enforceTelephonyFeatureWithException(callingPackage,
7175 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7176
Hall Liu912dfd32019-04-25 14:02:26 -07007177 int callingUid = Binder.getCallingUid();
7178 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007182 renounceFineLocationAccess, request, messenger, binder,
7183 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007184 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
yinxu504e1392017-04-12 16:03:22 -07007188 }
7189
Hall Liub2ac8ef2019-02-28 15:56:23 -08007190 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007191 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007192 boolean hasCarrierPriv;
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7196 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Hall Liu558027f2019-05-15 19:14:05 -07007200 boolean hasNetworkScanPermission =
7201 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007202 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007203
7204 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7205 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7206 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007207 }
7208
7209 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7210 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007211 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7212 return new SecurityException("Specific channels must not be"
7213 + " scanned without location access.");
7214 }
7215 }
7216 }
7217
Hall Liub2ac8ef2019-02-28 15:56:23 -08007218 return null;
7219 }
7220
yinxu504e1392017-04-12 16:03:22 -07007221 /**
7222 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007223 *
7224 * @param subId id of the subscription
7225 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007226 */
7227 @Override
7228 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7230 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231
Hall Liu912dfd32019-04-25 14:02:26 -07007232 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007235 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
yinxu504e1392017-04-12 16:03:22 -07007239 }
7240
7241 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007242 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007243 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007244 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007245 */
7246 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007247 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007248 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007249 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007250 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
joonhunshin4ac60942023-11-15 15:23:39 +00007252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7253 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 final long identity = Binder.clearCallingIdentity();
7256 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007257 if (DBG) log("getAllowedNetworkTypesBitmask");
7258 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7259 int networkTypesBitmask = (result != null ? result[0] : -1);
7260 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7261 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007265 }
7266
7267 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007268 * Get the allowed network types for certain reason.
7269 *
7270 * @param subId the id of the subscription.
7271 * @param reason the reason the allowed network type change is taking place
7272 * @return the allowed network types.
7273 */
7274 @Override
7275 public long getAllowedNetworkTypesForReason(int subId,
7276 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007278 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007279
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007280 if (!mApp.getResources().getBoolean(
7281 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7283 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7284 "getAllowedNetworkTypesForReason");
7285 }
joonhunshin4ac60942023-11-15 15:23:39 +00007286
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007287 final long identity = Binder.clearCallingIdentity();
7288 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007289 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007296 * Enable/Disable E-UTRA-NR Dual Connectivity
7297 * @param subId subscription id of the sim card
7298 * @param nrDualConnectivityState expected NR dual connectivity state
7299 * This can be passed following states
7300 * <ol>
7301 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7302 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7303 * <li>Disable NR dual connectivity and force secondary cell to be released
7304 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7305 * </ol>
7306 * @return operation result.
7307 */
7308 @Override
7309 public int setNrDualConnectivityState(int subId,
7310 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7312 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007313 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007314 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7315 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7316 }
7317
Sooraj Sasindran37444802020-08-11 10:40:43 -07007318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7322 nrDualConnectivityState, subId,
7323 workSource);
7324 if (DBG) log("enableNRDualConnectivity result: " + result);
7325 return result;
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
7329 }
7330
7331 /**
7332 * Is E-UTRA-NR Dual Connectivity enabled
7333 * @return true if dual connectivity is enabled else false
7334 */
7335 @Override
7336 public boolean isNrDualConnectivityEnabled(int subId) {
7337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007339 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007340 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007341 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7342 return false;
7343 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7348 null, subId, workSource);
7349 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7350 return isEnabled;
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
7354 }
7355
7356 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007357 * Set the allowed network types of the device and
7358 * provide the reason triggering the allowed network change.
7359 *
7360 * @param subId the id of the subscription.
7361 * @param reason the reason the allowed network type change is taking place
7362 * @param allowedNetworkTypes the allowed network types.
7363 * @return true on success; false on any failure.
7364 */
7365 @Override
7366 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007367 @TelephonyManager.AllowedNetworkTypesReason int reason,
7368 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7370 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007371 // If the caller only has carrier privileges, then they should not be able to override
7372 // any network types which were set for security reasons.
7373 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7374 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007375 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007376 throw new SecurityException(
7377 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007378 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007379 }
joonhunshin4ac60942023-11-15 15:23:39 +00007380
7381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7382 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7383
SongFerngWang3ef3e072020-12-21 16:41:52 +08007384 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007385 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007386 return false;
7387 }
7388 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7389 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007390 return false;
7391 }
7392
Jack Yu5b494332023-01-23 18:18:04 +00007393 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7394 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007395
Jack Yue37dd262022-12-16 11:53:37 -08007396 Phone phone = getPhone(subId);
7397 if (phone == null) {
7398 return false;
7399 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007400
Jack Yue37dd262022-12-16 11:53:37 -08007401 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007402 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007403 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007404 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007405
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007406 final long identity = Binder.clearCallingIdentity();
7407 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007408 Boolean success = (Boolean) sendRequest(
7409 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7410 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7411
7412 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7413 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
7417 }
7418
7419 /**
Miaoa84611c2019-03-15 09:21:10 +08007420 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007421 *
Miaoa84611c2019-03-15 09:21:10 +08007422 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007423 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007424 * @hide
7425 */
7426 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007427 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007428 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007429
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007430 if (!mApp.getResources().getBoolean(
7431 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7433 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7434 }
joonhunshin4ac60942023-11-15 15:23:39 +00007435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007437 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 try {
Miaoa84611c2019-03-15 09:21:10 +08007439 if (phone != null) {
7440 return phone.hasMatchedTetherApnSetting();
7441 } else {
7442 return false;
7443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007446 }
Junda Liu475951f2014-11-07 16:45:03 -08007447 }
7448
7449 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007450 * Get the user enabled state of Mobile Data.
7451 *
7452 * TODO: remove and use isUserDataEnabled.
7453 * This can't be removed now because some vendor codes
7454 * calls through ITelephony directly while they should
7455 * use TelephonyManager.
7456 *
7457 * @return true on enabled
7458 */
7459 @Override
7460 public boolean getDataEnabled(int subId) {
7461 return isUserDataEnabled(subId);
7462 }
7463
7464 /**
7465 * Get whether mobile data is enabled per user setting.
7466 *
7467 * There are other factors deciding whether mobile data is actually enabled, but they are
7468 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007469 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007470 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7471 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007472 *
7473 * @return {@code true} if data is enabled else {@code false}
7474 */
7475 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007476 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007477 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007478 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007479 try {
7480 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7481 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007482 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007483 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7484 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007485 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007487 mApp, subId, functionName);
7488
Robert Greenwalt646120a2014-05-23 11:54:03 -07007489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
Jack Yu285100e2022-12-02 22:48:35 -08007493 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7495 Phone phone = PhoneFactory.getPhone(phoneId);
7496 if (phone != null) {
7497 boolean retVal = phone.isUserDataEnabled();
7498 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7499 return retVal;
7500 } else {
7501 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7502 return false;
7503 }
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007506 }
7507 }
7508
7509 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007510 * Checks if the device is capable of mobile data by considering whether whether the
7511 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7512 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007513 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007514 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007515 */
7516 @Override
7517 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007519 try {
7520 try {
7521 mApp.enforceCallingOrSelfPermission(
7522 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007524 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007525 try {
7526 mApp.enforceCallingOrSelfPermission(
7527 android.Manifest.permission.READ_PHONE_STATE,
7528 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007529 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007530 mApp.enforceCallingOrSelfPermission(
7531 permission.READ_BASIC_PHONE_STATE, functionName);
7532 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007533 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007534 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007535 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537
joonhunshin4ac60942023-11-15 15:23:39 +00007538 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7539 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
7542 try {
Jack Yu285100e2022-12-02 22:48:35 -08007543 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007545 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007546 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007547 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 return retVal;
7549 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007550 if (DBG) {
7551 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7552 + subId + " retVal=false");
7553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 return false;
7555 }
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007558 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007559 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007560
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007561 /**
7562 * Check if data is enabled for a specific reason
7563 * @param subId Subscription index
7564 * @param reason the reason the data enable change is taking place
7565 * @return {@code true} if the overall data is enabled; {@code false} if not.
7566 */
7567 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007568 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007569 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007570 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007571 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007572 try {
7573 mApp.enforceCallingOrSelfPermission(
7574 android.Manifest.permission.ACCESS_NETWORK_STATE,
7575 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007576 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007577 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7578 functionName);
7579 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007580 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007581 try {
7582 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007583 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007584 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007586 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007587 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007588 }
7589
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007590 if (!mApp.getResources().getBoolean(
7591 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7592 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7593 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7594 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
Jack Yu285100e2022-12-02 22:48:35 -08007598 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007599 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007600 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007601 + " reason=" + reason);
7602 }
7603 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007604 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007605 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007606 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007607 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007608 return retVal;
7609 } else {
7610 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007611 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007612 + subId + " retVal=false");
7613 }
7614 return false;
7615 }
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
7620
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007621 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007622 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007623 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7624 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7625
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007626 // No permission needed; this only lets the caller inspect their own status.
7627 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007628 }
Junda Liu29340342014-07-10 15:23:27 -07007629
7630 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007631 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007632 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007633
7634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7635 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7636
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007637 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7638 }
7639
7640 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7641 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007642 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007643 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007644 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7645 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007646 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7647 if (cpt == null) {
7648 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007649 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7650 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007651 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007652 }
7653
7654 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007655 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007656 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007657
7658 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7659 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7660
chen xuf7e9fe82019-05-09 19:31:02 -07007661 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007662 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007663 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007664 Phone phone = getPhone(subId);
7665 if (phone == null) {
7666 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7668 }
7669 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7670 if (cpt == null) {
7671 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007672 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7673 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007674 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007675 }
7676
7677 @Override
7678 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007679 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007680
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007681 if (!mApp.getResources().getBoolean(
7682 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7684 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7685 "checkCarrierPrivilegesForPackageAnyPhone");
7686 }
joonhunshin4ac60942023-11-15 15:23:39 +00007687
Rambo Wange7209ce2022-02-23 13:41:02 -08007688 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7689 }
7690
7691 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007693 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007694 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007695 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007696 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7697 Phone phone = PhoneFactory.getPhone(phoneId);
7698 if (phone == null) {
7699 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007700 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7702 if (cpt == null) {
7703 continue;
7704 }
7705 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007706 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7707 break;
7708 }
7709 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007710 return result;
Junda Liu29340342014-07-10 15:23:27 -07007711 }
Derek Tan89e89d42014-07-08 17:00:10 -07007712
7713 @Override
Junda Liue64de782015-04-16 17:19:16 -07007714 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007715 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007716
7717 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7718 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7719 "getCarrierPackageNamesForIntentAndPhone");
7720
Rambo Wang8a247eb2022-02-08 21:11:18 +00007721 Phone phone = PhoneFactory.getPhone(phoneId);
7722 if (phone == null) {
7723 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007724 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007725 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7726 if (cpt == null) {
7727 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007728 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007729 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007730 }
7731
Amith Yamasani6e118872016-02-19 12:53:51 -08007732 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007733 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007734 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007735 Phone phone = PhoneFactory.getPhone(phoneId);
7736 if (phone == null) {
7737 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007738 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007739 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7740 if (cpt == null) {
7741 return Collections.emptyList();
7742 }
7743 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007744 }
7745
chen xuf7e9fe82019-05-09 19:31:02 -07007746 @Override
7747 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007748 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007749
7750 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7751 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7752 "getPackagesWithCarrierPrivilegesForAllPhones");
7753
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007754 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007755 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007756 try {
7757 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7758 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7759 }
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007762 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007763 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007764 }
7765
Rambo Wang6812ffb2022-03-15 16:54:17 -07007766 @Override
7767 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7768 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7769
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007770 if (!mApp.getResources().getBoolean(
7771 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7773 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7774 "getCarrierServicePackageNameForLogicalSlot");
7775 }
joonhunshin4ac60942023-11-15 15:23:39 +00007776
Rambo Wang6812ffb2022-03-15 16:54:17 -07007777 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7778 if (phone == null) {
7779 return null;
7780 }
7781 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7782 if (cpt == null) {
7783 return null;
7784 }
7785 return cpt.getCarrierServicePackageName();
7786 }
7787
Wink Savilleb564aae2014-10-23 10:18:09 -07007788 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007789 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007790 UiccPort port = phone == null ? null : phone.getUiccPort();
7791 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007792 return null;
7793 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007794 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007795 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007796 return null;
7797 }
7798 return iccId;
7799 }
7800
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007801 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007802 public void setCallComposerStatus(int subId, int status) {
7803 enforceModifyPermission();
7804
joonhunshin4ac60942023-11-15 15:23:39 +00007805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7806 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7807
Shuo Qiane4e11672020-12-15 22:15:33 -08007808 final long identity = Binder.clearCallingIdentity();
7809 try {
7810 Phone phone = getPhone(subId);
7811 if (phone != null) {
7812 Phone defaultPhone = phone.getImsPhone();
7813 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7814 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7815 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007816 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7817 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007818 }
7819 }
Shuo Qian284ae752020-12-22 19:10:14 -08007820 } catch (ImsException e) {
7821 throw new ServiceSpecificException(e.getCode());
7822 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007823 Binder.restoreCallingIdentity(identity);
7824 }
7825 }
7826
7827 @Override
7828 public int getCallComposerStatus(int subId) {
7829 enforceReadPrivilegedPermission("getCallComposerStatus");
7830
joonhunshin4ac60942023-11-15 15:23:39 +00007831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7832 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7833
Shuo Qiane4e11672020-12-15 22:15:33 -08007834 final long identity = Binder.clearCallingIdentity();
7835 try {
7836 Phone phone = getPhone(subId);
7837 if (phone != null) {
7838 Phone defaultPhone = phone.getImsPhone();
7839 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7840 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7841 return imsPhone.getCallComposerStatus();
7842 }
7843 }
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7848 }
7849
7850 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007851 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7852 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007853 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007854 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007855
joonhunshin4ac60942023-11-15 15:23:39 +00007856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7857 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7858 "setLine1NumberForDisplayForSubscriber");
7859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 final long identity = Binder.clearCallingIdentity();
7861 try {
7862 final String iccId = getIccId(subId);
7863 final Phone phone = getPhone(subId);
7864 if (phone == null) {
7865 return false;
7866 }
arunvoddub1365e62024-07-31 09:42:31 +00007867 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7868 Rlog.e(LOG_TAG, "Number is too long");
7869 return false;
7870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 final String subscriberId = phone.getSubscriberId();
7872
7873 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007874 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 + subscriberId + " to " + number);
7876 }
7877
7878 if (TextUtils.isEmpty(iccId)) {
7879 return false;
7880 }
7881
7882 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7883
7884 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7885 if (alphaTag == null) {
7886 editor.remove(alphaTagPrefKey);
7887 } else {
7888 editor.putString(alphaTagPrefKey, alphaTag);
7889 }
7890
7891 // Record both the line number and IMSI for this ICCID, since we need to
7892 // track all merged IMSIs based on line number
7893 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7894 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7895 if (number == null) {
7896 editor.remove(numberPrefKey);
7897 editor.remove(subscriberPrefKey);
7898 } else {
7899 editor.putString(numberPrefKey, number);
7900 editor.putString(subscriberPrefKey, subscriberId);
7901 }
7902
7903 editor.commit();
7904 return true;
7905 } finally {
7906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007907 }
Derek Tan7226c842014-07-02 17:42:23 -07007908 }
7909
7910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007911 public String getLine1NumberForDisplay(int subId, String callingPackage,
7912 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007913 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007915 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007916 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007917 return null;
7918 }
Derek Tan97ebb422014-09-05 16:55:38 -07007919
joonhunshin4ac60942023-11-15 15:23:39 +00007920 enforceTelephonyFeatureWithException(callingPackage,
7921 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 String iccId = getIccId(subId);
7926 if (iccId != null) {
7927 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7928 if (DBG_MERGE) {
7929 log("getLine1NumberForDisplay returning "
7930 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7931 }
7932 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7935 return null;
7936 } finally {
7937 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007938 }
Derek Tan7226c842014-07-02 17:42:23 -07007939 }
7940
7941 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007942 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7943 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007945 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007946 return null;
7947 }
Derek Tan97ebb422014-09-05 16:55:38 -07007948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949 final long identity = Binder.clearCallingIdentity();
7950 try {
7951 String iccId = getIccId(subId);
7952 if (iccId != null) {
7953 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7954 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7955 }
7956 return null;
7957 } finally {
7958 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007959 }
Derek Tan7226c842014-07-02 17:42:23 -07007960 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007961
7962 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007963 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7964 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007965 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7966 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007968 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007969 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007970 return null;
7971 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007972
Jordan Liub49b04b2019-05-06 14:45:15 -07007973 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7974 // the process, where TelephonyManager was instantiated.
7975 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007976 final long identity = Binder.clearCallingIdentity();
7977 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007978 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979 final TelephonyManager tele = TelephonyManager.from(context);
7980 final SubscriptionManager sub = SubscriptionManager.from(context);
7981
7982 // Figure out what subscribers are currently active
7983 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984
Jordan Liub49b04b2019-05-06 14:45:15 -07007985 // Only consider subs which match the current subId
7986 // This logic can be simplified. See b/131189269 for progress.
7987 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007988 activeSubscriberIds.add(tele.getSubscriberId(subId));
7989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990
7991 // First pass, find a number override for an active subscriber
7992 String mergeNumber = null;
7993 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7994 for (String key : prefs.keySet()) {
7995 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7996 final String subscriberId = (String) prefs.get(key);
7997 if (activeSubscriberIds.contains(subscriberId)) {
7998 final String iccId = key.substring(
7999 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8000 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8001 mergeNumber = (String) prefs.get(numberKey);
8002 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008003 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 + " for active subscriber " + subscriberId);
8005 }
8006 if (!TextUtils.isEmpty(mergeNumber)) {
8007 break;
8008 }
8009 }
8010 }
8011 }
8012
8013 // Shortcut when no active merged subscribers
8014 if (TextUtils.isEmpty(mergeNumber)) {
8015 return null;
8016 }
8017
8018 // Second pass, find all subscribers under that line override
8019 final ArraySet<String> result = new ArraySet<>();
8020 for (String key : prefs.keySet()) {
8021 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8022 final String number = (String) prefs.get(key);
8023 if (mergeNumber.equals(number)) {
8024 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8025 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8026 final String subscriberId = (String) prefs.get(subscriberKey);
8027 if (!TextUtils.isEmpty(subscriberId)) {
8028 result.add(subscriberId);
8029 }
8030 }
8031 }
8032 }
8033
8034 final String[] resultArray = result.toArray(new String[result.size()]);
8035 Arrays.sort(resultArray);
8036 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008037 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8039 }
8040 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008041 } finally {
8042 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008043 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008044 }
8045
8046 @Override
zoey chen38003472019-12-13 17:16:31 +08008047 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8048 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008049
joonhunshin4ac60942023-11-15 15:23:39 +00008050 enforceTelephonyFeatureWithException(callingPackage,
8051 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8052
Malcolm Chen6ca97372019-07-01 16:28:21 -07008053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 final TelephonyManager telephonyManager = mApp.getSystemService(
8056 TelephonyManager.class);
8057 String subscriberId = telephonyManager.getSubscriberId(subId);
8058 if (subscriberId == null) {
8059 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008060 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008061 + subId);
8062 }
8063 return null;
8064 }
8065
Jack Yu3beaf9d2023-04-14 09:17:27 -07008066 final SubscriptionInfo info = getSubscriptionManagerService()
8067 .getSubscriptionInfo(subId);
8068 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008069 // If it doesn't belong to any group, return just subscriberId of itself.
8070 if (groupUuid == null) {
8071 return new String[]{subscriberId};
8072 }
8073
8074 // Get all subscriberIds from the group.
8075 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008076 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8077 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8078 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008079 for (SubscriptionInfo subInfo : groupInfos) {
8080 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8081 if (subscriberId != null) {
8082 mergedSubscriberIds.add(subscriberId);
8083 }
8084 }
8085
8086 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8087 } finally {
8088 Binder.restoreCallingIdentity(identity);
8089
8090 }
8091 }
8092
8093 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008094 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008095 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008096 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097
joonhunshin4ac60942023-11-15 15:23:39 +00008098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8099 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 final Phone phone = getPhone(subId);
8104 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008108 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008109
8110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008111 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008112 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8113 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008114 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8115 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 final Phone phone = getPhone(subId);
8120 if (phone == null) {
8121 return false;
8122 }
8123 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8124 cdmaNonRoamingList);
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008127 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008128 }
8129
8130 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008131 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008132 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008133 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008134 if (phone == null) {
8135 return raf;
8136 }
8137
Shuo Qiandee53402020-05-29 14:08:15 -07008138 try {
8139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008140 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008141 mApp, phone.getSubId(), "getRadioAccessFamily");
8142 } catch (SecurityException e) {
8143 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8144 throw e;
8145 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008146
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008147 if (!mApp.getResources().getBoolean(
8148 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8149 enforceTelephonyFeatureWithException(callingPackage,
8150 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8151 }
joonhunshin4ac60942023-11-15 15:23:39 +00008152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 final long identity = Binder.clearCallingIdentity();
8154 try {
chen xub97461a2018-10-26 14:17:57 -07008155 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156 } finally {
8157 Binder.restoreCallingIdentity(identity);
8158 }
chen xub97461a2018-10-26 14:17:57 -07008159 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008160 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008161
8162 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008163 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008164 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008165 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8166 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008167 enforceTelephonyFeatureWithException(callingPackage,
8168 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8169
Hall Liu82694d52020-12-11 18:22:04 -08008170 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008171 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008172 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8173 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008174 if (!dialerRoleHolders.contains(callingPackage)) {
8175 throw new SecurityException("App must be the dialer role holder to"
8176 + " upload a call composer pic");
8177 }
8178
8179 Executors.newSingleThreadExecutor().execute(() -> {
8180 ByteArrayOutputStream output = new ByteArrayOutputStream(
8181 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8182 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8183 boolean readUntilEnd = false;
8184 int totalBytesRead = 0;
8185 byte[] buffer = new byte[16 * 1024];
8186 while (true) {
8187 int numRead;
8188 try {
8189 numRead = input.read(buffer);
8190 } catch (IOException e) {
8191 try {
8192 fd.checkError();
8193 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8194 null);
8195 } catch (IOException e1) {
8196 // This means that the other side closed explicitly with an error. If this
8197 // happens, log and ignore.
8198 loge("Remote end of call composer picture pipe closed: " + e1);
8199 }
8200 break;
8201 }
8202 if (numRead == -1) {
8203 readUntilEnd = true;
8204 break;
8205 }
8206 totalBytesRead += numRead;
8207 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8208 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8209 try {
8210 input.close();
8211 } catch (IOException e) {
8212 // ignore
8213 }
8214 break;
8215 }
8216 output.write(buffer, 0, numRead);
8217 }
8218 // Generally, the remote end will close the file descriptors. The only case where we
8219 // close is above, where the picture size is too big.
8220
8221 try {
8222 fd.checkError();
8223 } catch (IOException e) {
8224 loge("Remote end for call composer closed with an error: " + e);
8225 return;
8226 }
8227
Hall Liuaa4211e2021-01-20 15:43:39 -08008228 if (!readUntilEnd) {
8229 loge("Did not finish reading entire image; aborting");
8230 return;
8231 }
Hall Liu82694d52020-12-11 18:22:04 -08008232
Hall Liuaa4211e2021-01-20 15:43:39 -08008233 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8234 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8235 new CallComposerPictureTransfer.Factory() {},
8236 imageData,
8237 (result) -> {
8238 if (result.first != null) {
8239 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8240 Bundle outputResult = new Bundle();
8241 outputResult.putParcelable(
8242 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8243 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8244 outputResult);
8245 } else {
8246 callback.send(result.second, null);
8247 }
8248 }
8249 );
Hall Liu82694d52020-12-11 18:22:04 -08008250 });
8251 }
8252
8253 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008254 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257
joonhunshin4ac60942023-11-15 15:23:39 +00008258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8259 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 final long identity = Binder.clearCallingIdentity();
8262 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008263 ImsManager.getInstance(defaultPhone.getContext(),
8264 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008268 }
8269
8270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008271 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008272 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8274 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008275 return false;
8276 }
Svet Ganovb320e182015-04-16 12:30:10 -07008277
joonhunshin4ac60942023-11-15 15:23:39 +00008278 enforceTelephonyFeatureWithException(callingPackage,
8279 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 final long identity = Binder.clearCallingIdentity();
8282 try {
8283 // Check the user preference and the system-level IMS setting. Even if the user has
8284 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8285 // In the long run, we may instead need to check if there exists a connection service
8286 // which can support video calling.
8287 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008288 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289 return imsManager.isVtEnabledByPlatform()
8290 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8291 && imsManager.isVtEnabledByUser();
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
8294 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008295 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008296
Andrew Leea1239f22015-03-02 17:44:07 -08008297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008298 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8299 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008301 mApp, subId, callingPackage, callingFeatureId,
8302 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 return false;
8304 }
8305
joonhunshin4ac60942023-11-15 15:23:39 +00008306 enforceTelephonyFeatureWithException(callingPackage,
8307 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 CarrierConfigManager configManager =
8312 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008313 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
Andrew Leea1239f22015-03-02 17:44:07 -08008318 }
8319
8320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008321 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008323 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 return false;
8325 }
8326
joonhunshin4ac60942023-11-15 15:23:39 +00008327 enforceTelephonyFeatureWithException(callingPackage,
8328 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 final long identity = Binder.clearCallingIdentity();
8331 try {
8332 CarrierConfigManager configManager =
8333 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008334 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
Andrew Leea1239f22015-03-02 17:44:07 -08008339 }
8340
Andrew Lee9431b832015-03-09 18:46:45 -07008341 @Override
8342 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008343 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008344 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008345 }
8346
8347 @Override
8348 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8350 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 final long identity = Binder.clearCallingIdentity();
8353 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008354 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
Andrew Lee9431b832015-03-09 18:46:45 -07008358 }
8359
Hall Liuf6668912018-10-31 17:05:23 -07008360 /**
8361 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8362 * support for the feature and device firmware support.
8363 *
8364 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8365 */
8366 @Override
8367 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008368 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8369 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008372 final Phone phone = getPhone(subscriptionId);
8373 if (phone == null) {
8374 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8375 return false;
8376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008378 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008380 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8381 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8382 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 return isCarrierSupported && isDeviceSupported;
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
Hall Liu98187582018-01-22 19:15:32 -08008387 }
8388
Hall Liuf6668912018-10-31 17:05:23 -07008389 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008390 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8391 * RTT setting, will return true if the device and carrier both support RTT.
8392 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008393 */
8394 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 final long identity = Binder.clearCallingIdentity();
8396 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008397 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8398 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8399 return false;
8400 }
8401 }
8402
Hall Liu5bab75c2019-12-11 23:58:20 +00008403 boolean isRttSupported = isRttSupported(subscriptionId);
8404 boolean isUserRttSettingOn = Settings.Secure.getInt(
8405 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8406 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8407 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8408 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409 } finally {
8410 Binder.restoreCallingIdentity(identity);
8411 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008412 }
8413
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008414 @Deprecated
8415 @Override
8416 public String getDeviceId(String callingPackage) {
8417 return getDeviceIdWithFeature(callingPackage, null);
8418 }
8419
Sanket Padawe7310cc72015-01-14 09:53:20 -08008420 /**
8421 * Returns the unique device ID of phone, for example, the IMEI for
8422 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8423 *
8424 * <p>Requires Permission:
8425 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8426 */
8427 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008428 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008429 try {
8430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8431 } catch (SecurityException se) {
8432 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8433 throw new SecurityException("Package " + callingPackage + " does not belong to "
8434 + Binder.getCallingUid());
8435 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008436 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008437 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008438 return null;
8439 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008440 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008441 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008443 return null;
8444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 return phone.getDeviceId();
8449 } finally {
8450 Binder.restoreCallingIdentity(identity);
8451 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008452 }
8453
Ping Sunc67b7c22016-03-02 19:16:45 +08008454 /**
8455 * {@hide}
8456 * Returns the IMS Registration Status on a particular subid
8457 *
8458 * @param subId
8459 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008460 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008461 Phone phone = getPhone(subId);
8462 if (phone != null) {
8463 return phone.isImsRegistered();
8464 } else {
8465 return false;
8466 }
8467 }
8468
Santos Cordon7a1885b2015-02-03 11:15:19 -08008469 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008470 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008471 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008473 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008474 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8475 }
8476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
8481 }
8482 }
8483
8484 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008485 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008486 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008487 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008488 mApp,
8489 subscriptionId,
8490 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8491 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008492
8493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8494 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8495
Tyler Gunnf70ed162019-04-03 15:28:53 -07008496 final long identity = Binder.clearCallingIdentity();
8497 try {
8498 Phone phone = getPhone(subscriptionId);
8499 if (phone == null) {
8500 return null;
8501 }
8502 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 }
8507
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008508 /**
8509 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008510 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008511 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 Phone phone = getPhone(subId);
8515 if (phone != null) {
8516 return phone.isWifiCallingEnabled();
8517 } else {
8518 return false;
8519 }
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008522 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008523 }
8524
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008525 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008526 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008527 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008528 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 Phone phone = getPhone(subId);
8532 if (phone != null) {
8533 return phone.isVideoEnabled();
8534 } else {
8535 return false;
8536 }
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 }
8540 }
8541
8542 /**
8543 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8544 * defined in {@link ImsRegistrationImplBase}.
8545 */
8546 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 Phone phone = getPhone(subId);
8550 if (phone != null) {
8551 return phone.getImsRegistrationTech();
8552 } else {
8553 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8554 }
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008557 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008558 }
8559
Stuart Scott8eef64f2015-04-08 15:13:54 -07008560 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008561 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008562 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008563
8564 enforceTelephonyFeatureWithException(callingPackage,
8565 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8566
Stuart Scott981d8582015-04-21 14:09:50 -07008567 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8568 return;
8569 }
Kai Shif70f46f2021-03-03 13:59:46 -08008570 Phone defaultPhone = getDefaultPhone();
8571 if (defaultPhone != null) {
8572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8573 mApp, getDefaultPhone().getSubId(), "factoryReset");
8574 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008575 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008576
Svet Ganovcc087f82015-05-12 20:35:54 -07008577 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008578 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8579 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008580 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008581 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008582 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008583 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008584 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008585 setDataRoamingEnabled(subId, phone == null ? false
8586 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008587 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008588 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008589 // There has been issues when Sms raw table somehow stores orphan
8590 // fragments. They lead to garbled message when new fragments come
8591 // in and combined with those stale ones. In case this happens again,
8592 // user can reset all network settings which will clean up this table.
8593 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008594 // Clean up IMS settings as well here.
8595 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008596 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008597 ImsManager.getInstance(mApp, slotId).factoryReset();
8598 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008599
Kai Shif70f46f2021-03-03 13:59:46 -08008600 if (defaultPhone == null) {
8601 return;
8602 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008603 // Erase modem config if erase modem on network setting is enabled.
8604 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8605 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8606 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008607 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008608 }
Kai Shif70f46f2021-03-03 13:59:46 -08008609
8610 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008611 } finally {
8612 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008613 }
8614 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008615
SongFerngWangfd89b102021-05-27 22:44:54 +08008616 @VisibleForTesting
8617 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8618 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8619 return;
8620 }
8621 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8622 RILConstants.PREFERRED_NETWORK_MODE);
8623 SubscriptionManager.setSubscriptionProperty(subId,
8624 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8625 "user=" + defaultNetworkType);
8626 phone.loadAllowedNetworksFromSubscriptionDatabase();
8627 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8628 defaultNetworkType, null);
8629 }
8630
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008631 private void cleanUpSmsRawTable(Context context) {
8632 ContentResolver resolver = context.getContentResolver();
8633 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8634 resolver.delete(uri, null, null);
8635 }
8636
Narayan Kamath1c496c22015-04-16 14:40:19 +01008637 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008638 public String getSimLocaleForSubscriber(int subId) {
8639 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008640
8641 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8642 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8643
chen xu5d3637b2019-01-21 23:31:38 -08008644 final Phone phone = getPhone(subId);
8645 if (phone == null) {
8646 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008647 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008649 final long identity = Binder.clearCallingIdentity();
8650 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008651 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8652 phone.getContext().getOpPackageName(),
8653 phone.getContext().getAttributionTag());
8654 if (info == null) {
8655 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8656 return null;
chen xu6291c472019-02-04 12:55:53 -08008657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658 // Try and fetch the locale from the carrier properties or from the SIM language
8659 // preferences (EF-PL and EF-LI)...
8660 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008662 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8663 if (localeFromDefaultSim != null) {
8664 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8665 if (DBG) log("Using locale from subId: " + subId + " locale: "
8666 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008667 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008668 } else {
8669 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 }
8671 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673 // The SIM language preferences only store a language (e.g. fr = French), not an
8674 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8675 // the SIM and carrier preferences does not include a country we add the country
8676 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008677 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008678 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008679 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008680 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008681 }
8682
8683 if (DBG) log("No locale found - returning null");
8684 return null;
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008688 }
8689
tom hsu0b59d292022-09-29 23:49:21 +08008690 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008691 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008692 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008693 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008694 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008695 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8696 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008697 Locale.forLanguageTag(localeTag).getCountry())) {
8698 return localeTag;
8699 }
8700 }
8701 return inputLocale.toLanguageTag();
8702 }
8703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 /**
8705 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8706 */
8707 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008708 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008709 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008710 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008711
Gary Jian3aa9a762022-01-24 16:41:19 +08008712 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8713 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008714
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008715 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008716 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8717 * representing the state of the modem.
8718 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008719 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8720 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008721 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008722 */
8723 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008724 public void requestModemActivityInfo(ResultReceiver result) {
8725 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008726
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008727 if (!mApp.getResources().getBoolean(
8728 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8729 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8730 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8731 }
joonhunshin4ac60942023-11-15 15:23:39 +00008732
vagdeviaf9a5b92018-08-15 16:01:53 -07008733 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008734
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008737 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008738 } finally {
8739 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008740 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008741 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008742
Gary Jian76280a42022-12-07 16:18:33 +08008743 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008744 // less than total activity duration.
8745 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8746 if (info == null) {
8747 return false;
8748 }
8749 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008750 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008751 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8752
Hall Liu49656c02020-10-09 19:00:11 -07008753 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8754
Siddharth Rayb8114062018-06-17 15:02:38 -07008755 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008756 && (info.getSleepTimeMillis() <= activityDurationMs)
8757 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008758 }
8759
Gary Jian3aa9a762022-01-24 16:41:19 +08008760 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8761 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8762 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8763 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8764
8765 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8766 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8767 }
8768
8769 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8770 mLastModemActivityInfo.setReceiveTimeMillis(
8771 rat,
8772 freq,
8773 info.getReceiveTimeMillis(rat, freq)
8774 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8775 }
8776
8777 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8778 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8779 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8780 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8781
8782 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8783 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8784 }
8785 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8786 mLastModemActivityInfo.setReceiveTimeMillis(
8787 rat,
8788 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8789 }
8790
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008791 /**
8792 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8793 * @param info recent ModemActivityInfo
8794 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008795 private void mergeModemActivityInfo(ModemActivityInfo info) {
8796 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008797 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008798 boolean matched;
8799 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8800 matched = false;
8801 int rat = info.getSpecificInfoRat(i);
8802 int freq = info.getSpecificInfoFrequencyRange(i);
8803 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8804 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8805 //if it already exists
8806 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8807 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8808 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8809 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8810 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8811 updateLastModemActivityInfo(info, rat, freq);
8812 matched = true;
8813 }
8814 } else {
8815 updateLastModemActivityInfo(info, rat);
8816 matched = true;
8817 }
8818 }
8819 }
8820
8821 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008822 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008823 new ActivityStatsTechSpecificInfo(
8824 rat,
8825 freq,
8826 info.getTransmitTimeMillis(rat, freq),
8827 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008828 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008829 }
8830 }
8831 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8832 mLastModemActivitySpecificInfo =
8833 new ActivityStatsTechSpecificInfo[merged.size()];
8834 merged.toArray(mLastModemActivitySpecificInfo);
8835
8836 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8837 mLastModemActivityInfo.setSleepTimeMillis(
8838 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008839 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008840 mLastModemActivityInfo.setIdleTimeMillis(
8841 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008842 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008843
8844 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008845 new ModemActivityInfo(
8846 mLastModemActivityInfo.getTimestampMillis(),
8847 mLastModemActivityInfo.getSleepTimeMillis(),
8848 mLastModemActivityInfo.getIdleTimeMillis(),
8849 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008850 }
8851
8852 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8853 ActivityStatsTechSpecificInfo[] info) {
8854 int infoSize = info.length;
8855 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8856 for (int i = 0; i < infoSize; i++) {
8857 ret[i] = new ActivityStatsTechSpecificInfo(
8858 info[i].getRat(), info[i].getFrequencyRange(),
8859 info[i].getTransmitTimeMillis(),
8860 (int) info[i].getReceiveTimeMillis());
8861 }
8862 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008863 }
8864
Jack Yu85bd38a2015-11-09 11:34:32 -08008865 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008866 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008867 */
8868 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008869 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8870 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8871 Phone phone = PhoneFactory.getPhone(slotIndex);
8872 if (phone == null) {
8873 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8874 return null;
8875 }
8876
8877 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008879 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008880 return null;
8881 }
8882
joonhunshin4ac60942023-11-15 15:23:39 +00008883 enforceTelephonyFeatureWithException(callingPackage,
8884 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8885
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008886 boolean hasFinePermission = false;
8887 boolean hasCoarsePermission = false;
8888 if (!renounceFineLocationAccess) {
8889 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8890 LocationAccessPolicy.checkLocationPermission(mApp,
8891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8892 .setCallingPackage(callingPackage)
8893 .setCallingFeatureId(callingFeatureId)
8894 .setCallingPid(Binder.getCallingPid())
8895 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008896 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008897 .setLogAsInfo(true)
8898 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8899 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8900 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8901 .build());
8902 hasFinePermission =
8903 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8904 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008905
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008906 if (!renounceCoarseLocationAccess) {
8907 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8908 LocationAccessPolicy.checkLocationPermission(mApp,
8909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8910 .setCallingPackage(callingPackage)
8911 .setCallingFeatureId(callingFeatureId)
8912 .setCallingPid(Binder.getCallingPid())
8913 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008914 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008915 .setLogAsInfo(true)
8916 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8917 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8918 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8919 .build());
8920 hasCoarsePermission =
8921 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8922 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008923
Jordan Liu0f2bc442020-11-18 16:47:37 -08008924 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008926 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8927 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008928 if (subInfo != null && !subInfo.isActive()) {
8929 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008930 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008931 }
8932
Hall Liuf19c44f2018-11-27 14:38:17 -08008933 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008934 boolean isCallingPackageDataService = phone.getDataServicePackages()
8935 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008936
8937 // Scrub out the location info in ServiceState depending on what level of access
8938 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008939 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008940 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8941 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008945 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008946
8947 /**
8948 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8949 *
8950 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8951 * voicemail ringtone.
8952 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8953 * PhoneAccount.
8954 */
8955 @Override
8956 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8958 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 final long identity = Binder.clearCallingIdentity();
8961 try {
8962 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8963 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008964 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8968 } finally {
8969 Binder.restoreCallingIdentity(identity);
8970 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008971 }
8972
8973 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008974 * Sets the per-account voicemail ringtone.
8975 *
8976 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8977 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8978 *
8979 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8980 * voicemail ringtone.
8981 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8982 * PhoneAccount.
8983 */
8984 @Override
8985 public void setVoicemailRingtoneUri(String callingPackage,
8986 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008987 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008989 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8990 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8992 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8993 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995
joonhunshin4ac60942023-11-15 15:23:39 +00008996 enforceTelephonyFeatureWithException(callingPackage,
8997 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008999 final long identity = Binder.clearCallingIdentity();
9000 try {
9001 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9002 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009003 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009004 }
9005 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9006 } finally {
9007 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009008 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009009 }
9010
9011 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009012 * Returns whether vibration is set for voicemail notification in Phone settings.
9013 *
9014 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9015 * voicemail vibration setting.
9016 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9017 */
9018 @Override
9019 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9021 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9026 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009027 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009028 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009030 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9031 } finally {
9032 Binder.restoreCallingIdentity(identity);
9033 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009034 }
9035
Youhan Wange64578a2016-05-02 15:32:42 -07009036 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009037 * Sets the per-account voicemail vibration.
9038 *
9039 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9040 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9041 *
9042 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9043 * voicemail vibration setting.
9044 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9045 * specific PhoneAccount.
9046 */
9047 @Override
9048 public void setVoicemailVibrationEnabled(String callingPackage,
9049 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009050 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009052 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9053 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9055 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9056 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009057 }
9058
joonhunshin4ac60942023-11-15 15:23:39 +00009059 enforceTelephonyFeatureWithException(callingPackage,
9060 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9065 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009066 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009067 }
9068 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009071 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009072 }
9073
9074 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009075 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9076 *
9077 * @throws SecurityException if the caller does not have the required permission
9078 */
arunvoddud7401012022-12-15 16:08:12 +00009079 @VisibleForTesting
9080 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009081 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009082 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009083 }
9084
9085 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009086 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9087 * permission.
9088 *
9089 * @throws SecurityException if the caller does not have the required permission
9090 */
9091 private void enforceSendSmsPermission() {
9092 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9093 }
9094
9095 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009096 * Make sure either called from same process as self (phone) or IPC caller has interact across
9097 * users permission.
9098 *
9099 * @throws SecurityException if the caller does not have the required permission
9100 */
9101 private void enforceInteractAcrossUsersPermission(String message) {
9102 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9103 }
9104
9105 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009106 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009107 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009108 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009109 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009110 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009111 final long identity = Binder.clearCallingIdentity();
9112 try {
9113 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009114 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009115 if (componentName == null) {
9116 throw new SecurityException(
9117 "Caller not current active visual voicemail package[null]");
9118 }
9119 String vvmPackage = componentName.getPackageName();
9120 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009121 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009122 }
9123 } finally {
9124 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009125 }
9126 }
9127
9128 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009129 * Return the application ID for the app type.
9130 *
9131 * @param subId the subscription ID that this request applies to.
9132 * @param appType the uicc app type.
9133 * @return Application ID for specificied app type, or null if no uicc.
9134 */
9135 @Override
9136 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009137 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009138
9139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9140 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9141
Youhan Wange64578a2016-05-02 15:32:42 -07009142 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009143
9144 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009145 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146 if (phone == null) {
9147 return null;
9148 }
9149 String aid = null;
9150 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009151 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009152 .getApplicationByType(appType).getAid();
9153 } catch (Exception e) {
9154 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9155 }
9156 return aid;
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009159 }
Youhan Wange64578a2016-05-02 15:32:42 -07009160 }
9161
Youhan Wang4001d252016-05-11 10:29:41 -07009162 /**
9163 * Return the Electronic Serial Number.
9164 *
9165 * @param subId the subscription ID that this request applies to.
9166 * @return ESN or null if error.
9167 */
9168 @Override
9169 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009170 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009171 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009172
9173 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009174 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009175 if (phone == null) {
9176 return null;
9177 }
9178 String esn = null;
9179 try {
9180 esn = phone.getEsn();
9181 } catch (Exception e) {
9182 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9183 }
9184 return esn;
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009187 }
Youhan Wang4001d252016-05-11 10:29:41 -07009188 }
9189
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009190 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009191 * Return the Preferred Roaming List Version.
9192 *
9193 * @param subId the subscription ID that this request applies to.
9194 * @return PRLVersion or null if error.
9195 */
9196 @Override
9197 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009198 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009199
9200 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9201 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9202
Youhan Wang66ad5d72016-07-18 17:56:58 -07009203 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009204
9205 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009206 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009207 if (phone == null) {
9208 return null;
9209 }
9210 String cdmaPrlVersion = null;
9211 try {
9212 cdmaPrlVersion = phone.getCdmaPrlVersion();
9213 } catch (Exception e) {
9214 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9215 }
9216 return cdmaPrlVersion;
9217 } finally {
9218 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009219 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009220 }
9221
9222 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009223 * Get snapshot of Telephony histograms
9224 * @return List of Telephony histograms
9225 * @hide
9226 */
9227 @Override
9228 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9230 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009231
9232 final long identity = Binder.clearCallingIdentity();
9233 try {
9234 return RIL.getTelephonyRILTimingHistograms();
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009238 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009239
9240 /**
9241 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009242 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9243 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009244 * Require system privileges. In the future we may add this to carrier APIs.
9245 *
Michele Berionne482f8202018-11-27 18:57:59 -08009246 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009247 */
9248 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009249 @TelephonyManager.SetCarrierRestrictionResult
9250 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009251 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009252
9253 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9254 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9255
vagdeviaf9a5b92018-08-15 16:01:53 -07009256 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009257
Michele Berionne482f8202018-11-27 18:57:59 -08009258 if (carrierRestrictionRules == null) {
9259 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009260 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009262 final long identity = Binder.clearCallingIdentity();
9263 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009264 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009265 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009266 } finally {
9267 Binder.restoreCallingIdentity(identity);
9268 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009269 }
9270
9271 /**
9272 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009273 * Get the allowed carrier list and the excluded carrier list, including the priority between
9274 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009275 * Require system privileges. In the future we may add this to carrier APIs.
9276 *
Michele Berionne482f8202018-11-27 18:57:59 -08009277 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009278 */
9279 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009280 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009281 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009282
9283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9284 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9285
vagdeviaf9a5b92018-08-15 16:01:53 -07009286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009290 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9291 if (response instanceof CarrierRestrictionRules) {
9292 return (CarrierRestrictionRules) response;
9293 }
9294 // Response is an Exception of some kind,
9295 // which is signalled to the user as a NULL retval
9296 return null;
9297 } catch (Exception e) {
9298 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9299 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009303 }
9304
fionaxu59545b42016-05-25 15:53:37 -07009305 /**
arunvoddud7401012022-12-15 16:08:12 +00009306 * Fetches the carrier restriction status of the device and sends the status to the caller
9307 * through the callback.
9308 *
9309 * @param callback The callback that will be used to send the result.
9310 * @throws SecurityException if the caller does not have the required permission/privileges or
9311 * the caller is not allowlisted.
9312 */
9313 @Override
9314 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009315 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009316 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009317 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9318 try {
9319 mApp.enforceCallingOrSelfPermission(
9320 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9321 functionName);
9322 } catch (SecurityException e) {
9323 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9324 functionName);
9325 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009326 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9327 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009328 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9329 throw new SecurityException("Not an authorized caller");
9330 }
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009334 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009335 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 }
9340
arunvoddu567f2b42023-04-25 17:22:00 +00009341 @Override
9342 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9343 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9344 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9345 return allowListInfo.getShaIdList(pkgName, carrierId);
9346 }
9347
arunvoddud7401012022-12-15 16:08:12 +00009348 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009349 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009350 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009351 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009352 }
9353
9354 /**
fionaxu59545b42016-05-25 15:53:37 -07009355 * Action set from carrier signalling broadcast receivers to enable/disable radio
9356 * @param subId the subscription ID that this action applies to.
9357 * @param enabled control enable or disable radio.
9358 * {@hide}
9359 */
9360 @Override
9361 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9362 enforceModifyPermission();
9363 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364
9365 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009366 if (phone == null) {
9367 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9368 return;
9369 }
9370 try {
9371 phone.carrierActionSetRadioEnabled(enabled);
9372 } catch (Exception e) {
9373 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009374 } finally {
9375 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009376 }
9377 }
9378
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009379 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009380 * Enable or disable Voice over NR (VoNR)
9381 * @param subId the subscription ID that this action applies to.
9382 * @param enabled enable or disable VoNR.
9383 * @return operation result.
9384 */
9385 @Override
9386 public int setVoNrEnabled(int subId, boolean enabled) {
9387 enforceModifyPermission();
9388 final Phone phone = getPhone(subId);
9389
9390 final long identity = Binder.clearCallingIdentity();
9391 if (phone == null) {
9392 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9393 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9394 }
9395
9396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9397 try {
9398 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9399 workSource);
9400 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009401
9402 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9403 if (DBG) {
9404 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9405 }
9406 SubscriptionManager.setSubscriptionProperty(
9407 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9408 (enabled ? "1" : "0"));
9409 }
9410
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009411 return result;
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
9416
9417 /**
9418 * Is voice over NR enabled
9419 * @return true if VoNR is enabled else false
9420 */
9421 @Override
9422 public boolean isVoNrEnabled(int subId) {
9423 enforceReadPrivilegedPermission("isVoNrEnabled");
9424 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9428 null, subId, workSource);
9429 if (DBG) log("isVoNrEnabled: " + isEnabled);
9430 return isEnabled;
9431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
9434 }
9435
9436 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009437 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9438 * network status based on which carrier apps could apply actions accordingly,
9439 * enable/disable default url handler for example.
9440 *
9441 * @param subId the subscription ID that this action applies to.
9442 * @param report control start/stop reporting the default network status.
9443 * {@hide}
9444 */
9445 @Override
9446 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9447 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009448
9449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9450 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9451 "carrierActionReportDefaultNetworkStatus");
9452
fionaxu8da9cb12017-05-23 15:02:46 -07009453 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009454
9455 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009456 if (phone == null) {
9457 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9458 return;
9459 }
9460 try {
9461 phone.carrierActionReportDefaultNetworkStatus(report);
9462 } catch (Exception e) {
9463 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009464 } finally {
9465 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009466 }
9467 }
9468
9469 /**
fionaxud9622282017-07-17 17:51:30 -07009470 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9471 * @param subId the subscription ID that this action applies to.
9472 * {@hide}
9473 */
9474 @Override
9475 public void carrierActionResetAll(int subId) {
9476 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009477
9478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9479 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9480
fionaxud9622282017-07-17 17:51:30 -07009481 final Phone phone = getPhone(subId);
9482 if (phone == null) {
9483 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9484 return;
9485 }
9486 try {
9487 phone.carrierActionResetAll();
9488 } catch (Exception e) {
9489 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9490 }
9491 }
9492
9493 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009494 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9495 * bug report is being generated.
9496 */
9497 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009498 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009499 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9500 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009501 writer.println("Permission Denial: can't dump Phone from pid="
9502 + Binder.getCallingPid()
9503 + ", uid=" + Binder.getCallingUid()
9504 + "without permission "
9505 + android.Manifest.permission.DUMP);
9506 return;
9507 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009508 try {
9509 DumpsysHandler.dump(mApp, fd, writer, args);
9510 } catch (Exception e) {
9511 writer.println("Failed to dump phone information: " + e);
9512 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009513 }
Jack Yueb89b242016-06-22 13:27:47 -07009514
Brad Ebingerdac2f002018-04-03 15:17:52 -07009515 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009516 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9517 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9518 @NonNull String[] args) {
9519 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9520 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009521 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009522 }
9523
Jack Yueb89b242016-06-22 13:27:47 -07009524 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009525 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009526 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009527 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009528 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009529 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009530 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009531 */
9532 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009533 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009534 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009535 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9536 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9537 try {
9538 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009539 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009540 } catch (SecurityException se) {
9541 enforceModifyPermission();
9542 }
9543 } else {
9544 enforceModifyPermission();
9545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009546
joonhunshin4ac60942023-11-15 15:23:39 +00009547 enforceTelephonyFeatureWithException(callingPackage,
9548 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9549
Nate Myren116695d2024-02-09 09:36:01 -08009550 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009551 final long identity = Binder.clearCallingIdentity();
9552 try {
Nate Myren116695d2024-02-09 09:36:01 -08009553 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9554 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009555 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009556 callingUid, callingPackage, null, null);
9557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009558 Phone phone = getPhone(subId);
9559 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009560 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9561 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009562 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009563 phone.getDataSettingsManager().setDataEnabled(
9564 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009566 }
9567 } finally {
9568 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009569 }
9570 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009571
9572 /**
9573 * Get Client request stats
9574 * @return List of Client Request Stats
9575 * @hide
9576 */
9577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009578 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9579 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009581 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009582 return null;
9583 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009584 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009586 final long identity = Binder.clearCallingIdentity();
9587 try {
9588 if (phone != null) {
9589 return phone.getClientRequestStats();
9590 }
9591
9592 return null;
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009596 }
9597
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009598 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009599 String packageName = mApp.getPackageManager().getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009600 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009601 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9602 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9603 // exception. ROOT_UID seems not to have a valid package name returned by
9604 // PackageManager, so just fake it here to avoid issues when running telephony shell
9605 // commands that plumb through the RIL as root, like so:
9606 // $ adb root
9607 // $ adb shell cmd phone ...
9608 packageName = "root";
9609 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009610 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009611 }
Jack Yueb4124c2017-02-16 15:32:43 -08009612
9613 /**
Grace Chen70990072017-03-24 17:21:30 -07009614 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009615 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009616 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009617 * @param state State of SIM (power down, power up, pass through)
9618 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9619 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9620 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009621 *
9622 **/
9623 @Override
Grace Chen70990072017-03-24 17:21:30 -07009624 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009625 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009626
9627 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9628 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9629
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009630 Phone phone = PhoneFactory.getPhone(slotIndex);
9631
vagdeviaf9a5b92018-08-15 16:01:53 -07009632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009634 final long identity = Binder.clearCallingIdentity();
9635 try {
9636 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009637 phone.setSimPowerState(state, null, workSource);
9638 }
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
9644 /**
9645 * Set SIM card power state.
9646 *
9647 * @param slotIndex SIM slot id.
9648 * @param state State of SIM (power down, power up, pass through)
9649 * @param callback callback to trigger after success or failure
9650 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9651 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9652 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9653 *
9654 **/
9655 @Override
9656 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9657 IIntegerConsumer callback) {
9658 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009659
9660 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9661 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9662 "setSimPowerStateForSlotWithCallback");
9663
Jordan Liu109698e2020-11-24 14:50:34 -08009664 Phone phone = PhoneFactory.getPhone(slotIndex);
9665
9666 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9667
9668 final long identity = Binder.clearCallingIdentity();
9669 try {
9670 if (phone != null) {
9671 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9672 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009673 }
9674 } finally {
9675 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009676 }
9677 }
Shuo Qiandd210312017-04-12 22:11:33 +00009678
Tyler Gunn65d45c22017-06-05 11:22:26 -07009679 private boolean isUssdApiAllowed(int subId) {
9680 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009681 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009682 if (configManager == null) {
9683 return false;
9684 }
9685 PersistableBundle pb = configManager.getConfigForSubId(subId);
9686 if (pb == null) {
9687 return false;
9688 }
9689 return pb.getBoolean(
9690 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9691 }
9692
Shuo Qiandd210312017-04-12 22:11:33 +00009693 /**
Ling Mac28f0212023-03-24 16:07:15 -07009694 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009695 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009696 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009697 */
goneil9c5f4872017-12-05 14:07:56 -08009698 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009699 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009700 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009701
9702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9703 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009705 final long identity = Binder.clearCallingIdentity();
9706 try {
Ling Mac28f0212023-03-24 16:07:15 -07009707 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009708 } finally {
9709 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009710 }
9711 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009712
9713 /**
9714 * Get the current signal strength information for the given subscription.
9715 * Because this information is not updated when the device is in a low power state
9716 * it should not be relied-upon to be current.
9717 * @param subId Subscription index
9718 * @return the most recent cached signal strength info from the modem
9719 */
9720 @Override
9721 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009722 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9723 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009725 final long identity = Binder.clearCallingIdentity();
9726 try {
9727 Phone p = getPhone(subId);
9728 if (p == null) {
9729 return null;
9730 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009732 return p.getSignalStrength();
9733 } finally {
9734 Binder.restoreCallingIdentity(identity);
9735 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009736 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009737
Pengquan Meng77b7f132018-08-22 14:49:57 -07009738 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009739 * Get the current modem radio state for the given slot.
9740 * @param slotIndex slot index.
9741 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009742 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009743 * @return the current radio power state from the modem
9744 */
9745 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009746 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009747 Phone phone = PhoneFactory.getPhone(slotIndex);
9748 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9750 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009751 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9752 }
9753
joonhunshin4ac60942023-11-15 15:23:39 +00009754 enforceTelephonyFeatureWithException(callingPackage,
9755 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9756
Chen Xuf792fd62018-10-17 17:54:36 +00009757 final long identity = Binder.clearCallingIdentity();
9758 try {
9759 return phone.getRadioPowerState();
9760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
9763 }
9764 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9765 }
9766
9767 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009768 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9769 *
9770 * <p>Requires one of the following permissions:
9771 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009772 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009773 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9774 * privileges.
9775 *
9776 * @param subId subscription id
9777 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9778 * {@code false}.
9779 */
9780 @Override
9781 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009782 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009783 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009784 try {
9785 mApp.enforceCallingOrSelfPermission(
9786 android.Manifest.permission.ACCESS_NETWORK_STATE,
9787 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009788 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009789 mApp.enforceCallingOrSelfPermission(
9790 permission.READ_BASIC_PHONE_STATE, functionName);
9791 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009792 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009793 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009794 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009795 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009796
joonhunshin4ac60942023-11-15 15:23:39 +00009797 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9798 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9799
Pengquan Menga1bb6272018-09-06 09:59:22 -07009800 boolean isEnabled = false;
9801 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009802 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009803 Phone phone = getPhone(subId);
9804 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009805 } finally {
9806 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009807 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009808 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009809 }
9810
9811
9812 /**
9813 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9814 *
9815 * <p> Requires permission:
9816 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9817 * privileges.
9818 *
9819 * @param subId subscription id
9820 * @param isEnabled {@code true} means enable, {@code false} means disable.
9821 */
9822 @Override
9823 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9825 mApp, subId, "setDataRoamingEnabled");
9826
joonhunshin4ac60942023-11-15 15:23:39 +00009827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9828 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9829
Pengquan Menga1bb6272018-09-06 09:59:22 -07009830 final long identity = Binder.clearCallingIdentity();
9831 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009832 Phone phone = getPhone(subId);
9833 if (phone != null) {
9834 phone.setDataRoamingEnabled(isEnabled);
9835 }
9836 } finally {
9837 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009838 }
9839 }
9840
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009841 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009842 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009843 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009844 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009845 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009846
joonhunshin4ac60942023-11-15 15:23:39 +00009847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9848 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9849
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009850 boolean isAllowed = true;
9851 final long identity = Binder.clearCallingIdentity();
9852 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009853 Phone phone = getPhone(subId);
9854 if (phone != null) {
9855 isAllowed = phone.isCspPlmnEnabled();
9856 }
9857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 return isAllowed;
9861 }
9862
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009863 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9864 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009865 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009866 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009867 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009868 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9869 if (phone == null) {
9870 return false;
9871 }
9872 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9873 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9874 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009875 }
9876
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009877 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009878 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009879 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009880 mApp.getSystemService(AppOpsManager.class)
9881 .checkPackage(Binder.getCallingUid(), callingPackage);
9882
Jordan Liu1e142fc2019-04-22 15:10:43 -07009883 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009884 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009885 try {
9886 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009887 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009888 } catch (SecurityException e) {
9889 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9890 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009891 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009892 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009893 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009894 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009895 }
joonhunshin4ac60942023-11-15 15:23:39 +00009896
9897 enforceTelephonyFeatureWithException(callingPackage,
9898 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9899
sandeepjsb6c87872021-09-27 15:34:44 +00009900 // checking compatibility, if calling app's target SDK is T and beyond.
9901 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9902 Binder.getCallingUid())) {
9903 isIccIdAccessRestricted = true;
9904 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009905 final long identity = Binder.clearCallingIdentity();
9906 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009907 UiccController uiccController = UiccController.getInstance();
9908 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009909 if (hasReadPermission) {
9910 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009911 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009912
9913 // Remove private info if the caller doesn't have access
9914 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9915 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009916 //setting the value after compatibility check
9917 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009918 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9919 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009920 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009921 if (card == null) {
9922 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009923 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009924 continue;
9925 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009926 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9927 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009928 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009929 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009930 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009931 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9932 for (UiccPortInfo portInfo : portInfos) {
9933 UiccPort port = uiccController.getUiccPortForSlot(
9934 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9935 if (port == null) {
9936 // assume no access if port is null
9937 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9938 continue;
9939 }
9940 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9941 uiccPortInfos.add(portInfo);
9942 } else {
9943 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9944 }
9945 }
9946 filteredInfos.add(new UiccCardInfo(
9947 cardInfo.isEuicc(),
9948 cardInfo.getCardId(),
9949 null,
9950 cardInfo.getPhysicalSlotIndex(),
9951 cardInfo.isRemovable(),
9952 cardInfo.isMultipleEnabledProfilesSupported(),
9953 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009954 }
9955 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
sandeepjsb6c87872021-09-27 15:34:44 +00009961 /**
9962 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9963 * generally private and require carrier privileges to view.
9964 *
9965 * @hide
9966 */
9967 @NonNull
9968 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9969 List<UiccPortInfo> portinfo = new ArrayList<>();
9970 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9971 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9972 }
9973 return new UiccCardInfo(
9974 cardInfo.isEuicc(),
9975 cardInfo.getCardId(),
9976 null,
9977 cardInfo.getPhysicalSlotIndex(),
9978 cardInfo.isRemovable(),
9979 cardInfo.isMultipleEnabledProfilesSupported(),
9980 portinfo
9981 );
9982 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009983
sandeepjsb6c87872021-09-27 15:34:44 +00009984 /**
9985 * @hide
9986 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9987 * These values are generally private and require carrier privileges to view.
9988 */
9989 @NonNull
9990 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9991 return new UiccPortInfo(
9992 UiccPortInfo.ICCID_REDACTED,
9993 portInfo.getPortIndex(),
9994 portInfo.getLogicalSlotIndex(),
9995 portInfo.isActive()
9996 );
9997 }
9998 @Override
9999 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010000 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010001 mApp.getSystemService(AppOpsManager.class)
10002 .checkPackage(Binder.getCallingUid(), callingPackage);
10003
sandeepjsb6c87872021-09-27 15:34:44 +000010004 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010005
Aman Guptaf3c90b32022-03-17 04:54:16 +000010006 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10007 // we are reading iccId which is PII data.
10008 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010009
joonhunshin4ac60942023-11-15 15:23:39 +000010010 enforceTelephonyFeatureWithException(callingPackage,
10011 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10012
sandeepjsb6c87872021-09-27 15:34:44 +000010013 // checking compatibility, if calling app's target SDK is T and beyond.
10014 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10015 Binder.getCallingUid())) {
10016 isLogicalSlotAccessRestricted = true;
10017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010018 final long identity = Binder.clearCallingIdentity();
10019 try {
10020 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010021 if (slots == null || slots.length == 0) {
10022 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010023 return null;
10024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010025 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10026 for (int i = 0; i < slots.length; i++) {
10027 UiccSlot slot = slots[i];
10028 if (slot == null) {
10029 continue;
10030 }
10031
Jordan Liu7be7e652019-05-06 18:55:02 +000010032 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010033 UiccCard card = slot.getUiccCard();
10034 if (card != null) {
10035 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010036 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010037 cardId = slot.getEid();
10038 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010039 // If cardId is null, use iccId of default port as cardId.
10040 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010042 }
10043
Jordan Liu857451f2019-05-09 16:35:35 -070010044 if (cardId != null) {
10045 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10046 // if cardId is an EID, it's all digits so this is fine
10047 cardId = IccUtils.stripTrailingFs(cardId);
10048 }
10049
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010050 int cardState = 0;
10051 switch (slot.getCardState()) {
10052 case CARDSTATE_ABSENT:
10053 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10054 break;
10055 case CARDSTATE_PRESENT:
10056 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10057 break;
10058 case CARDSTATE_ERROR:
10059 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10060 break;
10061 case CARDSTATE_RESTRICTED:
10062 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10063 break;
10064 default:
10065 break;
10066
10067 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010068 List<UiccPortInfo> portInfos = new ArrayList<>();
10069 int[] portIndexes = slot.getPortList();
10070 for (int portIdx : portIndexes) {
10071 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010072 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010073 portInfos.add(new UiccPortInfo(iccId, portIdx,
10074 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010076 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010077 slot.isEuicc(),
10078 cardId,
10079 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010080 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010081 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010082 //setting the value after compatibility check
10083 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010084 }
10085 return infos;
10086 } finally {
10087 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010088 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010089 }
10090
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010091 /* Returns null if doesn't have read permission or carrier privilege access. */
10092 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10093 boolean hasReadPermission) {
10094 String iccId = slot.getIccId(portIndex);
10095 if (hasReadPermission) { // if has read permission
10096 return iccId;
10097 } else {
10098 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10099 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10100 // if no read permission, checking carrier privilege access
10101 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10102 return iccId;
10103 }
10104 }
10105 }
10106 // No read permission or carrier privilege access.
10107 return UiccPortInfo.ICCID_REDACTED;
10108 }
10109
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010110 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010111 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010112 public boolean switchSlots(int[] physicalSlots) {
10113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010114
joonhunshin4ac60942023-11-15 15:23:39 +000010115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10117
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010118 final long identity = Binder.clearCallingIdentity();
10119 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010120 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10121 for (int i = 0; i < physicalSlots.length; i++) {
10122 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10123 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10124 physicalSlots[i], i));
10125 }
10126 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010130 }
Jack Yu4c988042018-02-27 15:30:01 -080010131
10132 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010133 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10134 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10135 enforceModifyPermission();
10136
joonhunshin4ac60942023-11-15 15:23:39 +000010137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10138 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10139
sandeepjsb6c87872021-09-27 15:34:44 +000010140 final long identity = Binder.clearCallingIdentity();
10141 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010142 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010143 } finally {
10144 Binder.restoreCallingIdentity(identity);
10145 }
10146 }
10147
10148 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010149 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010150 enforceTelephonyFeatureWithException(callingPackage,
10151 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10152
Jordan Liu7de49fa2018-12-06 14:48:49 -080010153 final long identity = Binder.clearCallingIdentity();
10154 try {
10155 return UiccController.getInstance().getCardIdForDefaultEuicc();
10156 } finally {
10157 Binder.restoreCallingIdentity(identity);
10158 }
10159 }
10160
Pengquan Meng85728fb2018-03-12 16:31:21 -070010161 /**
goneil47ffb6e2018-04-06 15:40:58 -070010162 * A test API to reload the UICC profile.
10163 *
10164 * <p>Requires that the calling app has permission
10165 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10166 * @hide
10167 */
10168 @Override
10169 public void refreshUiccProfile(int subId) {
10170 enforceModifyPermission();
10171
10172 final long identity = Binder.clearCallingIdentity();
10173 try {
10174 Phone phone = getPhone(subId);
10175 if (phone == null) {
10176 return;
10177 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010178 UiccPort uiccPort = phone.getUiccPort();
10179 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010180 return;
10181 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010182 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010183 if (uiccProfile == null) {
10184 return;
10185 }
10186 uiccProfile.refresh();
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
10192 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010193 * Returns false if the mobile data is disabled by default, otherwise return true.
10194 */
10195 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010196 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010197 }
10198
10199 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010200 * Returns the default network type for the given {@code subId}, if the default network type is
10201 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10202 */
10203 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010204 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010205 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010206 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10207 return list.get(phoneId);
10208 }
10209 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010210 }
fionaxua13278b2018-03-21 00:08:13 -070010211
10212 @Override
10213 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010214 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010215 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010216
10217 final long identity = Binder.clearCallingIdentity();
10218 try {
10219 final Phone phone = getPhone(subId);
10220 if (phone == null) {
10221 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10222 return;
10223 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010224 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10225 if (cpt != null) {
10226 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10227 }
10228 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010229 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10230 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010231 if (carrierPrivilegeRules == null) {
10232 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10233 } else {
10234 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010236 } finally {
10237 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010238 }
fionaxua13278b2018-03-21 00:08:13 -070010239 }
10240
10241 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010242 public void setCarrierServicePackageOverride(
10243 int subId, String carrierServicePackage, String callingPackage) {
10244 TelephonyPermissions.enforceShellOnly(
10245 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10246
Benedict Wong66477622023-02-03 23:30:57 +000010247 final long identity = Binder.clearCallingIdentity();
10248 try {
10249 final Phone phone = getPhone(subId);
10250 if (phone == null || phone.getSubId() != subId) {
10251 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10252 throw new IllegalArgumentException("No phone for subid");
10253 }
10254 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10255 if (cpt == null) {
10256 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10257 throw new IllegalStateException("No CPT for phone");
10258 }
10259 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
10265 @Override
fionaxua13278b2018-03-21 00:08:13 -070010266 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010267 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010268
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 final Phone phone = getPhone(subId);
10272 if (phone == null) {
10273 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10274 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10275 }
10276 return phone.getCarrierIdListVersion();
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010279 }
fionaxua13278b2018-03-21 00:08:13 -070010280 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010281
10282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010283 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10284 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010286 mApp, subId, callingPackage, callingFeatureId,
10287 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010288 return -1;
10289 }
10290
10291 final long identity = Binder.clearCallingIdentity();
10292 try {
10293 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10294 } finally {
10295 Binder.restoreCallingIdentity(identity);
10296 }
10297 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010298
10299 @Override
10300 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010301 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010302 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010303 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010304
joonhunshin4ac60942023-11-15 15:23:39 +000010305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10306 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10307
Pengquan Menga1bb6272018-09-06 09:59:22 -070010308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
10315
10316 @Override
10317 public boolean setCdmaRoamingMode(int subId, int mode) {
10318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10319 mApp, subId, "setCdmaRoamingMode");
10320
joonhunshin4ac60942023-11-15 15:23:39 +000010321 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10322 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10323
Pengquan Menga1bb6272018-09-06 09:59:22 -070010324 final long identity = Binder.clearCallingIdentity();
10325 try {
10326 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10327 } finally {
10328 Binder.restoreCallingIdentity(identity);
10329 }
10330 }
10331
10332 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010333 public int getCdmaSubscriptionMode(int subId) {
10334 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010335 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010336 mApp, subId, "getCdmaSubscriptionMode");
10337
joonhunshin4ac60942023-11-15 15:23:39 +000010338 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10339 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10340
Sarah Chinbaab1432020-10-28 13:46:24 -070010341 final long identity = Binder.clearCallingIdentity();
10342 try {
10343 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
10348
10349 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010350 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10352 mApp, subId, "setCdmaSubscriptionMode");
10353
joonhunshin4ac60942023-11-15 15:23:39 +000010354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10355 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10356
Pengquan Menga1bb6272018-09-06 09:59:22 -070010357 final long identity = Binder.clearCallingIdentity();
10358 try {
10359 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010364
sqianc5eccab2018-10-19 18:46:41 -070010365 @Override
sqian8c685422019-02-22 15:55:18 -080010366 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010367 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010369 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10370 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010371 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10372 }
joonhunshin4ac60942023-11-15 15:23:39 +000010373
10374 enforceTelephonyFeatureWithException(callingPackage,
10375 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10376
sqian11b7a0e2018-12-05 18:48:28 -080010377 final long identity = Binder.clearCallingIdentity();
10378 try {
sqian854d44b2018-12-12 16:48:18 -080010379 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10380 for (Phone phone: PhoneFactory.getPhones()) {
10381 if (phone.getEmergencyNumberTracker() != null
10382 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10383 emergencyNumberListInternal.put(
10384 phone.getSubId(),
10385 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10386 }
sqian11b7a0e2018-12-05 18:48:28 -080010387 }
sqian854d44b2018-12-12 16:48:18 -080010388 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010389 } finally {
10390 Binder.restoreCallingIdentity(identity);
10391 }
sqianc5eccab2018-10-19 18:46:41 -070010392 }
10393
10394 @Override
sqian8c685422019-02-22 15:55:18 -080010395 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010396 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010397 if (!exactMatch) {
10398 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010399 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010400 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010401 }
joonhunshin4ac60942023-11-15 15:23:39 +000010402
10403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10404 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10405
sqian11b7a0e2018-12-05 18:48:28 -080010406 final long identity = Binder.clearCallingIdentity();
10407 try {
sqian854d44b2018-12-12 16:48:18 -080010408 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010409 //Note: we ignore passed in param exactMatch. We can remove it once
10410 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010411 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010412 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010413 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010414 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010415 }
sqian11b7a0e2018-12-05 18:48:28 -080010416 }
10417 return false;
10418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
10422
sqianf4ca7ed2019-01-15 18:32:07 -080010423 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010424 * Start emergency callback mode for GsmCdmaPhone for testing.
10425 */
10426 @Override
10427 public void startEmergencyCallbackMode() {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "startEmergencyCallbackMode");
10430 enforceModifyPermission();
10431 final long identity = Binder.clearCallingIdentity();
10432 try {
10433 for (Phone phone : PhoneFactory.getPhones()) {
10434 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10435 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10436 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10437 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10438 gsmCdmaPhone.obtainMessage(
10439 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10440 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10441 }
10442 }
10443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 }
10447
10448 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010449 * Update emergency number list for test mode.
10450 */
10451 @Override
10452 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10453 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10454 "updateEmergencyNumberListTestMode");
10455
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 for (Phone phone: PhoneFactory.getPhones()) {
10459 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10460 if (tracker != null) {
10461 tracker.executeEmergencyNumberTestModeCommand(action, num);
10462 }
10463 }
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
10469 /**
10470 * Get the full emergency number list for test mode.
10471 */
10472 @Override
10473 public List<String> getEmergencyNumberListTestMode() {
10474 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10475 "getEmergencyNumberListTestMode");
10476
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 Set<String> emergencyNumbers = new HashSet<>();
10480 for (Phone phone: PhoneFactory.getPhones()) {
10481 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10482 if (tracker != null) {
10483 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10484 emergencyNumbers.add(num.getNumber());
10485 }
10486 }
10487 }
10488 return new ArrayList<>(emergencyNumbers);
10489 } finally {
10490 Binder.restoreCallingIdentity(identity);
10491 }
10492 }
10493
chen xud6b45bd2018-10-30 22:27:10 -070010494 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010495 public int getEmergencyNumberDbVersion(int subId) {
10496 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10497
joonhunshin4ac60942023-11-15 15:23:39 +000010498 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10499 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10500
Shuo Qian3b6ee772019-11-13 17:43:31 -080010501 final long identity = Binder.clearCallingIdentity();
10502 try {
10503 final Phone phone = getPhone(subId);
10504 if (phone == null) {
10505 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10506 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10507 }
10508 return phone.getEmergencyNumberDbVersion();
10509 } finally {
10510 Binder.restoreCallingIdentity(identity);
10511 }
10512 }
10513
10514 @Override
10515 public void notifyOtaEmergencyNumberDbInstalled() {
10516 enforceModifyPermission();
10517
joonhunshin4ac60942023-11-15 15:23:39 +000010518 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10519 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10520
Shuo Qian3b6ee772019-11-13 17:43:31 -080010521 final long identity = Binder.clearCallingIdentity();
10522 try {
10523 for (Phone phone: PhoneFactory.getPhones()) {
10524 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10525 if (tracker != null) {
10526 tracker.updateOtaEmergencyNumberDatabase();
10527 }
10528 }
10529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
10533
10534 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010535 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010536 enforceActiveEmergencySessionPermission();
10537
joonhunshin4ac60942023-11-15 15:23:39 +000010538 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10539 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10540
Shuo Qian3b6ee772019-11-13 17:43:31 -080010541 final long identity = Binder.clearCallingIdentity();
10542 try {
10543 for (Phone phone: PhoneFactory.getPhones()) {
10544 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10545 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010546 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10547 }
10548 }
10549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
10554 @Override
10555 public void resetOtaEmergencyNumberDbFilePath() {
10556 enforceActiveEmergencySessionPermission();
10557
joonhunshin4ac60942023-11-15 15:23:39 +000010558 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10559 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10560
Shuo Qianc373f112020-03-05 17:55:34 -080010561 final long identity = Binder.clearCallingIdentity();
10562 try {
10563 for (Phone phone: PhoneFactory.getPhones()) {
10564 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10565 if (tracker != null) {
10566 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010567 }
10568 }
10569 } finally {
10570 Binder.restoreCallingIdentity(identity);
10571 }
10572 }
10573
10574 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010575 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10576 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10577 Phone phone = getPhone(subId);
10578 if (phone == null) {
10579 return null;
10580 }
10581 final long identity = Binder.clearCallingIdentity();
10582 try {
10583 UiccProfile profile = UiccController.getInstance()
10584 .getUiccProfileForPhone(phone.getPhoneId());
10585 if (profile != null) {
10586 return profile.getCertsFromCarrierPrivilegeAccessRules();
10587 }
10588 } finally {
10589 Binder.restoreCallingIdentity(identity);
10590 }
10591 return null;
10592 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010593
10594 /**
10595 * Enable or disable a modem stack.
10596 */
10597 @Override
10598 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10599 enforceModifyPermission();
10600
joonhunshin4ac60942023-11-15 15:23:39 +000010601 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10602 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10603
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 Phone phone = PhoneFactory.getPhone(slotIndex);
10607 if (phone == null) {
10608 return false;
10609 } else {
10610 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10611 }
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
Michelecea4cf22018-12-21 15:00:11 -080010616
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010617 /**
10618 * Whether a modem stack is enabled or not.
10619 */
10620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010621 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10622 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010623 Phone phone = PhoneFactory.getPhone(slotIndex);
10624 if (phone == null) return false;
10625
10626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010627 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10628 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010629 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10630 }
10631
joonhunshin4ac60942023-11-15 15:23:39 +000010632 enforceTelephonyFeatureWithException(callingPackage,
10633 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10634
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010635 final long identity = Binder.clearCallingIdentity();
10636 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010637 try {
10638 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10639 } catch (NoSuchElementException ex) {
10640 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10641 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
10646
Michelecea4cf22018-12-21 15:00:11 -080010647 @Override
Michele0ea7d782019-03-19 14:58:42 -070010648 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010649 enforceModifyPermission();
10650
joonhunshin4ac60942023-11-15 15:23:39 +000010651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10652 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10653
Michelecea4cf22018-12-21 15:00:11 -080010654 final long identity = Binder.clearCallingIdentity();
10655 try {
10656 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010657 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010658 .commit();
10659 } finally {
10660 Binder.restoreCallingIdentity(identity);
10661 }
10662 }
10663
10664 @Override
Michele0ea7d782019-03-19 14:58:42 -070010665 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010666 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010668 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10669 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010670 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010671 }
Michelecea4cf22018-12-21 15:00:11 -080010672
joonhunshin4ac60942023-11-15 15:23:39 +000010673 enforceTelephonyFeatureWithException(callingPackage,
10674 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10675
Michelecea4cf22018-12-21 15:00:11 -080010676 final long identity = Binder.clearCallingIdentity();
10677 try {
Michele0ea7d782019-03-19 14:58:42 -070010678 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010683
Michele0ea7d782019-03-19 14:58:42 -070010684 @TelephonyManager.IsMultiSimSupportedResult
10685 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010686 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10687 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10688 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010689 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10690 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010691 }
10692 // Check if the hardware supports multisim functionality. If usage of multisim is not
10693 // supported by the modem, indicate that it is restricted.
10694 PhoneCapability staticCapability =
10695 mPhoneConfigurationManager.getStaticPhoneCapability();
10696 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010697 loge("isMultiSimSupportedInternal: no static configuration available");
10698 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010699 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010700 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010701 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10702 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010703 }
10704 // Check if support of multiple SIMs is restricted by carrier
10705 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010706 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010707 }
10708
Michele0ea7d782019-03-19 14:58:42 -070010709 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010710 }
10711
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010712 /**
10713 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010714 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10715 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10716 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010717 * @param numOfSims number of active sims we want to switch to
10718 */
10719 @Override
10720 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010721 if (numOfSims == 1) {
10722 enforceModifyPermission();
10723 } else {
10724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10725 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10726 }
joonhunshin4ac60942023-11-15 15:23:39 +000010727
10728 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10729 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10730
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010731 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010732
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010733 try {
Michele30b57b22019-03-01 12:01:14 -080010734 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010735 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010736 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10737 return;
10738 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010739 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10740 } finally {
10741 Binder.restoreCallingIdentity(identity);
10742 }
10743 }
10744
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010745 @Override
10746 public boolean isApplicationOnUicc(int subId, int appType) {
10747 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010748
10749 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10750 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10751
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010752 Phone phone = getPhone(subId);
10753 if (phone == null) {
10754 return false;
10755 }
10756 final long identity = Binder.clearCallingIdentity();
10757 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010758 UiccPort uiccPort = phone.getUiccPort();
10759 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010760 return false;
10761 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010762 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010763 if (uiccProfile == null) {
10764 return false;
10765 }
10766 if (TelephonyManager.APPTYPE_SIM <= appType
10767 && appType <= TelephonyManager.APPTYPE_ISIM) {
10768 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10769 }
10770 return false;
10771 } finally {
10772 Binder.restoreCallingIdentity(identity);
10773 }
10774 }
10775
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010776 /**
chen xub4baa772019-04-03 10:23:41 -070010777 * Get whether making changes to modem configurations will trigger reboot.
10778 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010779 */
10780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010781 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10782 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010784 mApp, subId, callingPackage, callingFeatureId,
10785 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010786 return false;
10787 }
joonhunshin4ac60942023-11-15 15:23:39 +000010788
10789 enforceTelephonyFeatureWithException(callingPackage,
10790 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10791 "doesSwitchMultiSimConfigTriggerReboot");
10792
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010793 final long identity = Binder.clearCallingIdentity();
10794 try {
10795 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10796 } finally {
10797 Binder.restoreCallingIdentity(identity);
10798 }
10799 }
10800
Nathan Harold29f5f052019-02-15 13:41:57 -080010801 private void updateModemStateMetrics() {
10802 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10803 // TODO: check the state for each modem if the api is ready.
10804 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10805 }
10806
Pengquan Meng3889a572019-01-23 11:16:29 -080010807 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010808 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010809 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010810 // Verify that the callingPackage belongs to the calling UID
10811 mApp.getSystemService(AppOpsManager.class)
10812 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010813
10814 enforceTelephonyFeatureWithException(callingPackage,
10815 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10816
Pengquan Meng3889a572019-01-23 11:16:29 -080010817 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010818 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010819 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010820 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10821 if (slotInfos != null) {
10822 for (int i = 0; i < slotInfos.length; i++) {
10823 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10824 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10825 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10826 portInfo.getLogicalSlotIndex()));
10827 }
10828 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010829 }
10830 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010831 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010836
10837 /**
10838 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010839 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010840 */
jimsunf9ec1622022-09-13 21:18:43 +080010841 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010842 @Override
10843 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010844 return getHalVersion(HAL_SERVICE_RADIO);
10845 }
10846
10847 /**
10848 * Get the HAL Version of a specific service
10849 */
10850 @Override
10851 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010852 Phone phone = getDefaultPhone();
10853 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010854 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010855 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10856 return hv.major * 100 + hv.minor;
10857 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010858
10859 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010860 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010861 *
10862 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010863 */
10864 @Override
sangyun097dcf72024-01-04 10:35:49 +090010865 public @Nullable String getCurrentPackageName() {
10866 PackageManager pm = mApp.getPackageManager();
10867 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10868 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010869 }
10870
10871 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010872 * @return The calling package name or "phone" if the caller is the phone process. This is done
10873 * because multiple Phone has multiple packages in it and the first element in the array is not
10874 * actually always the caller.
10875 * Note: This is for logging purposes only and should not be used for security checks.
10876 */
10877 private String getCurrentPackageNameOrPhone() {
10878 PackageManager pm = mApp.getPackageManager();
10879 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10880 if (uidName != null && !uidName.isEmpty()) return uidName;
10881 return getCurrentPackageName();
10882 }
10883
10884 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010885 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10886 * corresponding network requests on a subId.
10887 *
10888 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010889 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010890 * 2) APN is un-metered for this subscription, or
10891 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010892 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010893 *
10894 * @return whether data is allowed for a apn type.
10895 *
10896 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010897 */
10898 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010899 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010900 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10901 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010902
joonhunshin4ac60942023-11-15 15:23:39 +000010903 enforceTelephonyFeatureWithException(callingPackage,
10904 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10905
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010906 // Now that all security checks passes, perform the operation as ourselves.
10907 final long identity = Binder.clearCallingIdentity();
10908 try {
10909 Phone phone = getPhone(subId);
10910 if (phone == null) return false;
10911
Jack Yu27422a52022-03-21 10:38:05 -070010912 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010913 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010914 isMetered = phone.getDataNetworkController().getDataConfigManager()
10915 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10916 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010917 isDataEnabled = (phone.getDataSettingsManager() != null)
10918 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010919 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010920 } finally {
10921 Binder.restoreCallingIdentity(identity);
10922 }
10923 }
10924
10925 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010926 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010927 enforceReadPrivilegedPermission("isApnMetered");
10928
joonhunshin4ac60942023-11-15 15:23:39 +000010929 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10930 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10931
Malcolm Chene5ad5792019-04-18 13:51:02 -070010932 // Now that all security checks passes, perform the operation as ourselves.
10933 final long identity = Binder.clearCallingIdentity();
10934 try {
10935 Phone phone = getPhone(subId);
10936 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010937 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10938 DataUtils.apnTypeToNetworkCapability(apnType),
10939 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010944
10945 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010946 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10947 int subscriptionId, IBooleanConsumer resultCallback) {
10948 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010949
10950 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10951 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10952
Hall Liu73f5d362020-01-20 13:42:00 -080010953 long token = Binder.clearCallingIdentity();
10954 try {
10955 Phone phone = getPhone(subscriptionId);
10956 if (phone == null) {
10957 try {
10958 if (resultCallback != null) {
10959 resultCallback.accept(false);
10960 }
10961 } catch (RemoteException e) {
10962 // ignore
10963 }
10964 return;
10965 }
10966 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10967 Pair.create(specifiers, (x) -> {
10968 try {
10969 if (resultCallback != null) {
10970 resultCallback.accept(x);
10971 }
10972 } catch (RemoteException e) {
10973 // ignore
10974 }
10975 });
10976 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10977 } finally {
10978 Binder.restoreCallingIdentity(token);
10979 }
10980 }
10981
10982 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010983 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10984 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010985 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010986 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010987
10988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10989 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10990
Sarah Chin679c08a2020-11-18 13:39:35 -080010991 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010994 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10995 if (result instanceof IllegalStateException) {
10996 throw (IllegalStateException) result;
10997 }
10998 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010999 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11000 return specifiers;
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
11006 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011007 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011008 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011009
11010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11011 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11012
Jack Yu8b766fc2022-03-21 09:42:33 -070011013 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011014 }
11015
11016 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011017 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11018 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011019 if (callingPackage == null) {
11020 callingPackage = getCurrentPackageName();
11021 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011022 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11023 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011024 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11025 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011026 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11027 }
11028 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11029 Intent intent = new Intent();
11030 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11031 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11032 // Bring up choose default SMS subscription dialog right now
11033 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11034 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011035 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011036 }
chen xud5ca2d52019-05-28 15:20:57 -070011037
11038 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011039 public void showSwitchToManagedProfileDialog() {
11040 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011041 try {
11042 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11043 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11044 // for work telephony.
11045 Intent intent = new Intent(Intent.ACTION_SENDTO);
11046 intent.setData(Uri.parse("smsto:"));
11047 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011048 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011049 } catch (ActivityNotFoundException e) {
11050 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11051 Intent intent = new Intent();
11052 intent.setClass(mApp, ErrorDialogActivity.class);
11053 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011054 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011055 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011056 }
11057
11058 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011059 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11061 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11062
chen xud5ca2d52019-05-28 15:20:57 -070011063 //TODO investigate if this API should require proper permission check in R b/133791609
11064 final long identity = Binder.clearCallingIdentity();
11065 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011066 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11067 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11068 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11069 return carrierUAProfUrl;
11070 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011071 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11072 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
11077
11078 @Override
11079 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011080 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11081 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11082
chen xud5ca2d52019-05-28 15:20:57 -070011083 //TODO investigate if this API should require proper permission check in R b/133791609
11084 final long identity = Binder.clearCallingIdentity();
11085 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011086 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11087 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11088 if (!TextUtils.isEmpty(carrierUserAgent)) {
11089 return carrierUserAgent;
11090 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011091 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11092 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011093 } finally {
11094 Binder.restoreCallingIdentity(identity);
11095 }
11096 }
Jack Yub07d4972019-05-28 16:12:25 -070011097
11098 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011099 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11100 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011101
joonhunshin4ac60942023-11-15 15:23:39 +000011102 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11103 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11104
Jack Yub07d4972019-05-28 16:12:25 -070011105 final long identity = Binder.clearCallingIdentity();
11106 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011107 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011108 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011109
Ling Maf188d502022-09-16 15:22:36 -070011110 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011111 } finally {
11112 Binder.restoreCallingIdentity(identity);
11113 }
11114 }
11115
11116 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011117 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011118 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011119 enforceModifyPermission();
11120
joonhunshin4ac60942023-11-15 15:23:39 +000011121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11122 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11123
changbettyd5c246e2019-12-24 15:40:37 +080011124 final long identity = Binder.clearCallingIdentity();
11125 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011126 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011127 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011128
Ling Maf188d502022-09-16 15:22:36 -070011129 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
11134
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011135 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011136 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011137 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11138 * otherwise.
11139 */
11140 @Override
11141 public void setCepEnabled(boolean isCepEnabled) {
11142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11143
11144 final long identity = Binder.clearCallingIdentity();
11145 try {
11146 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11147 for (Phone phone : PhoneFactory.getPhones()) {
11148 Phone defaultPhone = phone.getImsPhone();
11149 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11150 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11151 ImsPhoneCallTracker imsPhoneCallTracker =
11152 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11153 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11154 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11155 + imsPhone.getMsisdn());
11156 }
11157 }
11158 } finally {
11159 Binder.restoreCallingIdentity(identity);
11160 }
11161 }
allenwtsu46dcc572020-01-08 18:24:03 +080011162
11163 /**
11164 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11165 *
11166 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11167 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11168 * before being read.
11169 */
11170 @Override
11171 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11172 isCompressed) {
11173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11174 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11176 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11177 }
joonhunshin4ac60942023-11-15 15:23:39 +000011178
11179 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11180 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11181 Binder.getCallingUserHandle())) {
11182 if (!isImsAvailableOnDevice()) {
11183 // ProvisioningManager can not handle ServiceSpecificException.
11184 // Throw the IllegalStateException and annotate ProvisioningManager.
11185 throw new IllegalStateException("IMS not available on device.");
11186 }
11187 } else {
11188 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11189 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11190 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011191 }
11192
11193 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011194 try {
Hui Wang761a6682020-10-31 05:12:53 +000011195 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011198 }
11199 }
zoey chene02881a2019-12-30 16:11:23 +080011200
11201 @Override
11202 public boolean isIccLockEnabled(int subId) {
11203 enforceReadPrivilegedPermission("isIccLockEnabled");
11204
joonhunshin4ac60942023-11-15 15:23:39 +000011205 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11206 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11207
zoey chene02881a2019-12-30 16:11:23 +080011208 // Now that all security checks passes, perform the operation as ourselves.
11209 final long identity = Binder.clearCallingIdentity();
11210 try {
11211 Phone phone = getPhone(subId);
11212 if (phone != null && phone.getIccCard() != null) {
11213 return phone.getIccCard().getIccLockEnabled();
11214 } else {
11215 return false;
11216 }
11217 } finally {
11218 Binder.restoreCallingIdentity(identity);
11219 }
11220 }
11221
11222 /**
11223 * Set the ICC pin lock enabled or disabled.
11224 *
11225 * @return an integer representing the status of IccLock enabled or disabled in the following
11226 * three cases:
11227 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11228 * successfully.
11229 * - Positive number and zero for remaining password attempts.
11230 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11231 *
11232 */
11233 @Override
11234 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11235 enforceModifyPermission();
11236
joonhunshin4ac60942023-11-15 15:23:39 +000011237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11238 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11239
zoey chene02881a2019-12-30 16:11:23 +080011240 Phone phone = getPhone(subId);
11241 if (phone == null) {
11242 return 0;
11243 }
11244 // Now that all security checks passes, perform the operation as ourselves.
11245 final long identity = Binder.clearCallingIdentity();
11246 try {
11247 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11248 new Pair<Boolean, String>(enabled, password), phone, null);
11249 return attemptsRemaining;
11250
11251 } catch (Exception e) {
11252 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11253 } finally {
11254 Binder.restoreCallingIdentity(identity);
11255 }
11256 return 0;
11257 }
11258
11259 /**
11260 * Change the ICC password used in ICC pin lock.
11261 *
11262 * @return an integer representing the status of IccLock changed in the following three cases:
11263 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11264 * - Positive number and zero for remaining password attempts.
11265 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11266 *
11267 */
11268 @Override
11269 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11270 enforceModifyPermission();
11271
joonhunshin4ac60942023-11-15 15:23:39 +000011272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11273 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11274
zoey chene02881a2019-12-30 16:11:23 +080011275 Phone phone = getPhone(subId);
11276 if (phone == null) {
11277 return 0;
11278 }
11279 // Now that all security checks passes, perform the operation as ourselves.
11280 final long identity = Binder.clearCallingIdentity();
11281 try {
11282 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11283 new Pair<String, String>(oldPassword, newPassword), phone, null);
11284 return attemptsRemaining;
11285
11286 } catch (Exception e) {
11287 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11288 } finally {
11289 Binder.restoreCallingIdentity(identity);
11290 }
11291 return 0;
11292 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011293
11294 /**
11295 * Request for receiving user activity notification
11296 */
11297 @Override
11298 public void requestUserActivityNotification() {
11299 if (!mNotifyUserActivity.get()
11300 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11301 mNotifyUserActivity.set(true);
11302 }
11303 }
11304
11305 /**
11306 * Called when userActivity is signalled in the power manager.
11307 * This is safe to call from any thread, with any window manager locks held or not.
11308 */
11309 @Override
11310 public void userActivity() {
11311 // ***************************************
11312 // * Inherited from PhoneWindowManager *
11313 // ***************************************
11314 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11315 // WITH ITS LOCKS HELD.
11316 //
11317 // This code must be VERY careful about the locks
11318 // it acquires.
11319 // In fact, the current code acquires way too many,
11320 // and probably has lurking deadlocks.
11321
Jack Yu86374492024-09-16 13:05:44 -070011322 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011323 throw new SecurityException("Only the OS may call notifyUserActivity()");
11324 }
11325
11326 if (mNotifyUserActivity.getAndSet(false)) {
11327 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11328 USER_ACTIVITY_NOTIFICATION_DELAY);
11329 }
11330 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011331
11332 @Override
11333 public boolean canConnectTo5GInDsdsMode() {
11334 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11335 }
Jack Yud10cdd42020-09-28 20:28:01 -070011336
11337 @Override
11338 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11339 String callingFeatureId) {
11340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11341 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11342 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11343 }
11344
joonhunshin4ac60942023-11-15 15:23:39 +000011345 enforceTelephonyFeatureWithException(callingPackage,
11346 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11347
Jack Yud10cdd42020-09-28 20:28:01 -070011348 Phone phone = getPhone(subId);
11349 if (phone == null) {
11350 throw new RuntimeException("phone is not available");
11351 }
11352 // Now that all security checks passes, perform the operation as ourselves.
11353 final long identity = Binder.clearCallingIdentity();
11354 try {
11355 return phone.getEquivalentHomePlmns();
11356 } finally {
11357 Binder.restoreCallingIdentity(identity);
11358 }
11359 }
Daniel Bright59e67312020-11-13 11:49:37 -080011360
11361 @Override
11362 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011363 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011364 if (!mApp.getResources().getBoolean(
11365 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11366 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11367 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11368 "isRadioInterfaceCapabilitySupported");
11369 }
joonhunshin4ac60942023-11-15 15:23:39 +000011370
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011371 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011372 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011373 if (radioInterfaceCapabilities == null) {
11374 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011375 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011376 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011377 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011378
Hui Wang641e81c2020-10-12 12:14:23 -070011379 @Override
11380 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11381 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011382 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11383 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11384 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11385 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11386 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011387
11388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11389 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11390
Hui Wang641e81c2020-10-12 12:14:23 -070011391 if (DBG) {
11392 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11393 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11394 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11395 }
11396
11397 if (!SubscriptionManager.isValidSubscriptionId(subId)
11398 || appType < TelephonyManager.APPTYPE_UNKNOWN
11399 || appType > TelephonyManager.APPTYPE_ISIM
11400 || nafUrl == null || securityProtocol == null || callback == null) {
11401 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11402 if (callback != null) {
11403 try {
11404 callback.onAuthenticationFailure(
11405 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11406 } catch (RemoteException exception) {
11407 log("Fail to notify onAuthenticationFailure due to " + exception);
11408 }
11409 return;
11410 }
11411 }
11412
11413 final long token = Binder.clearCallingIdentity();
11414 try {
11415 getGbaManager(subId).bootstrapAuthenticationRequest(
11416 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011417 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011418 } finally {
11419 Binder.restoreCallingIdentity(token);
11420 }
11421 }
11422
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011423 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011424 * Attempts to set the radio power state for all phones for thermal reason.
11425 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011426 * requested radio power state will actually be set. See {@link
11427 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11428 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011429 * @param enable {@code true} if trying to turn radio on.
11430 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11431 * false}.
11432 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011433 private boolean setRadioPowerForThermal(boolean enable) {
11434 boolean isPhoneAvailable = false;
11435 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11436 Phone phone = PhoneFactory.getPhone(i);
11437 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011438 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011439 isPhoneAvailable = true;
11440 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011441 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011442
11443 // return true if successfully informed the phone object about the thermal radio power
11444 // request.
11445 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011446 }
11447
11448 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011449 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011450 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11451 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11452 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11453 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11454 throw new IllegalArgumentException("modem does not support data throttling");
11455 }
11456
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011457 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11458 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011459 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011460 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11461 }
11462
Sarah Chinecc78c42022-03-31 21:16:48 -070011463 setDataEnabledForReason(
11464 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011465
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011466 if (isDataThrottlingSupported) {
11467 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011468 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011469 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11470 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11471 } else if (thermalMitigationResult
11472 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011473 log("Modem likely does not support data throttling on secondary carrier. Data " +
11474 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11475 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011476 }
11477 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011478 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011479
11480 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011481 }
11482
Jack Nudelman644b91a2021-03-12 14:09:48 -080011483 private static List<String> getThermalMitigationAllowlist(Context context) {
11484 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11485 for (String pckg : context.getResources()
11486 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11487 sThermalMitigationAllowlistedPackages.add(pckg);
11488 }
11489 }
11490
11491 return sThermalMitigationAllowlistedPackages;
11492 }
11493
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011494 private boolean isAnyPhoneInEmergencyState() {
11495 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11496 if (tm.isInEmergencyCall()) {
11497 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11498 return true;
11499 }
11500 for (Phone phone : PhoneFactory.getPhones()) {
11501 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11502 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011503 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11504 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011505 return true;
11506 }
11507 }
11508
11509 return false;
11510 }
11511
Jack Nudelman644b91a2021-03-12 14:09:48 -080011512 /**
11513 * Used by shell commands to add an authorized package name for thermal mitigation.
11514 * @param packageName name of package to be allowlisted
11515 * @param context
11516 */
11517 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11518 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11519 sThermalMitigationAllowlistedPackages.add(packageName);
11520 }
11521
11522 /**
11523 * Used by shell commands to remove an authorized package name for thermal mitigation.
11524 * @param packageName name of package to remove from allowlist
11525 * @param context
11526 */
11527 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11528 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11529 sThermalMitigationAllowlistedPackages.remove(packageName);
11530 }
11531
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 /**
11533 * Thermal mitigation request to control functionalities at modem.
11534 *
11535 * @param subId the id of the subscription.
11536 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011537 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011538 *
11539 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11540 */
11541 @Override
11542 @ThermalMitigationResult
11543 public int sendThermalMitigationRequest(
11544 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011545 ThermalMitigationRequest thermalMitigationRequest,
11546 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011547 enforceModifyPermission();
11548
Jack Nudelman644b91a2021-03-12 14:09:48 -080011549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011550
11551 enforceTelephonyFeatureWithException(callingPackage,
11552 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11553
Jack Nudelman644b91a2021-03-12 14:09:48 -080011554 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11555 .contains(callingPackage)) {
11556 throw new SecurityException("Calling package must be configured in the device config. "
11557 + "calling package: " + callingPackage);
11558 }
11559
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011560 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11561 final long identity = Binder.clearCallingIdentity();
11562
11563 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11564 try {
11565 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11566 switch (thermalMitigationAction) {
11567 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11568 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011569 handleDataThrottlingRequest(subId,
11570 thermalMitigationRequest.getDataThrottlingRequest(),
11571 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011572 break;
11573 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11574 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11575 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11576 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11577 }
11578
11579 // Ensure that radio is on. If not able to power on due to phone being
11580 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011581 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011582 thermalMitigationResult =
11583 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11584 break;
11585 }
11586
11587 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011588 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011589 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11590 break;
11591 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11592 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11593 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11594 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11595 }
11596
11597 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11598 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011599 Phone phone = getPhone(subId);
11600 if (phone == null) {
11601 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011602 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011603 break;
11604 }
11605
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011606 TelephonyConnectionService service =
11607 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011608 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011609 Log.e(LOG_TAG, "An emergency call is pending");
11610 thermalMitigationResult =
11611 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11612 break;
11613 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011614 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011615 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011616 break;
11617 }
11618 } else {
11619 thermalMitigationResult =
11620 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11621 break;
11622 }
11623
11624 // Turn radio off. If not able to power off due to phone being unavailable,
11625 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011626 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011627 thermalMitigationResult =
11628 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11629 break;
11630 }
11631 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011632 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011633 break;
11634 default:
11635 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11636 + "not exist. Requested action: " + thermalMitigationAction);
11637 }
11638 } catch (IllegalArgumentException e) {
11639 throw e;
11640 } catch (Exception e) {
11641 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11642 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11643 } finally {
11644 Binder.restoreCallingIdentity(identity);
11645 }
11646
11647 if (DBG) {
11648 log("thermalMitigationRequest returning with thermalMitigationResult: "
11649 + thermalMitigationResult);
11650 }
11651
11652 return thermalMitigationResult;
11653 }
Hui Wang641e81c2020-10-12 12:14:23 -070011654
11655 /**
11656 * Set the GbaService Package Name that Telephony will bind to.
11657 *
11658 * @param subId The sim that the GbaService is associated with.
11659 * @param packageName The name of the package to be replaced with.
11660 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11661 */
11662 @Override
11663 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11664 enforceModifyPermission();
11665
11666 final long identity = Binder.clearCallingIdentity();
11667 try {
11668 return getGbaManager(subId).overrideServicePackage(packageName);
11669 } finally {
11670 Binder.restoreCallingIdentity(identity);
11671 }
11672 }
11673
11674 /**
11675 * Return the package name of the currently bound GbaService.
11676 *
11677 * @param subId The sim that the GbaService is associated with.
11678 * @return the package name of the GbaService configuration, null if GBA is not supported.
11679 */
11680 @Override
11681 public String getBoundGbaService(int subId) {
11682 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11683
11684 final long identity = Binder.clearCallingIdentity();
11685 try {
11686 return getGbaManager(subId).getServicePackage();
11687 } finally {
11688 Binder.restoreCallingIdentity(identity);
11689 }
11690 }
11691
11692 /**
11693 * Set the release time for telephony to unbind GbaService.
11694 *
11695 * @param subId The sim that the GbaService is associated with.
11696 * @param interval The release time to unbind GbaService by millisecond.
11697 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11698 */
11699 @Override
11700 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11701 enforceModifyPermission();
11702
11703 final long identity = Binder.clearCallingIdentity();
11704 try {
11705 return getGbaManager(subId).overrideReleaseTime(interval);
11706 } finally {
11707 Binder.restoreCallingIdentity(identity);
11708 }
11709 }
11710
11711 /**
11712 * Return the release time for telephony to unbind GbaService.
11713 *
11714 * @param subId The sim that the GbaService is associated with.
11715 * @return The release time to unbind GbaService by millisecond.
11716 */
11717 @Override
11718 public int getGbaReleaseTime(int subId) {
11719 enforceReadPrivilegedPermission("getGbaReleaseTime");
11720
11721 final long identity = Binder.clearCallingIdentity();
11722 try {
11723 return getGbaManager(subId).getReleaseTime();
11724 } finally {
11725 Binder.restoreCallingIdentity(identity);
11726 }
11727 }
11728
11729 private GbaManager getGbaManager(int subId) {
11730 GbaManager instance = GbaManager.getInstance(subId);
11731 if (instance == null) {
11732 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11733 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11734 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11735 }
11736 return instance;
11737 }
Hui Wang761a6682020-10-31 05:12:53 +000011738
11739 /**
11740 * indicate whether the device and the carrier can support
11741 * RCS VoLTE single registration.
11742 */
11743 @Override
11744 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011745 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11746 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11747 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11748 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011749
11750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11751 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11752 }
11753
11754 final long identity = Binder.clearCallingIdentity();
11755 try {
11756 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11757 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011758 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11759 if (isCapable != null) {
11760 return isCapable;
11761 }
Hui Wang761a6682020-10-31 05:12:53 +000011762 }
Hui Wang67af90e2021-06-04 16:57:15 -070011763 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11764 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011765 } finally {
11766 Binder.restoreCallingIdentity(identity);
11767 }
11768 }
11769
11770 /**
11771 * Register RCS provisioning callback.
11772 */
11773 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011774 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011775 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011776 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011777 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011778 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11779 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011780
11781 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11782 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11783 }
joonhunshin4ac60942023-11-15 15:23:39 +000011784 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11785 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11786 Binder.getCallingUserHandle())) {
11787 if (!isImsAvailableOnDevice()) {
11788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11789 "IMS not available on device.");
11790 }
11791 } else {
11792 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11793 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011794 }
11795
11796 final long identity = Binder.clearCallingIdentity();
11797 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011798 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011799 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011800 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11801 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011802 }
Hui Wang761a6682020-10-31 05:12:53 +000011803 } finally {
11804 Binder.restoreCallingIdentity(identity);
11805 }
11806 }
11807
11808 /**
11809 * Unregister RCS provisioning callback.
11810 */
11811 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011812 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011813 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011814 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011815 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011816 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11817 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011818
11819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11820 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11821 }
joonhunshin4ac60942023-11-15 15:23:39 +000011822
11823 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11824 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11825 Binder.getCallingUserHandle())) {
11826 if (!isImsAvailableOnDevice()) {
11827 // operation failed silently
11828 Rlog.w(LOG_TAG, "IMS not available on device.");
11829 return;
11830 }
11831 } else {
11832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11833 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11834 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011835 }
11836
11837 final long identity = Binder.clearCallingIdentity();
11838 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011839 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011840 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011841 } finally {
11842 Binder.restoreCallingIdentity(identity);
11843 }
11844 }
11845
11846 /**
11847 * trigger RCS reconfiguration.
11848 */
11849 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011850 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11851 "triggerRcsReconfiguration",
11852 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011853
11854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11855 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11856 }
joonhunshin4ac60942023-11-15 15:23:39 +000011857 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11858 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11859 Binder.getCallingUserHandle())) {
11860 if (!isImsAvailableOnDevice()) {
11861 // ProvisioningManager can not handle ServiceSpecificException.
11862 // Throw the IllegalStateException and annotate ProvisioningManager.
11863 throw new IllegalStateException("IMS not available on device.");
11864 }
11865 } else {
11866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11867 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011868 }
11869
11870 final long identity = Binder.clearCallingIdentity();
11871 try {
11872 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11873 } finally {
11874 Binder.restoreCallingIdentity(identity);
11875 }
11876 }
11877
11878 /**
11879 * Provide the client configuration parameters of the RCS application.
11880 */
11881 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011882 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11883 "setRcsClientConfiguration",
11884 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011885
11886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11887 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11888 }
joonhunshin4ac60942023-11-15 15:23:39 +000011889 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11890 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11891 Binder.getCallingUserHandle())) {
11892 if (!isImsAvailableOnDevice()) {
11893 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11894 "IMS not available on device.");
11895 }
11896 } else {
11897 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11898 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011899 }
11900
11901 final long identity = Binder.clearCallingIdentity();
11902
11903 try {
11904 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11905 if (configBinder == null) {
11906 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011907 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11908 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011909 } else {
11910 configBinder.setRcsClientConfiguration(rcc);
11911 }
joonhunshin3e154242021-09-17 06:33:39 +000011912
11913 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11914 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011915 } catch (RemoteException e) {
11916 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011917 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11918 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011919 } finally {
11920 Binder.restoreCallingIdentity(identity);
11921 }
11922 }
11923
11924 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011925 * Enables or disables the test mode for RCS VoLTE single registration.
11926 */
11927 @Override
11928 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11929 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11930 "setRcsSingleRegistrationTestModeEnabled");
11931
11932 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11933 }
11934
11935 /**
11936 * Gets the test mode for RCS VoLTE single registration.
11937 */
11938 @Override
11939 public boolean getRcsSingleRegistrationTestModeEnabled() {
11940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11941 "getRcsSingleRegistrationTestModeEnabled");
11942
11943 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11944 }
11945
11946 /**
Hui Wang761a6682020-10-31 05:12:53 +000011947 * Overrides the config of RCS VoLTE single registration enabled for the device.
11948 */
11949 @Override
11950 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11952 "setDeviceSingleRegistrationEnabledOverride");
11953 enforceModifyPermission();
11954
11955 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11956 : Boolean.parseBoolean(enabledStr);
11957 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011958 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011959 }
11960
11961 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011962 * Sends a device to device communication message. Only usable via shell.
11963 * @param message message to send.
11964 * @param value message value.
11965 */
11966 @Override
11967 public void sendDeviceToDeviceMessage(int message, int value) {
11968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011969 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011970 enforceModifyPermission();
11971
11972 final long identity = Binder.clearCallingIdentity();
11973 try {
11974 TelephonyConnectionService service =
11975 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11976 if (service == null) {
11977 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11978 return;
11979 }
11980 service.sendTestDeviceToDeviceMessage(message, value);
11981 } finally {
11982 Binder.restoreCallingIdentity(identity);
11983 }
11984 }
11985
Tyler Gunnbabbda02021-02-10 11:05:02 -080011986 /**
11987 * Sets the specified device to device transport active.
11988 * @param transport The transport to set active.
11989 */
11990 @Override
11991 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11993 "setActiveDeviceToDeviceTransport");
11994 enforceModifyPermission();
11995
11996 final long identity = Binder.clearCallingIdentity();
11997 try {
11998 TelephonyConnectionService service =
11999 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12000 if (service == null) {
12001 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12002 return;
12003 }
12004 service.setActiveDeviceToDeviceTransport(transport);
12005 } finally {
12006 Binder.restoreCallingIdentity(identity);
12007 }
12008 }
Tyler Gunn92479152021-01-20 16:30:10 -080012009
Tyler Gunnd4339262021-05-03 14:46:49 -070012010 @Override
12011 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12013 "setDeviceToDeviceForceEnabled");
12014
12015 final long identity = Binder.clearCallingIdentity();
12016 try {
12017 Arrays.stream(PhoneFactory.getPhones()).forEach(
12018 p -> {
12019 Phone thePhone = p.getImsPhone();
12020 if (thePhone != null && thePhone instanceof ImsPhone) {
12021 ImsPhone imsPhone = (ImsPhone) thePhone;
12022 CallTracker tracker = imsPhone.getCallTracker();
12023 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12024 ImsPhoneCallTracker imsPhoneCallTracker =
12025 (ImsPhoneCallTracker) tracker;
12026 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12027 }
12028 }
12029 }
12030 );
12031 } finally {
12032 Binder.restoreCallingIdentity(identity);
12033 }
12034 }
12035
Tyler Gunn92479152021-01-20 16:30:10 -080012036 /**
Hui Wang761a6682020-10-31 05:12:53 +000012037 * Gets the config of RCS VoLTE single registration enabled for the device.
12038 */
12039 @Override
12040 public boolean getDeviceSingleRegistrationEnabled() {
12041 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12042 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12043 }
12044
12045 /**
12046 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12047 */
12048 @Override
12049 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12051 "setCarrierSingleRegistrationEnabledOverride");
12052 enforceModifyPermission();
12053
12054 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12055 : Boolean.parseBoolean(enabledStr);
12056 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12057 subId, enabled);
12058 }
12059
12060 /**
12061 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12062 */
12063 @Override
12064 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12065 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12066 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12067 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012068
12069 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012070 * Overrides the ims feature validation result
12071 */
12072 @Override
12073 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12075 "setImsFeatureValidationOverride");
12076
12077 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12078 : Boolean.parseBoolean(enabledStr);
12079 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12080 subId, enabled);
12081 }
12082
12083 /**
12084 * Gets the ims feature validation override value
12085 */
12086 @Override
12087 public boolean getImsFeatureValidationOverride(int subId) {
12088 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12089 "getImsFeatureValidationOverride");
12090 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12091 }
12092
12093 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012094 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12095 * their mobile plan.
12096 */
12097 @Override
12098 public String getMobileProvisioningUrl() {
12099 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12100 final long identity = Binder.clearCallingIdentity();
12101 try {
12102 return getDefaultPhone().getMobileProvisioningUrl();
12103 } finally {
12104 Binder.restoreCallingIdentity(identity);
12105 }
12106 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012107
James.cf Linbcdf8b32021-01-14 16:44:13 +080012108 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012109 * Get the EAB contact from the EAB database.
12110 */
12111 @Override
12112 public String getContactFromEab(String contact) {
12113 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12114 enforceModifyPermission();
12115 final long identity = Binder.clearCallingIdentity();
12116 try {
12117 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12118 } finally {
12119 Binder.restoreCallingIdentity(identity);
12120 }
12121 }
12122
12123 /**
Calvin Pana1434322021-07-01 19:27:01 +080012124 * Get the EAB capability from the EAB database.
12125 */
12126 @Override
12127 public String getCapabilityFromEab(String contact) {
12128 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12129 enforceModifyPermission();
12130 final long identity = Binder.clearCallingIdentity();
12131 try {
12132 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12133 } finally {
12134 Binder.restoreCallingIdentity(identity);
12135 }
12136 }
12137
12138 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012139 * Remove the EAB contacts from the EAB database.
12140 */
12141 @Override
12142 public int removeContactFromEab(int subId, String contacts) {
12143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12144 enforceModifyPermission();
12145 final long identity = Binder.clearCallingIdentity();
12146 try {
12147 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12148 } finally {
12149 Binder.restoreCallingIdentity(identity);
12150 }
12151 }
12152
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012153 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012154 public boolean getDeviceUceEnabled() {
12155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12156 final long identity = Binder.clearCallingIdentity();
12157 try {
12158 return mApp.getDeviceUceEnabled();
12159 } finally {
12160 Binder.restoreCallingIdentity(identity);
12161 }
12162 }
12163
12164 @Override
12165 public void setDeviceUceEnabled(boolean isEnabled) {
12166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12167 final long identity = Binder.clearCallingIdentity();
12168 try {
12169 mApp.setDeviceUceEnabled(isEnabled);
12170 } finally {
12171 Binder.restoreCallingIdentity(identity);
12172 }
12173 }
12174
Brad Ebinger14d467f2021-02-12 06:18:28 +000012175 /**
12176 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12177 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12178 */
12179 // Used for SHELL command only right now.
12180 @Override
12181 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12182 List<String> featureTags) {
12183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12184 "addUceRegistrationOverrideShell");
12185 final long identity = Binder.clearCallingIdentity();
12186 try {
12187 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12188 new ArraySet<>(featureTags));
12189 } catch (ImsException e) {
12190 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12191 } finally {
12192 Binder.restoreCallingIdentity(identity);
12193 }
12194 }
12195
12196 /**
12197 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12198 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12199 */
12200 // Used for SHELL command only right now.
12201 @Override
12202 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12203 List<String> featureTags) {
12204 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12205 "removeUceRegistrationOverrideShell");
12206 final long identity = Binder.clearCallingIdentity();
12207 try {
12208 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12209 new ArraySet<>(featureTags));
12210 } catch (ImsException e) {
12211 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12212 } finally {
12213 Binder.restoreCallingIdentity(identity);
12214 }
12215 }
12216
12217 /**
12218 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12219 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12220 */
12221 // Used for SHELL command only right now.
12222 @Override
12223 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12224 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12225 "clearUceRegistrationOverrideShell");
12226 final long identity = Binder.clearCallingIdentity();
12227 try {
12228 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12229 } catch (ImsException e) {
12230 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12231 } finally {
12232 Binder.restoreCallingIdentity(identity);
12233 }
12234 }
12235
12236 /**
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 getLatestRcsContactUceCapabilityShell(int subId) {
12242 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12243 "getLatestRcsContactUceCapabilityShell");
12244 final long identity = Binder.clearCallingIdentity();
12245 try {
12246 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12247 } catch (ImsException e) {
12248 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12249 } finally {
12250 Binder.restoreCallingIdentity(identity);
12251 }
12252 }
12253
12254 /**
12255 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12256 * device does not have an active PUBLISH.
12257 */
12258 // Used for SHELL command only right now.
12259 @Override
12260 public String getLastUcePidfXmlShell(int subId) {
12261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12262 final long identity = Binder.clearCallingIdentity();
12263 try {
12264 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12265 } catch (ImsException e) {
12266 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12267 } finally {
12268 Binder.restoreCallingIdentity(identity);
12269 }
12270 }
12271
James.cf Line8713a42021-04-29 16:04:26 +080012272 /**
12273 * Remove UCE requests cannot be sent to the network status.
12274 */
12275 // Used for SHELL command only right now.
12276 @Override
12277 public boolean removeUceRequestDisallowedStatus(int subId) {
12278 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12279 final long identity = Binder.clearCallingIdentity();
12280 try {
12281 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12282 } catch (ImsException e) {
12283 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12284 } finally {
12285 Binder.restoreCallingIdentity(identity);
12286 }
12287 }
12288
James.cf Lin18bb9002021-05-25 01:37:38 +080012289 /**
12290 * Remove UCE requests cannot be sent to the network status.
12291 */
12292 // Used for SHELL command only.
12293 @Override
12294 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12295 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12296 final long identity = Binder.clearCallingIdentity();
12297 try {
12298 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12299 } catch (ImsException e) {
12300 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12301 } finally {
12302 Binder.restoreCallingIdentity(identity);
12303 }
12304 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012305
James.cf Lin4b784aa2021-01-31 03:25:15 +080012306 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012307 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12308 String callingPackage) {
12309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12310 mApp, subId, "setSignalStrengthUpdateRequest");
12311
joonhunshin4ac60942023-11-15 15:23:39 +000012312 enforceTelephonyFeatureWithException(callingPackage,
12313 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12314
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012315 final int callingUid = Binder.getCallingUid();
12316 // Verify that tha callingPackage belongs to the calling UID
12317 mApp.getSystemService(AppOpsManager.class)
12318 .checkPackage(callingUid, callingPackage);
12319
Rambo Wang3607f502021-02-01 21:51:40 -080012320 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012321
12322 final long identity = Binder.clearCallingIdentity();
12323 try {
12324 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12325 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12326
12327 if (result instanceof IllegalStateException) {
12328 throw (IllegalStateException) result;
12329 }
12330 } finally {
12331 Binder.restoreCallingIdentity(identity);
12332 }
12333 }
12334
12335 @Override
12336 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12337 String callingPackage) {
12338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12339 mApp, subId, "clearSignalStrengthUpdateRequest");
12340
joonhunshin4ac60942023-11-15 15:23:39 +000012341 enforceTelephonyFeatureWithException(callingPackage,
12342 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12343
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012344 final int callingUid = Binder.getCallingUid();
12345 // Verify that tha callingPackage belongs to the calling UID
12346 mApp.getSystemService(AppOpsManager.class)
12347 .checkPackage(callingUid, callingPackage);
12348
12349 final long identity = Binder.clearCallingIdentity();
12350 try {
12351 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12352 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12353
12354 if (result instanceof IllegalStateException) {
12355 throw (IllegalStateException) result;
12356 }
12357 } finally {
12358 Binder.restoreCallingIdentity(identity);
12359 }
12360 }
12361
Rambo Wang3607f502021-02-01 21:51:40 -080012362 private static void validateSignalStrengthUpdateRequest(Context context,
12363 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012364 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012365 // phone/system process do not have further restriction on request
12366 return;
12367 }
12368
12369 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012370 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012371 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012372 context.enforceCallingOrSelfPermission(
12373 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12374 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012375 }
12376
12377 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012378 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012379 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012380 || info.isEnabled()) {
12381 throw new IllegalArgumentException(
12382 "Only system can set hide fields in SignalThresholdInfo");
12383 }
12384
12385 // Thresholds length for each RAN need in range. This has been validated in
12386 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12387 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12388 final int[] thresholds = info.getThresholds();
12389 Objects.requireNonNull(thresholds);
12390 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12391 || thresholds.length
12392 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12393 throw new IllegalArgumentException(
12394 "thresholds length is out of range: " + thresholds.length);
12395 }
12396 }
12397 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012398
12399 /**
12400 * Gets the current phone capability.
12401 *
12402 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12403 * @return the PhoneCapability which describes the data connection capability of modem.
12404 * It's used to evaluate possible phone config change, for example from single
12405 * SIM device to multi-SIM device.
12406 */
12407 @Override
12408 public PhoneCapability getPhoneCapability() {
12409 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012410
12411 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12412 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12413
SongFerngWang8236caa2021-01-17 21:51:44 +080012414 final long identity = Binder.clearCallingIdentity();
12415 try {
12416 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12417 } finally {
12418 Binder.restoreCallingIdentity(identity);
12419 }
12420 }
Michele Berionne5e411512020-11-13 02:36:59 +000012421
12422 /**
12423 * Prepare TelephonyManager for an unattended reboot. The reboot is
12424 * required to be done shortly after the API is invoked.
12425 */
12426 @Override
12427 @TelephonyManager.PrepareUnattendedRebootResult
12428 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012429 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012430 enforceRebootPermission();
12431
joonhunshin4ac60942023-11-15 15:23:39 +000012432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12433 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12434
Michele Berionne5e411512020-11-13 02:36:59 +000012435 final long identity = Binder.clearCallingIdentity();
12436 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012437 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012438 } finally {
12439 Binder.restoreCallingIdentity(identity);
12440 }
12441 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012442
12443 /**
12444 * Request to get the current slicing configuration including URSP rules and
12445 * NSSAIs (configured, allowed and rejected).
12446 *
12447 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12448 */
12449 @Override
12450 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012451 TelephonyPermissions
12452 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12453 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012454
joonhunshin4ac60942023-11-15 15:23:39 +000012455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12456 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12457 "getSlicingConfig");
12458
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012459 final long identity = Binder.clearCallingIdentity();
12460 try {
12461 Phone phone = getDefaultPhone();
12462 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12463 } finally {
12464 Binder.restoreCallingIdentity(identity);
12465 }
12466 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012467
12468 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012469 * Check whether the given premium capability is available for purchase from the carrier.
12470 *
12471 * @param capability The premium capability to check.
12472 * @param subId The subId to check the premium capability for.
12473 *
12474 * @return Whether the given premium capability is available to purchase.
12475 */
12476 @Override
12477 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12478 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12479 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12480 log("Premium capability "
12481 + TelephonyManager.convertPremiumCapabilityToString(capability)
12482 + " is not available for purchase due to missing permissions.");
12483 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12484 + "permission READ_BASIC_PHONE_STATE.");
12485 }
12486
joonhunshin4ac60942023-11-15 15:23:39 +000012487 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12488 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12489
Sarah Chin2ec39f62022-08-31 17:03:26 -070012490 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012491 if (phone == null) {
12492 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12493 return false;
12494 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012495 final long identity = Binder.clearCallingIdentity();
12496 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012497 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012498 .isPremiumCapabilityAvailableForPurchase(capability);
12499 } finally {
12500 Binder.restoreCallingIdentity(identity);
12501 }
12502 }
12503
12504 /**
12505 * Purchase the given premium capability from the carrier.
12506 *
12507 * @param capability The premium capability to purchase.
12508 * @param callback The result of the purchase request.
12509 * @param subId The subId to purchase the premium capability for.
12510 */
12511 @Override
12512 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12513 log("purchasePremiumCapability: capability="
12514 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12515 + getCurrentPackageName());
12516
12517 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12518 mApp, "purchasePremiumCapability")) {
12519 log("purchasePremiumCapability "
12520 + TelephonyManager.convertPremiumCapabilityToString(capability)
12521 + " failed due to missing permissions.");
12522 throw new SecurityException("purchasePremiumCapability requires permission "
12523 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012524 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12525 mApp, "purchasePremiumCapability")) {
12526 log("purchasePremiumCapability "
12527 + TelephonyManager.convertPremiumCapabilityToString(capability)
12528 + " failed due to missing permissions.");
12529 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012530 }
12531
joonhunshin4ac60942023-11-15 15:23:39 +000012532 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12533 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12534
Sarah Chin2ec39f62022-08-31 17:03:26 -070012535 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012536 if (phone == null) {
12537 try {
12538 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12539 callback.accept(result);
12540 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12541 } catch (RemoteException e) {
12542 String logStr = "Purchase premium capability "
12543 + TelephonyManager.convertPremiumCapabilityToString(capability)
12544 + " failed due to RemoteException handling null phone: " + e;
12545 if (DBG) log(logStr);
12546 AnomalyReporter.reportAnomaly(
12547 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12548 }
12549 return;
12550 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012551
12552 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012553 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012554 callingProcess = mApp.getPackageManager().getApplicationInfo(
12555 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012556 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012557 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012558 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012559
12560 boolean isVisible = false;
12561 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12562 if (am != null) {
12563 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12564 if (processes != null) {
12565 for (ActivityManager.RunningAppProcessInfo process : processes) {
12566 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012567 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012568 if (process.processName.equals(callingProcess) && process.importance
12569 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12570 isVisible = true;
12571 break;
12572 }
12573 }
12574 }
12575 }
12576
12577 if (!isVisible) {
12578 try {
12579 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12580 callback.accept(result);
12581 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12582 } catch (RemoteException e) {
12583 String logStr = "Purchase premium capability "
12584 + TelephonyManager.convertPremiumCapabilityToString(capability)
12585 + " failed due to RemoteException handling background application: " + e;
12586 if (DBG) log(logStr);
12587 AnomalyReporter.reportAnomaly(
12588 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12589 }
12590 return;
12591 }
12592
Sarah Chin71b3a852022-09-28 15:54:19 -070012593 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012594 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012595 }
12596
12597 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012598 * Register an IMS connection state callback
12599 */
12600 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012601 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12602 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012603 if (feature == ImsFeature.FEATURE_MMTEL) {
12604 // ImsMmTelManager
12605 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12606 TelephonyPermissions
12607 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12608 mApp, subId, "registerImsStateCallback");
12609 } else if (feature == ImsFeature.FEATURE_RCS) {
12610 // ImsRcsManager or SipDelegateManager
12611 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12612 Binder.getCallingUid(), "registerImsStateCallback",
12613 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12614 Manifest.permission.READ_PRECISE_PHONE_STATE,
12615 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12616 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12617 }
12618
12619 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12620 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12621 "IMS not available on device.");
12622 }
12623
12624 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12625 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12626 }
12627
12628 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12629 if (controller == null) {
12630 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12631 "IMS not available on device.");
12632 }
12633
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012634 if (callingPackage == null) {
12635 callingPackage = getCurrentPackageName();
12636 }
12637
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012638 final long token = Binder.clearCallingIdentity();
12639 try {
12640 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012641 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012642 } catch (ImsException e) {
12643 throw new ServiceSpecificException(e.getCode());
12644 } finally {
12645 Binder.restoreCallingIdentity(token);
12646 }
12647 }
12648
12649 /**
12650 * Unregister an IMS connection state callback
12651 */
12652 @Override
12653 public void unregisterImsStateCallback(IImsStateCallback cb) {
12654 final long token = Binder.clearCallingIdentity();
12655 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12656 if (controller == null) {
12657 return;
12658 }
12659 try {
12660 controller.unregisterImsStateCallback(cb);
12661 } finally {
12662 Binder.restoreCallingIdentity(token);
12663 }
12664 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012665
12666 /**
12667 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12668 *
12669 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012670 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012671 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012672 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012673 * If there is current registered network this value will be same as the registered cell
12674 * identity. If the device goes out of service the previous cell identity is cached and
12675 * will be returned. If the cache age of the Cell identity is more than 24 hours
12676 * it will be cleared and null will be returned.
12677 *
12678 */
12679 @Override
12680 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12681 String callingFeatureId) {
12682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12683 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12684 LocationAccessPolicy.checkLocationPermission(mApp,
12685 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12686 .setCallingPackage(callingPackage)
12687 .setCallingFeatureId(callingFeatureId)
12688 .setCallingPid(Binder.getCallingPid())
12689 .setCallingUid(Binder.getCallingUid())
12690 .setMethod("getLastKnownCellIdentity")
12691 .setLogAsInfo(true)
12692 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12693 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12694 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12695 .build());
12696
12697 boolean hasFinePermission =
12698 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12699 if (!hasFinePermission
12700 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12701 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012702 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012703 }
12704
12705 final long identity = Binder.clearCallingIdentity();
12706 try {
Ling Mac28f0212023-03-24 16:07:15 -070012707 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012708 if (sst == null) return null;
12709 return sst.getLastKnownCellIdentity();
12710 } finally {
12711 Binder.restoreCallingIdentity(identity);
12712 }
12713 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012714
jimsun3b9ccac2021-10-26 15:01:23 +080012715 /**
12716 * Sets the modem service class Name that Telephony will bind to.
12717 *
12718 * @param serviceName The class name of the modem service.
12719 * @return true if the operation is succeed, otherwise false.
12720 */
12721 public boolean setModemService(String serviceName) {
12722 Log.d(LOG_TAG, "setModemService - " + serviceName);
12723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012725 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12726 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012727 return mPhoneConfigurationManager.setModemService(serviceName);
12728 }
12729
12730 /**
12731 * Return the class name of the currently bounded modem service.
12732 *
12733 * @return the class name of the modem service.
12734 */
12735 public String getModemService() {
12736 String result;
12737 Log.d(LOG_TAG, "getModemService");
12738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12739 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012740 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012741 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12742 "getModemService");
12743 result = mPhoneConfigurationManager.getModemService();
12744 Log.d(LOG_TAG, "result = " + result);
12745 return result;
12746 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012747
Hakjun Choi3ee81112023-12-19 15:40:58 +000012748 /**
12749 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12750 * including carrier config, entitlement server, and config update.
12751 *
12752 * @param subId subId The subscription ID of the carrier.
12753 *
12754 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12755 * be returned.
12756 *
12757 * @throws SecurityException if the caller doesn't have the required permission.
12758 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012759 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12760 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012761 final long identity = Binder.clearCallingIdentity();
12762 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012763 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012764 } finally {
12765 Binder.restoreCallingIdentity(identity);
12766 }
12767 }
12768
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012769 @Override
12770 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12771 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12772 mApp.enforceCallingOrSelfPermission(
12773 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12774 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12775
12776 final long identity = Binder.clearCallingIdentity();
12777 try {
12778 Phone phone = getPhone(subId);
12779 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012780 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12781 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012782 phone.setVoiceServiceStateOverride(hasService);
12783 } finally {
12784 Binder.restoreCallingIdentity(identity);
12785 }
12786 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012787
12788 /**
12789 * set removable eSIM as default eUICC.
12790 *
12791 * @hide
12792 */
12793 @Override
12794 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12795 enforceModifyPermission();
12796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12797
12798 final long identity = Binder.clearCallingIdentity();
12799 try {
12800 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12801 } finally {
12802 Binder.restoreCallingIdentity(identity);
12803 }
12804 }
12805
12806 /**
12807 * Returns whether the removable eSIM is default eUICC or not.
12808 *
12809 * @hide
12810 */
12811 @Override
12812 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12813 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12814 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12815
12816 final long identity = Binder.clearCallingIdentity();
12817 try {
12818 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12819 } finally {
12820 Binder.restoreCallingIdentity(identity);
12821 }
12822 }
12823
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012824 /**
12825 * Get the component name of the default app to direct respond-via-message intent for the
12826 * user associated with this subscription, update the cache if there is no respond-via-message
12827 * application currently configured for this user.
12828 * @return component name of the app and class to direct Respond Via Message intent to, or
12829 * {@code null} if the functionality is not supported.
12830 * @hide
12831 */
12832 @Override
12833 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12834 boolean updateIfNeeded) {
12835 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012836
joonhunshin4ac60942023-11-15 15:23:39 +000012837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12838 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12839 "getDefaultRespondViaMessageApplication");
12840
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012841 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12842
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012843 UserHandle userHandle = null;
12844 final long identity = Binder.clearCallingIdentity();
12845 try {
12846 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12847 } finally {
12848 Binder.restoreCallingIdentity(identity);
12849 }
12850 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12851 updateIfNeeded, userHandle);
12852 }
Jack Yuf5badd92022-12-08 00:50:53 -080012853
12854 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012855 * Set whether the device is able to connect with null ciphering or integrity
12856 * algorithms. This is a global setting and will apply to all active subscriptions
12857 * and all new subscriptions after this.
12858 *
12859 * @param enabled when true, null cipher and integrity algorithms are allowed.
12860 * @hide
12861 */
12862 @Override
12863 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12864 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12865 enforceModifyPermission();
12866 checkForNullCipherAndIntegritySupport();
12867
12868 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12869 // for listening to these preference changes and applying them immediately.
12870 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12871 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12872 editor.apply();
12873
12874 for (Phone phone: PhoneFactory.getPhones()) {
12875 phone.handleNullCipherEnabledChange();
12876 }
12877 }
12878
12879
12880 /**
12881 * Get whether the device is able to connect with null ciphering or integrity
12882 * algorithms. Note that this retrieves the phone-global preference and not
12883 * the state of the radio.
12884 *
12885 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12886 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12887 * version for this feature.
12888 * @hide
12889 */
12890 @Override
12891 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12892 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12893 enforceReadPermission();
12894 checkForNullCipherAndIntegritySupport();
12895 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12896 }
12897
12898 private void checkForNullCipherAndIntegritySupport() {
12899 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12900 throw new UnsupportedOperationException(
12901 "Null cipher and integrity operations require HAL 2.1 or above");
12902 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012903 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12904 throw new UnsupportedOperationException(
12905 "Null cipher and integrity operations unsupported by modem");
12906 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012907 }
12908
Gil Cukierman06403e12023-11-29 16:33:03 +000012909 private void checkForIdentifierDisclosureNotificationSupport() {
12910 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12911 throw new UnsupportedOperationException(
12912 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12913 + "above");
12914 }
12915 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12916 throw new UnsupportedOperationException(
12917 "Cellular identifier disclosure transparency operations unsupported by modem");
12918 }
12919 }
12920
Michael Groover826b71d2023-12-21 22:08:06 -060012921 private void checkForNullCipherNotificationSupport() {
12922 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12923 throw new UnsupportedOperationException(
12924 "Null cipher notification operations require HAL 2.2 or above");
12925 }
12926 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12927 throw new UnsupportedOperationException(
12928 "Null cipher notification operations unsupported by modem");
12929 }
12930 }
12931
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012932 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012933 * Get the SIM state for the slot index.
12934 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12935 *
12936 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12937 */
12938 @Override
12939 @SimState
12940 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012941 if (!mApp.getResources().getBoolean(
12942 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12943 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12944 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12945 }
joonhunshin4ac60942023-11-15 15:23:39 +000012946
Jack Yuf5badd92022-12-08 00:50:53 -080012947 IccCardConstants.State simState;
12948 if (slotIndex < 0) {
12949 simState = IccCardConstants.State.UNKNOWN;
12950 } else {
12951 Phone phone = null;
12952 try {
12953 phone = PhoneFactory.getPhone(slotIndex);
12954 } catch (IllegalStateException e) {
12955 // ignore
12956 }
12957 if (phone == null) {
12958 simState = IccCardConstants.State.UNKNOWN;
12959 } else {
12960 IccCard icc = phone.getIccCard();
12961 if (icc == null) {
12962 simState = IccCardConstants.State.UNKNOWN;
12963 } else {
12964 simState = icc.getState();
12965 }
12966 }
12967 }
12968 return simState.ordinal();
12969 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012970
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012971 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12972 boolean enableLogcat,
12973 long logcatStartTimestampMillis, boolean enableTelecomDump,
12974 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012975 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012976 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12977 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12978 ecdDataBuilder
12979 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12980 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012981 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012982 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012983 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012984 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12985 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012986 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12987 Executors.newCachedThreadPool(), db,
12988 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012989 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012990 }
12991
12992 /**
12993 * Request telephony to persist state for debugging emergency call failures.
12994 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012995 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012996 * @param enableLogcat whether to collect logcat output
12997 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12998 * @param enableTelecomDump whether to collect telecom dumpsys
12999 * @param enableTelephonyDump whether to collect telephony dumpsys
13000 */
13001 @Override
13002 @RequiresPermission(android.Manifest.permission.DUMP)
13003 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13004 long logcatStartTimestampMillis, boolean enableTelecomDump,
13005 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013006 // Verify that the caller has READ_DROPBOX_DATA permission.
13007 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13008 && Flags.enableReadDropboxPermission()) {
13009 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13010 "persistEmergencyCallDiagnosticData");
13011 } else {
13012 // Otherwise, enforce legacy permission.
13013 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13014 "persistEmergencyCallDiagnosticData");
13015 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013016 final long identity = Binder.clearCallingIdentity();
13017 try {
13018 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13019 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13020
13021 } finally {
13022 Binder.restoreCallingIdentity(identity);
13023 }
13024 }
13025
Hui Wang9b5793a2022-12-05 14:38:06 -060013026 /**
13027 * Get current cell broadcast ranges.
13028 */
13029 @Override
13030 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13031 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13032 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13033 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013034
13035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13036 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13037
Hui Wang9b5793a2022-12-05 14:38:06 -060013038 final long identity = Binder.clearCallingIdentity();
13039 try {
13040 return getPhone(subId).getCellBroadcastIdRanges();
13041 } finally {
13042 Binder.restoreCallingIdentity(identity);
13043 }
13044 }
13045
13046 /**
13047 * Set reception of cell broadcast messages with the list of the given ranges
13048 *
13049 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13050 */
13051 @Override
13052 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13053 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13054 @Nullable IIntegerConsumer callback) {
13055 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13056 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013057
13058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13059 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13060
Hui Wang9b5793a2022-12-05 14:38:06 -060013061 final long identity = Binder.clearCallingIdentity();
13062 try {
13063 Phone phone = getPhoneFromSubId(subId);
13064 if (DBG) {
13065 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13066 }
13067 phone.setCellBroadcastIdRanges(ranges, result -> {
13068 if (callback != null) {
13069 try {
13070 callback.accept(result);
13071 } catch (RemoteException e) {
13072 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13073 }
13074 }
13075 });
13076 } finally {
13077 Binder.restoreCallingIdentity(identity);
13078 }
13079 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013080
13081 /**
13082 * Returns whether the device supports the domain selection service.
13083 *
13084 * @return {@code true} if the device supports the domain selection service.
13085 */
13086 @Override
13087 public boolean isDomainSelectionSupported() {
13088 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13089 "isDomainSelectionSupported");
13090
13091 final long identity = Binder.clearCallingIdentity();
13092 try {
13093 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13094 } finally {
13095 Binder.restoreCallingIdentity(identity);
13096 }
13097 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013098
13099 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013100 * Returns whether the AOSP domain selection service is supported.
13101 *
13102 * @return {@code true} if the AOSP domain selection service is supported,
13103 * {@code false} otherwise.
13104 */
13105 @Override
13106 public boolean isAospDomainSelectionService() {
13107 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13108 "isAospDomainSelectionService");
13109
13110 final long identity = Binder.clearCallingIdentity();
13111 try {
13112 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13113 String dssComponentName = mApp.getResources().getString(
13114 R.string.config_domain_selection_service_component_name);
13115 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13116 TelephonyDomainSelectionService.class.getName());
13117 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13118 + ", aosp=" + componentName.flattenToString());
13119 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13120 }
13121 } finally {
13122 Binder.restoreCallingIdentity(identity);
13123 }
13124 return false;
13125 }
13126
13127 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013128 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13129 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13130 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013131 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013132 * @param enableSatellite {@code true} to enable the satellite modem and
13133 * {@code false} to disable.
13134 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013135 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013136 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013137 *
13138 * @throws SecurityException if the caller doesn't have the required permission.
13139 */
13140 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013141 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013142 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013143 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013144 if (enableSatellite) {
13145 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13146 @Override
13147 protected void onReceiveResult(int resultCode, Bundle resultData) {
13148 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13149 + ", resultData=" + resultData);
13150 boolean isAllowed = false;
13151 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13152 callback::accept);
13153 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13154 if (resultData != null
13155 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13156 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13157 } else {
13158 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13159 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013160 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013161 result.accept(resultCode);
13162 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013163 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013164 if (isAllowed) {
13165 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013166 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013167 } else {
13168 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13169 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013170 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013171 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013172 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
joonhunshin83da7cd2024-08-22 08:53:35 +000013173 resultReceiver);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013174 } else {
13175 // No need to check if satellite is allowed at current location when disabling satellite
13176 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013177 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013178 }
Sarah Chin503828c2023-02-01 23:54:20 -080013179 }
13180
13181 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013182 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013183 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013184 * @param result The result receiver that returns whether the satellite modem is enabled
13185 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013186 *
13187 * @throws SecurityException if the caller doesn't have the required permission.
13188 */
13189 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013190 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013191 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013192 mSatelliteController.requestIsSatelliteEnabled(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013193 }
13194
13195 /**
Sarah Chin43457982023-02-15 17:50:38 -080013196 * Request to get whether the satellite service demo mode is enabled.
13197 *
Sarah Chin43457982023-02-15 17:50:38 -080013198 * @param result The result receiver that returns whether the satellite demo mode is enabled
13199 * if the request is successful or an error code if the request failed.
13200 *
13201 * @throws SecurityException if the caller doesn't have the required permission.
13202 */
13203 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013204 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013205 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013206 mSatelliteController.requestIsDemoModeEnabled(result);
Sarah Chin43457982023-02-15 17:50:38 -080013207 }
13208
13209 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013210 * Request to get whether the satellite service is enabled with emergency mode.
13211 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013212 * @param result The result receiver that returns whether the satellite emergency mode is
13213 * enabled if the request is successful or an error code if the request failed.
13214 *
13215 * @throws SecurityException if the caller doesn't have the required permission.
13216 */
13217 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013218 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013219 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013220 mSatelliteController.requestIsEmergencyModeEnabled(result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013221 }
13222
13223 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013224 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013225 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013226 * @param result The result receiver that returns whether the satellite service is supported on
13227 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013228 */
13229 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013230 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
13231 mSatelliteController.requestIsSatelliteSupported(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013232 }
13233
13234 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013235 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013236 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013237 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13238 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013239 *
13240 * @throws SecurityException if the caller doesn't have required permission.
13241 */
13242 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013243 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013244 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
joonhunshin83da7cd2024-08-22 08:53:35 +000013245 mSatelliteController.requestSatelliteCapabilities(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013246 }
13247
13248 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013249 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013250 * This can be called by the pointing UI when the user starts pointing to the satellite.
13251 * Modem should continue to report the pointing input as the device or satellite moves.
13252 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013253 * @param resultCallback The callback to get the result of the request.
13254 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013255 *
13256 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013257 */
13258 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013259 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013260 @NonNull IIntegerConsumer resultCallback,
13261 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13262 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013263 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013264 }
13265
13266 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013267 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013268 * This can be called by the pointing UI when the user stops pointing to the satellite.
13269 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013270 * @param resultCallback The callback to get the result of the request.
13271 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013272 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013273 *
13274 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013275 */
13276 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013277 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013278 @NonNull IIntegerConsumer resultCallback,
13279 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13280 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013281 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013282 }
13283
13284 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013285 * Register the subscription with a satellite provider.
13286 * This is needed to register the subscription if the provider allows dynamic registration.
13287 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013288 * @param token The token to be used as a unique identifier for provisioning with satellite
13289 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013290 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013291 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013292 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013293 * @return The signal transport used by the caller to cancel the provision request,
13294 * or {@code null} if the request failed.
13295 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013296 * @throws SecurityException if the caller doesn't have the required permission.
13297 */
13298 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013299 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013300 @NonNull String token, @NonNull byte[] provisionData,
13301 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013302 enforceSatelliteCommunicationPermission("provisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013303 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013304 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013305 }
13306
13307 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013308 * Unregister the device/subscription with the satellite provider.
13309 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013310 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013311 * should report as deprovisioned.
13312 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013313 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013314 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013315 *
13316 * @throws SecurityException if the caller doesn't have the required permission.
13317 */
13318 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013319 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013320 @NonNull String token, @NonNull IIntegerConsumer callback) {
13321 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013322 mSatelliteController.deprovisionSatelliteService(token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013323 }
13324
13325 /**
Sarah Chin43457982023-02-15 17:50:38 -080013326 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013327 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013328 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013329 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013330 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013331 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013332 * @throws SecurityException if the caller doesn't have the required permission.
13333 */
13334 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013335 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013336 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013337 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013338 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013339 }
13340
13341 /**
Sarah Chin43457982023-02-15 17:50:38 -080013342 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013343 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013344 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013345 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013346 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013347 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013348 * @throws SecurityException if the caller doesn't have the required permission.
13349 */
13350 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013351 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013352 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013353 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013354 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013355 }
13356
13357 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013358 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013359 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013360 * @param result The result receiver that returns whether the device is provisioned with a
13361 * satellite provider if the request is successful or an error code if the
13362 * request failed.
13363 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013364 * @throws SecurityException if the caller doesn't have the required permission.
13365 */
13366 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013367 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013368 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
joonhunshin83da7cd2024-08-22 08:53:35 +000013369 mSatelliteController.requestIsSatelliteProvisioned(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013370 }
13371
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013372 /**
Sarah Chin43457982023-02-15 17:50:38 -080013373 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013374 *
Sarah Chin43457982023-02-15 17:50:38 -080013375 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013376 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013377 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013378 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013379 * @throws SecurityException if the caller doesn't have the required permission.
13380 */
13381 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013382 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013383 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013384 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013385 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013386 }
13387
13388 /**
Sarah Chin43457982023-02-15 17:50:38 -080013389 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013390 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013391 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013392 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013393 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013394 *
13395 * @throws SecurityException if the caller doesn't have the required permission.
13396 */
13397 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013398 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013399 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013400 mSatelliteController.unregisterForModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013401 }
13402
13403 /**
13404 * Register to receive incoming datagrams over satellite.
13405 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013406 * @param callback The callback to handle incoming datagrams over satellite.
13407 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013408 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013409 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013410 * @throws SecurityException if the caller doesn't have the required permission.
13411 */
13412 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013413 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013414 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013415 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013416 return mSatelliteController.registerForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013417 }
13418
13419 /**
13420 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013421 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013422 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013423 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013424 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013425 *
13426 * @throws SecurityException if the caller doesn't have the required permission.
13427 */
13428 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013429 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013430 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013431 mSatelliteController.unregisterForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013432 }
13433
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013434 /**
13435 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013436 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013437 * This method requests modem to check if there are any pending datagrams to be received over
13438 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013439 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013440 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013441 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013442 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013443 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013444 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013445 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013446 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
joonhunshin83da7cd2024-08-22 08:53:35 +000013447 mSatelliteController.pollPendingDatagrams(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013448 }
13449
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013450 /**
13451 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013452 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013453 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13454 * input to this method. Datagram received here will be passed down to modem without any
13455 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013456 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013457 * @param datagramType datagram type indicating whether the datagram is of type
13458 * SOS_SMS or LOCATION_SHARING.
13459 * @param datagram encoded gateway datagram which is encrypted by the caller.
13460 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013461 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13462 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013463 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013464 *
13465 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013466 */
13467 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013468 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013469 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13470 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013471 enforceSatelliteCommunicationPermission("sendDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013472 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013473 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013474 }
13475
Sarah Chindf715ec2023-02-13 13:46:24 -080013476 /**
13477 * Request to get whether satellite communication is allowed for the current location.
13478 *
13479 * @param subId The subId of the subscription to check whether satellite communication is
13480 * allowed for the current location for.
13481 * @param result The result receiver that returns whether satellite communication is allowed
13482 * for the current location if the request is successful or an error code
13483 * if the request failed.
13484 *
13485 * @throws SecurityException if the caller doesn't have the required permission.
13486 */
13487 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013488 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013489 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013490 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
joonhunshin83da7cd2024-08-22 08:53:35 +000013491 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013492 }
13493
13494 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013495 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013496 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013497 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013498 * be visible if the request is successful or an error code if the request failed.
13499 *
13500 * @throws SecurityException if the caller doesn't have the required permission.
13501 */
13502 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013503 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013504 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
joonhunshin83da7cd2024-08-22 08:53:35 +000013505 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013506 }
13507
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013508 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013509 * Inform that Device is aligned to satellite for demo mode.
13510 *
Hakjun Choiae365972023-04-25 11:00:31 +000013511 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13512 * {@code false} Device fails to align with the satellite for demo mode.
13513 *
13514 * @throws SecurityException if the caller doesn't have required permission.
13515 */
13516 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13517
joonhunshin83da7cd2024-08-22 08:53:35 +000013518 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013519 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
joonhunshin83da7cd2024-08-22 08:53:35 +000013520 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013521 }
13522
13523 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013524 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13525 * by modem.
13526 *
13527 * @param subId The subId of the subscription to request for.
13528 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013529 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013530 * operation.
13531 *
13532 * @throws SecurityException if the caller doesn't have required permission.
13533 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013534 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013535 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13536 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013537 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013538 final long identity = Binder.clearCallingIdentity();
13539 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013540 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013541 } finally {
13542 Binder.restoreCallingIdentity(identity);
13543 }
13544 }
13545
13546 /**
13547 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13548 * by modem.
13549 *
13550 * @param subId The subId of the subscription to request for.
13551 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013552 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013553 * operation.
13554 *
13555 * @throws SecurityException if the caller doesn't have required permission.
13556 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013557 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013558 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13559 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013560 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013561 final long identity = Binder.clearCallingIdentity();
13562 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013563 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013564 } finally {
13565 Binder.restoreCallingIdentity(identity);
13566 }
13567 }
13568
13569 /**
13570 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013571 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013572 *
13573 * @param subId The subId of the subscription to request for.
13574 *
13575 * @return Integer array of reasons for disallowing satellite communication.
13576 *
13577 * @throws SecurityException if the caller doesn't have the required permission.
13578 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013579 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013580 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013581 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013582 final long identity = Binder.clearCallingIdentity();
13583 try {
13584 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013585 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013586 return reasonSet.stream().mapToInt(i->i).toArray();
13587 } finally {
13588 Binder.restoreCallingIdentity(identity);
13589 }
13590 }
13591
13592 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013593 * Request to get the signal strength of the satellite connection.
13594 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013595 * @param result Result receiver to get the error code of the request and the current signal
13596 * strength of the satellite connection.
13597 *
13598 * @throws SecurityException if the caller doesn't have required permission.
13599 */
13600 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013601 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013602 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13603 final long identity = Binder.clearCallingIdentity();
13604 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013605 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013606 } finally {
13607 Binder.restoreCallingIdentity(identity);
13608 }
13609 }
13610
13611 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013612 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13613 * is not successful, a {@link ServiceSpecificException} that contains
13614 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013615 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013616 * @param callback The callback to handle the NTN signal strength changed event. If the
13617 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13618 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13619 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13620 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013621 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013622 * @throws SecurityException If the caller doesn't have the required permission.
13623 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013624 */
13625 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013626 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013627 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013628 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13629 final long identity = Binder.clearCallingIdentity();
13630 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013631 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013632 } finally {
13633 Binder.restoreCallingIdentity(identity);
13634 }
13635 }
13636
13637 /**
13638 * Unregisters for NTN signal strength changed from satellite modem.
13639 * If callback was not registered before, the request will be ignored.
13640 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013641 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013642 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013643 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013644 *
13645 * @throws SecurityException if the caller doesn't have the required permission.
13646 */
13647 @Override
13648 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013649 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013650 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13651 final long identity = Binder.clearCallingIdentity();
13652 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013653 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013654 } finally {
13655 Binder.restoreCallingIdentity(identity);
13656 }
13657 }
13658
13659 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013660 * Registers for satellite capabilities change event from the satellite service.
13661 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013662 * @param callback The callback to handle the satellite capabilities changed event.
13663 *
13664 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13665 *
13666 * @throws SecurityException if the caller doesn't have required permission.
13667 */
13668 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013669 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013670 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013671 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013672 final long identity = Binder.clearCallingIdentity();
13673 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013674 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013675 } finally {
13676 Binder.restoreCallingIdentity(identity);
13677 }
13678 }
13679
13680 /**
13681 * Unregisters for satellite capabilities change event from the satellite service.
13682 * If callback was not registered before, the request will be ignored.
13683 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013684 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013685 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013686 *
13687 * @throws SecurityException if the caller doesn't have required permission.
13688 */
13689 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013690 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013691 @NonNull ISatelliteCapabilitiesCallback callback) {
13692 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013693 final long identity = Binder.clearCallingIdentity();
13694 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013695 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013696 } finally {
13697 Binder.restoreCallingIdentity(identity);
13698 }
13699 }
13700
13701 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013702 * Registers for the satellite supported state changed.
13703 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013704 * @param callback The callback to handle the satellite supported state changed event.
13705 *
13706 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13707 *
13708 * @throws SecurityException if the caller doesn't have the required permission.
13709 */
13710 @Override
13711 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013712 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013713 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013714 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013715 }
13716
13717 /**
13718 * Unregisters for the satellite supported state changed.
13719 * If callback was not registered before, the request will be ignored.
13720 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013721 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013722 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000013723 *
13724 * @throws SecurityException if the caller doesn't have the required permission.
13725 */
13726 @Override
13727 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013728 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013729 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013730 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013731 }
13732
13733 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013734 * This API can be used by only CTS to update satellite vendor service package name.
13735 *
13736 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013737 * @param provisioned Whether satellite should be provisioned or not.
13738 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013739 * @return {@code true} if the satellite vendor service is set successfully,
13740 * {@code false} otherwise.
13741 */
Hakjun Choic3393242024-06-26 18:02:08 +000013742 public boolean setSatelliteServicePackageName(String servicePackageName,
13743 String provisioned) {
13744 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13745 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013746 TelephonyPermissions.enforceShellOnly(
13747 Binder.getCallingUid(), "setSatelliteServicePackageName");
13748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13749 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13750 "setSatelliteServicePackageName");
Hakjun Choic3393242024-06-26 18:02:08 +000013751 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13752 provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013753 }
13754
13755 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013756 * This API can be used by only CTS to update satellite gateway service package name.
13757 *
13758 * @param servicePackageName The package name of the satellite gateway service.
13759 * @return {@code true} if the satellite gateway service is set successfully,
13760 * {@code false} otherwise.
13761 */
13762 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13763 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13764 TelephonyPermissions.enforceShellOnly(
13765 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13767 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13768 "setSatelliteGatewayServicePackageName");
13769 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13770 }
13771
13772 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013773 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13774 *
13775 * @param packageName The package name of the satellite pointing UI app.
13776 * @param className The class name of the satellite pointing UI app.
13777 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13778 * {@code false} otherwise.
13779 */
13780 public boolean setSatellitePointingUiClassName(
13781 @Nullable String packageName, @Nullable String className) {
13782 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13783 + ", className=" + className);
13784 TelephonyPermissions.enforceShellOnly(
13785 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13787 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13788 "setSatelliteGatewayServicePackageName");
13789 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13790 }
13791
13792 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013793 * This API can be used by only CTS to update the timeout duration in milliseconds that
13794 * satellite should stay at listening mode to wait for the next incoming page before disabling
13795 * listening mode.
13796 *
13797 * @param timeoutMillis The timeout duration in millisecond.
13798 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13799 */
13800 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13801 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13802 TelephonyPermissions.enforceShellOnly(
13803 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13805 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13806 "setSatelliteListeningTimeoutDuration");
13807 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13808 }
13809
13810 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013811 * This API can be used by only CTS to override the timeout durations used by the
13812 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013813 *
13814 * @param timeoutMillis The timeout duration in millisecond.
13815 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13816 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013817 public boolean setDatagramControllerTimeoutDuration(
13818 boolean reset, int timeoutType, long timeoutMillis) {
13819 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13820 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013821 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013822 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013825 "setDatagramControllerTimeoutDuration");
13826 return mSatelliteController.setDatagramControllerTimeoutDuration(
13827 reset, timeoutType, timeoutMillis);
13828 }
13829
13830 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013831 * This API can be used by only CTS to override the boolean configs used by the
13832 * DatagramController module.
13833 *
13834 * @param enable Whether to enable or disable boolean config.
13835 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13836 */
13837 public boolean setDatagramControllerBooleanConfig(
13838 boolean reset, int booleanType, boolean enable) {
13839 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13840 + ", reset=" + reset + ", enable=" + enable);
13841 TelephonyPermissions.enforceShellOnly(
13842 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13844 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13845 "ssetDatagramControllerBooleanConfig");
13846 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13847 }
13848
13849
13850 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013851 * This API can be used by only CTS to override the timeout durations used by the
13852 * SatelliteController module.
13853 *
13854 * @param timeoutMillis The timeout duration in millisecond.
13855 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13856 */
13857 public boolean setSatelliteControllerTimeoutDuration(
13858 boolean reset, int timeoutType, long timeoutMillis) {
13859 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13860 + reset + ", timeoutMillis=" + timeoutMillis);
13861 TelephonyPermissions.enforceShellOnly(
13862 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13864 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13865 "setSatelliteControllerTimeoutDuration");
13866 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13867 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013868 }
13869
13870 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013871 * This API can be used in only testing to override connectivity status in monitoring emergency
13872 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13873 *
13874 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13875 * of the following values to enable the override:
13876 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13877 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13878 * To disable the override, use -1 for handoverType.
13879 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13880 * delaySeconds after the emergency call starts.
13881 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13882 */
13883 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13884 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13885 TelephonyPermissions.enforceShellOnly(
13886 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13888 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13889 "setEmergencyCallToSatelliteHandoverType");
13890 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13891 handoverType, delaySeconds);
13892 }
13893
13894 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013895 * This API can be used in only testing to override oem-enabled satellite provision status.
13896 *
13897 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13898 * otherwise.
13899 * @param isProvisioned The overriding provision status.
13900 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13901 */
13902 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13903 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13904 + ", isProvisioned=" + isProvisioned);
13905 TelephonyPermissions.enforceShellOnly(
13906 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13908 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13909 "setOemEnabledSatelliteProvisionStatus");
13910 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13911 }
13912
13913 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013914 * This API should be used by only CTS tests to forcefully set telephony country codes.
13915 *
13916 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13917 */
13918 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13919 Map cachedNetworkCountryCodes, String locationCountryCode,
13920 long locationCountryCodeTimestampNanos) {
13921 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13922 + String.join(", ", currentNetworkCountryCodes)
13923 + ", locationCountryCode=" + locationCountryCode
13924 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13925 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13926 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13927 TelephonyPermissions.enforceShellOnly(
13928 Binder.getCallingUid(), "setCachedLocationCountryCode");
13929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13930 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13931 "setCachedLocationCountryCode");
youngtaecha31b141d2024-07-15 12:01:39 +000013932 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), mFeatureFlags)
13933 .setCountryCodes(reset, currentNetworkCountryCodes, cachedNetworkCountryCodes,
13934 locationCountryCode, locationCountryCodeTimestampNanos);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013935 }
13936
13937 /**
13938 * This API should be used by only CTS tests to override the overlay configs of satellite
13939 * access controller.
13940 *
13941 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13942 * otherwise.
13943 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13944 */
13945 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13946 String s2CellFile, long locationFreshDurationNanos,
13947 List<String> satelliteCountryCodes) {
13948 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13949 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13950 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13951 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13952 ? String.join(", ", satelliteCountryCodes) : null));
13953 TelephonyPermissions.enforceShellOnly(
13954 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13956 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13957 "setSatelliteAccessControlOverlayConfigs");
13958 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13959 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13960 }
13961
13962 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013963 * This API can be used by only CTS to override the cached value for the device overlay config
13964 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13965 * outgoing satellite datagrams should be sent to modem in demo mode.
13966 *
13967 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13968 * satellite modem or not.
13969 *
13970 * @return {@code true} if the operation is successful, {@code false} otherwise.
13971 */
13972 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13973 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13974 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13975 + "disabled");
13976 return false;
13977 }
13978 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13979 TelephonyPermissions.enforceShellOnly(
13980 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13982 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13983 "setShouldSendDatagramToModemInDemoMode");
13984 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13985 shouldSendToModemInDemoMode);
13986 }
13987
13988 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013989 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13990 *
13991 * @param state a state indicates whether satellite access allowed state should be cached and
13992 * the allowed state.
13993 * @return {@code true} if the setting is successful, {@code false} otherwise.
13994 */
13995 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13996 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13997 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13998 + "oemEnabledSatelliteFlag is disabled");
13999 return false;
14000 }
14001
14002 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14003 + "state=" + state);
14004 TelephonyPermissions.enforceShellOnly(
14005 Binder.getCallingUid(),
14006 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14008 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14009 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14010 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14011 state);
14012 }
14013
14014 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014015 * Sets the service defined in ComponentName to be bound.
14016 *
14017 * This should only be used for testing.
14018 * @return {@code true} if the DomainSelectionService to bind to was set,
14019 * {@code false} otherwise.
14020 */
14021 @Override
14022 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14023 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14024
14025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14026 "setDomainSelectionServiceOverride");
14027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14028 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14029
14030 final long identity = Binder.clearCallingIdentity();
14031 try {
14032 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14033 return DomainSelectionResolver.getInstance()
14034 .setDomainSelectionServiceOverride(componentName);
14035 }
14036 } finally {
14037 Binder.restoreCallingIdentity(identity);
14038 }
14039 return false;
14040 }
14041
14042 /**
14043 * Clears the DomainSelectionService override.
14044 *
14045 * This should only be used for testing.
14046 * @return {@code true} if the DomainSelectionService override was cleared,
14047 * {@code false} otherwise.
14048 */
14049 @Override
14050 public boolean clearDomainSelectionServiceOverride() {
14051 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14052
14053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14054 "clearDomainSelectionServiceOverride");
14055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14056 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14057
14058 final long identity = Binder.clearCallingIdentity();
14059 try {
14060 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14061 return DomainSelectionResolver.getInstance()
14062 .clearDomainSelectionServiceOverride();
14063 }
14064 } finally {
14065 Binder.restoreCallingIdentity(identity);
14066 }
14067 return false;
14068 }
14069
14070 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014071 * Enable or disable notifications sent for cellular identifier disclosure events.
14072 *
14073 * Disclosure events are defined as instances where a device has sent a cellular identifier
14074 * on the Non-access stratum (NAS) before a security context is established. As a result the
14075 * identifier is sent in the clear, which has privacy implications for the user.
14076 *
14077 * @param enable if notifications about disclosure events should be enabled
14078 * @throws SecurityException if the caller does not have the required privileges
14079 * @throws UnsupportedOperationException if the modem does not support this feature.
14080 */
14081 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014082 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014083 enforceModifyPermission();
14084 checkForIdentifierDisclosureNotificationSupport();
14085
14086 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14087 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14088 editor.apply();
14089
14090 // Each phone instance is responsible for updating its respective modem immediately
14091 // after we've made a preference change.
14092 for (Phone phone : PhoneFactory.getPhones()) {
14093 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14094 }
14095 }
14096
14097 /**
14098 * Get whether or not cellular identifier disclosure notifications are enabled.
14099 *
14100 * @throws SecurityException if the caller does not have the required privileges
14101 * @throws UnsupportedOperationException if the modem does not support this feature.
14102 */
14103 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014104 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014105 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14106 checkForIdentifierDisclosureNotificationSupport();
14107 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14108 }
14109
14110 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014111 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14112 * are in use by the cellular modem.
14113 *
14114 * @throws IllegalStateException if the Telephony process is not currently available
14115 * @throws SecurityException if the caller does not have the required privileges
14116 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14117 * and integrity algorithms in use
14118 * @hide
14119 */
14120 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014121 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014122 enforceModifyPermission();
14123 checkForNullCipherNotificationSupport();
14124
14125 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14126 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14127 editor.apply();
14128
14129 // Each phone instance is responsible for updating its respective modem immediately
14130 // after a preference change.
14131 for (Phone phone : PhoneFactory.getPhones()) {
14132 phone.handleNullCipherNotificationPreferenceChanged();
14133 }
14134 }
14135
14136 /**
14137 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14138 * cellular modem.
14139 *
14140 * @throws IllegalStateException if the Telephony process is not currently available
14141 * @throws SecurityException if the caller does not have the required privileges
14142 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14143 * and integrity algorithms in use
14144 * @hide
14145 */
14146 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14147 public boolean isNullCipherNotificationsEnabled() {
14148 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14149 checkForNullCipherNotificationSupport();
14150 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14151 }
14152
14153 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014154 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14155 *
14156 * <p>This method behaves in one of the following ways:
14157 * <ul>
14158 * <li>return true : if the calling package has the appop permission {@link
14159 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14160 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14161 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14162 * Owner device identifier access check, or the calling package has carrier privileges</>
14163 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14164 * </ul>
14165 */
14166 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14167 String callingPackage, @Nullable String callingFeatureId, String message) {
14168 for (Phone phone : PhoneFactory.getPhones()) {
14169 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14170 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14171 return true;
14172 }
14173 }
14174 return false;
14175 }
arunvoddud7401012022-12-15 16:08:12 +000014176
14177 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014178 * @return The subscription manager service instance.
14179 */
14180 public SubscriptionManagerService getSubscriptionManagerService() {
14181 return SubscriptionManagerService.getInstance();
14182 }
14183
14184 /**
arunvoddud7401012022-12-15 16:08:12 +000014185 * Class binds the consumer[callback] and carrierId.
14186 */
14187 private static class CallerCallbackInfo {
14188 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014189 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014190
Steve Statia28b7cb32024-03-11 23:58:50 +000014191 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014192 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014193 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014194 }
14195
14196 public Consumer<Integer> getConsumer() {
14197 return mConsumer;
14198 }
14199
Steve Statia28b7cb32024-03-11 23:58:50 +000014200 public Set<Integer> getCarrierIds() {
14201 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014202 }
14203 }
joonhunshin4ac60942023-11-15 15:23:39 +000014204
14205 /*
14206 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14207 * But the context that is passed in is unused if the phone app is already alive.
14208 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14209 */
14210 @VisibleForTesting
14211 public void setPackageManager(PackageManager packageManager) {
14212 mPackageManager = packageManager;
14213 }
14214
14215 /*
Nate Myren453c3472024-03-13 11:28:11 -070014216 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14217 * But the context that is passed in is unused if the phone app is already alive.
14218 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14219 */
14220 @VisibleForTesting
14221 public void setAppOpsManager(AppOpsManager appOps) {
14222 mAppOps = appOps;
14223 }
14224
14225 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014226 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14227 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14228 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14229 */
14230 @VisibleForTesting
14231 public void setFeatureFlags(FeatureFlags featureFlags) {
14232 mFeatureFlags = featureFlags;
14233 }
14234
14235 /**
14236 * Make sure the device has required telephony feature
14237 *
14238 * @throws UnsupportedOperationException if the device does not have required telephony feature
14239 */
14240 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14241 @NonNull String telephonyFeature, @NonNull String methodName) {
14242 if (callingPackage == null || mPackageManager == null) {
14243 return;
14244 }
14245
14246 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14247 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014248 Binder.getCallingUserHandle())
14249 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14250 // Skip to check associated telephony feature,
14251 // if compatibility change is not enabled for the current process or
14252 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014253 return;
14254 }
14255
14256 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14257 throw new UnsupportedOperationException(
14258 methodName + " is unsupported without " + telephonyFeature);
14259 }
14260 }
youngtaecha5d483d52024-04-29 17:05:45 +000014261
14262 /**
14263 * Registers for the satellite communication allowed state changed.
14264 *
14265 * @param subId The subId of the subscription to register for the satellite communication
14266 * allowed state changed.
14267 * @param callback The callback to handle the satellite communication allowed
14268 * state changed event.
14269 *
14270 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14271 *
14272 * @throws SecurityException if the caller doesn't have the required permission.
14273 */
14274 @Override
14275 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14276 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14277 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014278 final long identity = Binder.clearCallingIdentity();
14279 try {
14280 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14281 subId, callback);
14282 } finally {
14283 Binder.restoreCallingIdentity(identity);
14284 }
youngtaecha5d483d52024-04-29 17:05:45 +000014285 }
14286
14287 /**
14288 * Unregisters for the satellite communication allowed state changed.
14289 * If callback was not registered before, the request will be ignored.
14290 *
14291 * @param subId The subId of the subscription to unregister for the satellite communication
14292 * allowed state changed.
14293 * @param callback The callback that was passed to
14294 * {@link #registerForCommunicationAllowedStateChanged(int,
14295 * ISatelliteCommunicationAllowedStateCallback)}. *
14296 * @throws SecurityException if the caller doesn't have the required permission.
14297 */
14298 @Override
14299 public void unregisterForCommunicationAllowedStateChanged(
14300 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14301 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014302 final long identity = Binder.clearCallingIdentity();
14303 try {
14304 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14305 callback);
14306 } finally {
14307 Binder.restoreCallingIdentity(identity);
14308 }
youngtaecha5d483d52024-04-29 17:05:45 +000014309 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014310
14311 /**
14312 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14313 *
14314 * @param subId The subId of the subscription to the satellite session stats for.
14315 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14316 * if the request is successful or an error code if the request failed.
14317 *
14318 * @throws SecurityException if the caller doesn't have required permission.
14319 */
14320 @Override
14321 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14322 enforceModifyPermission();
14323 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014324 final long identity = Binder.clearCallingIdentity();
14325 try {
14326 mSatelliteController.requestSatelliteSessionStats(subId, result);
14327 } finally {
14328 Binder.restoreCallingIdentity(identity);
14329 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014330 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014331
14332 /**
14333 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14334 *
14335 * @param result The result receiver, which returns the list of prioritized satellite tokens
14336 * to be used for provision if the request is successful or an error code if the request failed.
14337 *
14338 * @throws SecurityException if the caller doesn't have the required permission.
14339 */
14340 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014341 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14342 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014343 final long identity = Binder.clearCallingIdentity();
14344 try {
14345 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14346 } finally {
14347 Binder.restoreCallingIdentity(identity);
14348 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014349 }
14350
14351 /**
14352 * Deliver the list of provisioned satellite subscriber ids.
14353 *
14354 * @param list List of provisioned satellite subscriber ids.
14355 * @param result The result receiver that returns whether deliver success or fail.
14356 *
14357 * @throws SecurityException if the caller doesn't have the required permission.
14358 */
14359 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014360 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014361 @NonNull ResultReceiver result) {
14362 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014363 final long identity = Binder.clearCallingIdentity();
14364 try {
14365 mSatelliteController.provisionSatellite(list, result);
14366 } finally {
14367 Binder.restoreCallingIdentity(identity);
14368 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014369 }
Hyosund6aaf062024-08-23 23:02:10 +000014370
14371 /**
14372 * This API can be used by only CTS to override the cached value for the device overlay config
14373 * value :
14374 * config_satellite_gateway_service_package and
14375 * config_satellite_carrier_roaming_esos_provisioned_class.
14376 * These values are set before sending an intent to broadcast there are any change to list of
14377 * subscriber informations.
14378 *
14379 * @param name the name is one of the following that constitute an intent.
14380 * Component package name, or component class name.
14381 * @return {@code true} if the setting is successful, {@code false} otherwise.
14382 */
14383 @Override
14384 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14385 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14386 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14387 + " carrierRoamingNbIotNtn is disabled");
14388 return false;
14389 }
14390 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14391 TelephonyPermissions.enforceShellOnly(
14392 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14394 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14395 "setSatelliteSubscriberIdListChangedIntentComponent");
14396 final long identity = Binder.clearCallingIdentity();
14397 try {
14398 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14399 } finally {
14400 Binder.restoreCallingIdentity(identity);
14401 }
14402 }
Jack Yufa8ed012023-02-11 15:42:28 -080014403}