blob: 65dcb94a4ccb67cb19974f44e64345986ca724d3 [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);
2616 mApp.startActivity(intent);
2617 }
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
2631 // need to do a permission check since we're calling startActivity()
2632 // 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);
2667 mApp.startActivity(intent);
2668 } 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();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004357 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4358 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004359 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004360
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004361 /**
fionaxu0152e512016-11-14 13:36:14 -08004362 * Sets the voice activation state of a given subId.
4363 */
4364 @Override
4365 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4367 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
joonhunshin4ac60942023-11-15 15:23:39 +00004369 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4370 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 final Phone phone = getPhone(subId);
4375 if (phone != null) {
4376 phone.setVoiceActivationState(activationState);
4377 } else {
4378 loge("setVoiceActivationState fails with invalid subId: " + subId);
4379 }
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004382 }
4383 }
4384
4385 /**
4386 * Sets the data activation state of a given subId.
4387 */
4388 @Override
4389 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4391 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392
joonhunshin4ac60942023-11-15 15:23:39 +00004393 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4394 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 final Phone phone = getPhone(subId);
4399 if (phone != null) {
4400 phone.setDataActivationState(activationState);
4401 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004402 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 }
4404 } finally {
4405 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004406 }
4407 }
4408
4409 /**
4410 * Returns the voice activation state of a given subId.
4411 */
4412 @Override
4413 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415
joonhunshin4ac60942023-11-15 15:23:39 +00004416 enforceTelephonyFeatureWithException(callingPackage,
4417 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4418
fionaxu0152e512016-11-14 13:36:14 -08004419 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 if (phone != null) {
4423 return phone.getVoiceActivationState();
4424 } else {
4425 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4426 }
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004429 }
4430 }
4431
4432 /**
4433 * Returns the data activation state of a given subId.
4434 */
4435 @Override
4436 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438
joonhunshin4ac60942023-11-15 15:23:39 +00004439 enforceTelephonyFeatureWithException(callingPackage,
4440 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4441
fionaxu0152e512016-11-14 13:36:14 -08004442 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 if (phone != null) {
4446 return phone.getDataActivationState();
4447 } else {
4448 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4449 }
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004452 }
4453 }
4454
4455 /**
Wink Saville36469e72014-06-11 15:17:00 -07004456 * Returns the unread count of voicemails for a subId
4457 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004459 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4460 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004462 mApp, subId, callingPackage, callingFeatureId,
4463 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004464 return 0;
4465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 final Phone phone = getPhone(subId);
4469 if (phone != null) {
4470 return phone.getVoiceMessageCount();
4471 } else {
4472 return 0;
4473 }
4474 } finally {
4475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004477 }
4478
4479 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004480 * returns true, if the device is in a state where both voice and data
4481 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004482 */
4483 @Override
4484 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004485 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4486 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 final long identity = Binder.clearCallingIdentity();
4489 try {
Ling Mac28f0212023-03-24 16:07:15 -07004490 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004494 }
4495
4496 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004497 * Send the dialer code if called from the current default dialer or the caller has
4498 * carrier privilege.
4499 * @param inputCode The dialer code to send
4500 */
4501 @Override
4502 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004503 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004504 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004505 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4506 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004507 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004508 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004509 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
joonhunshin4ac60942023-11-15 15:23:39 +00004512 enforceTelephonyFeatureWithException(callingPackage,
4513 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004517 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
fionaxu235cc5e2017-03-06 22:25:57 -08004521 }
4522
Pengquan Menga1bb6272018-09-06 09:59:22 -07004523 @Override
4524 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004525 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004526 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4527 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004528
4529 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4530 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4531
shilufc958392020-01-20 11:36:01 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
4534 if (!isActiveSubscription(subId)) {
4535 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4536 }
4537 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4538 } finally {
4539 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004541 }
4542
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004544 public boolean isInEmergencySmsMode() {
4545 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004546
4547 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4548 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4549
Brad Ebingerb2b65522019-03-15 13:48:47 -07004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 for (Phone phone : PhoneFactory.getPhones()) {
4553 if (phone.isInEmergencySmsMode()) {
4554 return true;
4555 }
4556 }
4557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 return false;
4561 }
4562
shilu366312e2019-12-17 09:28:10 -08004563 /**
4564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4565 * @param subId The subscription to use to check the configuration.
4566 * @param c The callback that will be used to send the result.
4567 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004568 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004569 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4570 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004571 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004572 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004573
4574 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4576 "IMS not available on device.");
4577 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004578 final long token = Binder.clearCallingIdentity();
4579 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004580 int slotId = getSlotIndexOrException(subId);
4581 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004582
4583 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4584 if (controller != null) {
4585 ImsManager imsManager = controller.getImsManager(subId);
4586 if (imsManager != null) {
4587 imsManager.addRegistrationCallbackForSubscription(c, subId);
4588 } else {
4589 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4590 }
4591 } else {
4592 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4593 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004594 } catch (ImsException e) {
4595 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 } finally {
4597 Binder.restoreCallingIdentity(token);
4598 }
4599 }
4600
shilu366312e2019-12-17 09:28:10 -08004601 /**
4602 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4603 * @param subId The subscription to use to check the configuration.
4604 * @param c The callback that will be used to send the result.
4605 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004607 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004609 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4611 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4612 }
Meng Wangafbc5852019-09-19 17:37:13 -07004613 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004614
Meng Wangafbc5852019-09-19 17:37:13 -07004615 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004616 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4617 if (controller != null) {
4618 ImsManager imsManager = controller.getImsManager(subId);
4619 if (imsManager != null) {
4620 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4621 } else {
4622 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4623 + "is inactive, ignoring unregister.");
4624 // If the ImsManager is not valid, just return, since the callback
4625 // will already have been removed internally.
4626 }
4627 }
Meng Wangafbc5852019-09-19 17:37:13 -07004628 } finally {
4629 Binder.restoreCallingIdentity(token);
4630 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 }
4632
Brad Ebingera34a6c22019-10-22 17:36:18 -07004633 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004634 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4635 * @param subId The subscription to use to check the configuration.
4636 * @param c The callback that will be used to send the result.
4637 */
4638 @Override
4639 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4640 throws RemoteException {
4641 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4642 mApp, subId, "registerImsEmergencyRegistrationCallback");
4643
4644 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4646 "IMS not available on device.");
4647 }
4648 final long token = Binder.clearCallingIdentity();
4649 try {
4650 int slotId = getSlotIndexOrException(subId);
4651 verifyImsMmTelConfiguredOrThrow(slotId);
4652
4653 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4654 if (controller != null) {
4655 ImsManager imsManager = controller.getImsManager(subId);
4656 if (imsManager != null) {
4657 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4658 } else {
4659 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4660 }
4661 } else {
4662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4663 }
4664 } catch (ImsException e) {
4665 throw new ServiceSpecificException(e.getCode());
4666 } finally {
4667 Binder.restoreCallingIdentity(token);
4668 }
4669 }
4670
4671 /**
4672 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4673 * @param subId The subscription to use to check the configuration.
4674 * @param c The callback that will be used to send the result.
4675 */
4676 @Override
4677 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4678 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4679 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4681 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4682 }
4683 final long token = Binder.clearCallingIdentity();
4684
4685 try {
4686 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4687 if (controller != null) {
4688 ImsManager imsManager = controller.getImsManager(subId);
4689 if (imsManager != null) {
4690 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4691 } else {
4692 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4693 + "is inactive, ignoring unregister.");
4694 // If the ImsManager is not valid, just return, since the callback
4695 // will already have been removed internally.
4696 }
4697 }
4698 } finally {
4699 Binder.restoreCallingIdentity(token);
4700 }
4701 }
4702
4703 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004704 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4705 */
4706 @Override
4707 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4708 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4709 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4711 "IMS not available on device.");
4712 }
4713 final long token = Binder.clearCallingIdentity();
4714 try {
4715 Phone phone = getPhone(subId);
4716 if (phone == null) {
4717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4718 + subId + "'");
4719 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4720 }
4721 phone.getImsRegistrationState(regState -> {
4722 try {
4723 consumer.accept((regState == null)
4724 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4725 } catch (RemoteException e) {
4726 // Ignore if the remote process is no longer available to call back.
4727 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4728 }
4729 });
4730 } finally {
4731 Binder.restoreCallingIdentity(token);
4732 }
4733 }
4734
4735 /**
4736 * Get the transport type for the IMS service registration state.
4737 */
4738 @Override
4739 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004740 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004741 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004742 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4744 "IMS not available on device.");
4745 }
4746 final long token = Binder.clearCallingIdentity();
4747 try {
4748 Phone phone = getPhone(subId);
4749 if (phone == null) {
4750 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4751 + subId + "'");
4752 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4753 }
4754 phone.getImsRegistrationTech(regTech -> {
4755 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4756 int regTechConverted = (regTech == null)
4757 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4758 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4759 regTechConverted);
4760 try {
4761 consumer.accept(regTechConverted);
4762 } catch (RemoteException e) {
4763 // Ignore if the remote process is no longer available to call back.
4764 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4765 }
4766 });
4767 } finally {
4768 Binder.restoreCallingIdentity(token);
4769 }
4770 }
4771
shilu366312e2019-12-17 09:28:10 -08004772 /**
4773 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4774 * @param subId The subscription to use to check the configuration.
4775 * @param c The callback that will be used to send the result.
4776 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004778 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4779 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004780 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004781 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004782 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4783 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4784 "IMS not available on device.");
4785 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 final long token = Binder.clearCallingIdentity();
4787 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004788 int slotId = getSlotIndexOrException(subId);
4789 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004790
4791 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4792 if (controller != null) {
4793 ImsManager imsManager = controller.getImsManager(subId);
4794 if (imsManager != null) {
4795 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4796 } else {
4797 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4798 }
4799 } else {
4800 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4801 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004802 } catch (ImsException e) {
4803 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 } finally {
4805 Binder.restoreCallingIdentity(token);
4806 }
4807 }
4808
shilu366312e2019-12-17 09:28:10 -08004809 /**
4810 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4811 * @param subId The subscription to use to check the configuration.
4812 * @param c The callback that will be used to send the result.
4813 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004814 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004815 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004817 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4819 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4820 }
Meng Wangafbc5852019-09-19 17:37:13 -07004821
4822 final long token = Binder.clearCallingIdentity();
4823 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004824 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4825 if (controller != null) {
4826 ImsManager imsManager = controller.getImsManager(subId);
4827 if (imsManager != null) {
4828 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4829 } else {
4830 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4831 + " is inactive, ignoring unregister.");
4832 // If the ImsManager is not valid, just return, since the callback
4833 // will already have been removed internally.
4834 }
4835 }
Meng Wangafbc5852019-09-19 17:37:13 -07004836 } finally {
4837 Binder.restoreCallingIdentity(token);
4838 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004839 }
4840
4841 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004842 public boolean isCapable(int subId, int capability, int regTech) {
4843 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004844
4845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4846 FEATURE_TELEPHONY_IMS, "isCapable");
4847
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 final long token = Binder.clearCallingIdentity();
4849 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004850 int slotId = getSlotIndexOrException(subId);
4851 verifyImsMmTelConfiguredOrThrow(slotId);
4852 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4853 } catch (com.android.ims.ImsException e) {
4854 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4855 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004856 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004857 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4858 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004859 } finally {
4860 Binder.restoreCallingIdentity(token);
4861 }
4862 }
4863
4864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004865 public boolean isAvailable(int subId, int capability, int regTech) {
4866 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004867
4868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4869 FEATURE_TELEPHONY_IMS, "isAvailable");
4870
Brad Ebinger35c841c2018-10-01 10:40:55 -07004871 final long token = Binder.clearCallingIdentity();
4872 try {
4873 Phone phone = getPhone(subId);
4874 if (phone == null) return false;
4875 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004876 } catch (com.android.ims.ImsException e) {
4877 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4878 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004879 } finally {
4880 Binder.restoreCallingIdentity(token);
4881 }
4882 }
4883
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004884 /**
4885 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4886 * subscription.
4887 * @param subId The subscription to use to check the configuration.
4888 * @param callback The callback that will be used to send the result.
4889 * @param capability The MmTelFeature capability that will be used to send the result.
4890 * @param transportType The transport type of the MmTelFeature capability.
4891 */
4892 @Override
4893 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4894 int transportType) {
4895 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004896 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4897 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4898 "IMS not available on device.");
4899 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004900 final long token = Binder.clearCallingIdentity();
4901 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004902 int slotId = getSlotIndex(subId);
4903 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4904 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4905 + subId + "'");
4906 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4907 }
4908 verifyImsMmTelConfiguredOrThrow(slotId);
4909 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4910 transportType, aBoolean -> {
4911 try {
4912 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4913 } catch (RemoteException e) {
4914 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4915 + "running. Ignore");
4916 }
4917 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004918 } catch (ImsException e) {
4919 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004920 } finally {
4921 Binder.restoreCallingIdentity(token);
4922 }
4923 }
4924
shilu366312e2019-12-17 09:28:10 -08004925 /**
4926 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4927 * @param subId The subscription to use to check the configuration.
4928 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004929 @Override
4930 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004931 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004932 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004933
joonhunshin4ac60942023-11-15 15:23:39 +00004934 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4935 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4936
Brad Ebinger35c841c2018-10-01 10:40:55 -07004937 final long token = Binder.clearCallingIdentity();
4938 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004939 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004940 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004941 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004942 } catch (ImsException e) {
4943 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 } finally {
4945 Binder.restoreCallingIdentity(token);
4946 }
4947 }
4948
4949 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004950 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004952 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004953
4954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4955 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4956
Brad Ebinger35c841c2018-10-01 10:40:55 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004959 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004960 // This setting doesn't require an active ImsService connection, so do not verify. The
4961 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004962 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004963 } catch (ImsException e) {
4964 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004965 } finally {
4966 Binder.restoreCallingIdentity(identity);
4967 }
4968 }
4969
shilu366312e2019-12-17 09:28:10 -08004970 /**
4971 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4972 * @param subId The subscription to use to check the configuration.
4973 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004974 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004975 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004976 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004977 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004978
4979 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4980 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4981
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004985 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004986 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004987 } catch (ImsException e) {
4988 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
4992 }
4993
4994 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004995 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004997 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004998
4999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5000 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5001
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 final long identity = Binder.clearCallingIdentity();
5003 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005004 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005005 // This setting doesn't require an active ImsService connection, so do not verify. The
5006 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005007 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005008 } catch (ImsException e) {
5009 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
5013 }
5014
shilu366312e2019-12-17 09:28:10 -08005015 /**
5016 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5017 * @param subId The subscription to use to check the configuration.
5018 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 @Override
5020 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005021 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005022 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005023
5024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5025 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5026
Brad Ebinger35c841c2018-10-01 10:40:55 -07005027 final long identity = Binder.clearCallingIdentity();
5028 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005029 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005030 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005031 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005032 } catch (ImsException e) {
5033 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
5037 }
5038
5039 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005040 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005042 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005043
5044 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5045 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5046
Brad Ebinger35c841c2018-10-01 10:40:55 -07005047 final long identity = Binder.clearCallingIdentity();
5048 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005049 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005050 // This setting doesn't require an active ImsService connection, so do not verify. The
5051 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005052 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005053 } catch (ImsException e) {
5054 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
5058 }
5059
shilu366312e2019-12-17 09:28:10 -08005060 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005061 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5062 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5063 * @param subId The subscription to use to check the configuration.
5064 */
5065 @Override
5066 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005067 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005068 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005069
5070 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5071 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5072
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005075 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005076 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005077 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005078 } catch (ImsException e) {
5079 throw new ServiceSpecificException(e.getCode());
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
5083 }
5084
5085 /**
5086 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5087 * Requires MODIFY_PHONE_STATE permission.
5088 * @param subId The subscription to use to check the configuration.
5089 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5090 * false otherwise
5091 */
5092 @Override
5093 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5095 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005096
5097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5098 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5099
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005102 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005103 // This setting doesn't require an active ImsService connection, so do not verify. The
5104 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005105 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005106 } catch (ImsException e) {
5107 throw new ServiceSpecificException(e.getCode());
5108 } finally {
5109 Binder.restoreCallingIdentity(identity);
5110 }
5111 }
5112
5113 /**
shilu366312e2019-12-17 09:28:10 -08005114 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5115 * @param subId The subscription to use to check the configuration.
5116 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005117 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005118
Brad Ebinger35c841c2018-10-01 10:40:55 -07005119 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005120 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005121 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005122
5123 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5124 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5125
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 final long identity = Binder.clearCallingIdentity();
5127 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005128 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005129 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005130 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005131 } catch (ImsException e) {
5132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
5136 }
5137
5138 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005139 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005141 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005142
5143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5144 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5145
Brad Ebinger35c841c2018-10-01 10:40:55 -07005146 final long identity = Binder.clearCallingIdentity();
5147 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005148 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005149 // This setting doesn't require an active ImsService connection, so do not verify. The
5150 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005152 } catch (ImsException e) {
5153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 @Override
5160 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5162 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005163
5164 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5165 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5166
Brad Ebinger35c841c2018-10-01 10:40:55 -07005167 final long identity = Binder.clearCallingIdentity();
5168 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005169 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005170 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005171 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005172 } catch (ImsException e) {
5173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178
shilu366312e2019-12-17 09:28:10 -08005179 /**
5180 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5181 * @param subId The subscription to use to check the configuration.
5182 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005183 @Override
5184 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005185 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005186 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005187
5188 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5189 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5190
Brad Ebinger35c841c2018-10-01 10:40:55 -07005191 final long identity = Binder.clearCallingIdentity();
5192 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005193 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005194 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005195 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005196 } catch (ImsException e) {
5197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
5201 }
5202
5203 @Override
5204 public void setVoWiFiModeSetting(int subId, int mode) {
5205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5206 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005207
5208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5209 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5210
Brad Ebinger35c841c2018-10-01 10:40:55 -07005211 final long identity = Binder.clearCallingIdentity();
5212 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005213 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005214 // This setting doesn't require an active ImsService connection, so do not verify. The
5215 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005216 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005217 } catch (ImsException e) {
5218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
5222 }
5223
5224 @Override
5225 public int getVoWiFiRoamingModeSetting(int subId) {
5226 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005227
5228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5229 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5230
Brad Ebinger35c841c2018-10-01 10:40:55 -07005231 final long identity = Binder.clearCallingIdentity();
5232 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005233 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005234 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005235 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005236 } catch (ImsException e) {
5237 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
5241 }
5242
5243 @Override
5244 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5246 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005247
5248 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5249 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5250
Brad Ebinger35c841c2018-10-01 10:40:55 -07005251 final long identity = Binder.clearCallingIdentity();
5252 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005253 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005254 // This setting doesn't require an active ImsService connection, so do not verify. The
5255 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005256 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005257 } catch (ImsException e) {
5258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
5262 }
5263
5264 @Override
5265 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5267 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005268
5269 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5270 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5271
Brad Ebinger35c841c2018-10-01 10:40:55 -07005272 final long identity = Binder.clearCallingIdentity();
5273 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005274 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005275 // This setting doesn't require an active ImsService connection, so do not verify. The
5276 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005277 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005278 } catch (ImsException e) {
5279 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
5283 }
5284
shilu366312e2019-12-17 09:28:10 -08005285 /**
5286 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5287 * @param subId The subscription to use to check the configuration.
5288 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005289 @Override
5290 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005291 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005292 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005293
5294 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5295 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5296
Brad Ebinger35c841c2018-10-01 10:40:55 -07005297 final long identity = Binder.clearCallingIdentity();
5298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005300 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005301 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005302 } catch (ImsException e) {
5303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005309 @Override
5310 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5311 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005312
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005313 final long identity = Binder.clearCallingIdentity();
5314 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005315 if (!isImsAvailableOnDevice()) {
5316 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5317 "IMS not available on device.");
5318 }
5319 int slotId = getSlotIndexOrException(subId);
5320 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005321
5322 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5323 if (controller != null) {
5324 ImsManager imsManager = controller.getImsManager(subId);
5325 if (imsManager != null) {
5326 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5327 } else {
5328 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5329 }
5330 } else {
5331 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5332 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005333 } catch (ImsException e) {
5334 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
5338 }
5339
5340 @Override
5341 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5342 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005343
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005344 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005345 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5346 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5347 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005348 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005349 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5350 if (controller != null) {
5351 ImsManager imsManager = controller.getImsManager(subId);
5352 if (imsManager != null) {
5353 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5354 } else {
5355 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5356 + " is inactive, ignoring unregister.");
5357 // If the ImsManager is not valid, just return, since the callback will already
5358 // have been removed internally.
5359 }
5360 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005361 } finally {
5362 Binder.restoreCallingIdentity(identity);
5363 }
5364 }
5365
joonhunshincffb7fc2021-11-28 07:32:01 +00005366 @Override
5367 public void registerFeatureProvisioningChangedCallback(int subId,
5368 IFeatureProvisioningCallback callback) {
5369 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5370 mApp, subId, "registerFeatureProvisioningChangedCallback");
5371
5372 final long identity = Binder.clearCallingIdentity();
5373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5374 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5375 }
5376
joonhunshin91bc1952022-04-29 08:47:15 +00005377 try {
5378 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5379 if (controller == null) {
5380 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5381 "Device does not support IMS");
5382 }
5383 controller.addFeatureProvisioningChangedCallback(subId, callback);
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
5386 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005387 }
5388
5389 @Override
5390 public void unregisterFeatureProvisioningChangedCallback(int subId,
5391 IFeatureProvisioningCallback callback) {
5392 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5393 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5394
5395 final long identity = Binder.clearCallingIdentity();
5396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5397 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5398 }
5399
joonhunshin91bc1952022-04-29 08:47:15 +00005400 try {
5401 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5402 if (controller == null) {
5403 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5404 return;
5405 }
5406 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005410 }
allenwtsu99c623b2020-01-03 18:24:23 +08005411
5412 private void checkModifyPhoneStatePermission(int subId, String message) {
5413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5414 message);
5415 }
5416
allenwtsu99c623b2020-01-03 18:24:23 +08005417 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005418 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005419 boolean isProvisioned) {
5420 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5421
joonhunshin4ac60942023-11-15 15:23:39 +00005422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5423 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5424
allenwtsu99c623b2020-01-03 18:24:23 +08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005427 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5428 if (controller == null) {
5429 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5430 return;
5431 }
5432 controller.setRcsProvisioningStatusForCapability(
5433 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
allenwtsu99c623b2020-01-03 18:24:23 +08005437 }
5438
5439
5440 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005441 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5442 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5443 mApp, subId, "getRcsProvisioningStatusForCapability");
5444
joonhunshin4ac60942023-11-15 15:23:39 +00005445 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5446 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5447
allenwtsu99c623b2020-01-03 18:24:23 +08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005450 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5451 if (controller == null) {
5452 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5453
5454 // device does not support IMS, this method will return true always.
5455 return true;
5456 }
5457 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
5461 }
5462
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005463 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005464 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5465 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005466 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005467
joonhunshin4ac60942023-11-15 15:23:39 +00005468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5469 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5470
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005471 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005472 final long identity = Binder.clearCallingIdentity();
5473 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005474 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5475 if (controller == null) {
5476 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5477 return;
5478 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005479 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005480 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
5484 }
5485
5486 @Override
5487 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005488 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5489 mApp, subId, "getProvisioningStatusForCapability");
5490
joonhunshin4ac60942023-11-15 15:23:39 +00005491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5492 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5493
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005494 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005495 final long identity = Binder.clearCallingIdentity();
5496 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005497 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5498 if (controller == null) {
5499 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005500
joonhunshin91bc1952022-04-29 08:47:15 +00005501 // device does not support IMS, this method will return true always.
5502 return true;
5503 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005504 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5505 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
5509 }
5510
5511 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005512 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5513 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5514 mApp, subId, "isProvisioningRequiredForCapability");
5515
joonhunshin4ac60942023-11-15 15:23:39 +00005516 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5517 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5518
joonhunshincffb7fc2021-11-28 07:32:01 +00005519 final long identity = Binder.clearCallingIdentity();
5520 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005521 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5522 if (controller == null) {
5523 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5524
5525 // device does not support IMS, this method will return false
5526 return false;
5527 }
5528 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005529 } finally {
5530 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005531 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 }
5533
5534 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005535 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5536 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5537 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005538
joonhunshin4ac60942023-11-15 15:23:39 +00005539 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5540 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5541
joonhunshincffb7fc2021-11-28 07:32:01 +00005542 final long identity = Binder.clearCallingIdentity();
5543 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005544 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5545 if (controller == null) {
5546 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5547
5548 // device does not support IMS, this method will return false
5549 return false;
5550 }
5551 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005555 }
5556
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005557 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005558 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005559 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5560 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5561 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005562 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5563 mApp, subId, "getImsProvisioningInt");
5564
joonhunshin4ac60942023-11-15 15:23:39 +00005565 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5566 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5567
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005568 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005572 int slotId = getSlotIndex(subId);
5573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5574 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5575 + subId + "' for key:" + key);
5576 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5577 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005578
joonhunshin91bc1952022-04-29 08:47:15 +00005579 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5580 if (controller == null) {
5581 loge("getImsProvisioningInt: Device does not support IMS");
5582
5583 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5584 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5585 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005586 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5587 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005588 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5589 return retVal;
5590 }
5591
calvinpanb5a34062021-02-08 19:59:36 +08005592 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005593 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005594 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5595 + subId + "' for key:" + key);
5596 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601
5602 @Override
5603 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005604 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5605 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5606 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005607 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5608 mApp, subId, "getImsProvisioningString");
5609
joonhunshin4ac60942023-11-15 15:23:39 +00005610 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5611 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5612
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005616 int slotId = getSlotIndex(subId);
5617 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5618 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5619 + subId + "' for key:" + key);
5620 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5621 }
calvinpanb5a34062021-02-08 19:59:36 +08005622 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005623 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005624 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5625 + subId + "' for key:" + key);
5626 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
5630 }
5631
5632 @Override
5633 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005634 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5635 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5636 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5638 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005639
joonhunshin4ac60942023-11-15 15:23:39 +00005640 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5641 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5642
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005643 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005647 int slotId = getSlotIndex(subId);
5648 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5649 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5650 + subId + "' for key:" + key);
5651 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5652 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005653
joonhunshin91bc1952022-04-29 08:47:15 +00005654 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5655 if (controller == null) {
5656 loge("setImsProvisioningInt: Device does not support IMS");
5657
5658 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5660 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005661 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5662 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005663 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5664 return retVal;
5665 }
5666
calvinpanb5a34062021-02-08 19:59:36 +08005667 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5668 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005669 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005670 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005671 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 }
5676
5677 @Override
5678 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005679 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5680 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5681 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5683 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005684
5685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5686 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5687
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005691 int slotId = getSlotIndex(subId);
5692 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5693 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5694 + subId + "' for key:" + key);
5695 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5696 }
calvinpanb5a34062021-02-08 19:59:36 +08005697 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5698 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005699 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005700 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005701 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
5705 }
5706
Brad Ebinger919631e2021-06-02 17:46:35 -07005707 /**
5708 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5709 * for the given slot ID or no ImsResolver instance has been created.
5710 * @param slotId The slot ID that the IMS service is created for.
5711 * @throws ImsException If there is no ImsService configured for this slot.
5712 */
5713 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5714 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5715 ImsFeature.FEATURE_MMTEL)) {
5716 throw new ImsException("This subscription does not support MMTEL over IMS",
5717 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5718 }
5719 }
5720
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005721 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005722 int slotId = SubscriptionManager.getSlotIndex(subId);
5723 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005724 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5725 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005726 }
5727 return slotId;
5728 }
5729
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005730 private int getSlotIndex(int subId) {
5731 int slotId = SubscriptionManager.getSlotIndex(subId);
5732 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5733 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5734 }
5735 return slotId;
5736 }
5737
Wink Saville36469e72014-06-11 15:17:00 -07005738 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005739 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005740 */
5741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005742 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5743 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005744 try {
5745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5746 } catch (SecurityException se) {
5747 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5748 throw new SecurityException("Package " + callingPackage + " does not belong to "
5749 + Binder.getCallingUid());
5750 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005751 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005752 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005753 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005754 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005755 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005756 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005758 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5759 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005760
joonhunshin4ac60942023-11-15 15:23:39 +00005761 enforceTelephonyFeatureWithException(callingPackage,
5762 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 final Phone phone = getPhone(subId);
5767 if (phone != null) {
5768 return phone.getServiceState().getDataNetworkType();
5769 } else {
5770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5771 }
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005775 }
5776
5777 /**
5778 * Returns the data network type
5779 */
5780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005782 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005783 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005784 }
5785
5786 /**
5787 * Returns the data network type for a subId
5788 */
5789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005790 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5791 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005792 String functionName = "getDataNetworkTypeForSubscriber";
5793 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5794 mApp, functionName)) {
5795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5796 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5797 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5798 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005799 }
5800
joonhunshin4ac60942023-11-15 15:23:39 +00005801 enforceTelephonyFeatureWithException(callingPackage,
5802 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 final Phone phone = getPhone(subId);
5807 if (phone != null) {
5808 return phone.getServiceState().getDataNetworkType();
5809 } else {
5810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5811 }
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005815 }
5816
5817 /**
Wink Saville36469e72014-06-11 15:17:00 -07005818 * Returns the Voice network type for a subId
5819 */
5820 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005821 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5822 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005823 String functionName = "getVoiceNetworkTypeForSubscriber";
5824 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5825 mApp, functionName)) {
5826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5827 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5828 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5829 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005830 }
5831
joonhunshin4ac60942023-11-15 15:23:39 +00005832 enforceTelephonyFeatureWithException(callingPackage,
5833 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 final Phone phone = getPhone(subId);
5838 if (phone != null) {
5839 return phone.getServiceState().getVoiceNetworkType();
5840 } else {
5841 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5842 }
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005846 }
5847
5848 /**
5849 * @return true if a ICC card is present
5850 */
5851 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005852 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005853 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005854 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005855 }
5856
5857 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005858 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005859 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005860 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005861 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005862 if (!mApp.getResources().getBoolean(
5863 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5864 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5865 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5866 }
joonhunshin4ac60942023-11-15 15:23:39 +00005867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 final Phone phone = PhoneFactory.getPhone(slotIndex);
5871 if (phone != null) {
5872 return phone.getIccCard().hasIccCard();
5873 } else {
5874 return false;
5875 }
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005879 }
5880
5881 /**
5882 * Return if the current radio is LTE on CDMA. This
5883 * is a tri-state return value as for a period of time
5884 * the mode may be unknown.
5885 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005886 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005887 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005888 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005889 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005890 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005891 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5892 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5893 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005894 }
5895
Sanket Padawe356d7632015-06-22 14:03:32 -07005896 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005897 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5898 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005899 try {
5900 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5901 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005902 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5903 }
5904
joonhunshin4ac60942023-11-15 15:23:39 +00005905 enforceTelephonyFeatureWithException(callingPackage,
5906 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 final Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5913 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005914 return TelephonyProperties.lte_on_cdma_device()
5915 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 }
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005919 }
Wink Saville36469e72014-06-11 15:17:00 -07005920 }
5921
Wink Saville36469e72014-06-11 15:17:00 -07005922 /**
5923 * {@hide}
5924 * Returns Default subId, 0 in the case of single standby.
5925 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005926 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005927 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005928 }
5929
Shishir Agrawala9f32182016-04-12 12:00:16 -07005930 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005931 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005932 }
5933
Wink Savilleb564aae2014-10-23 10:18:09 -07005934 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005935 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005936 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005937
Pengquan Menge92a50d2018-09-21 15:54:48 -07005938 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005939 return getSubscriptionManagerService().isActiveSubId(subId,
5940 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005941 }
5942
Ihab Awadf2177b72013-11-25 13:33:23 -08005943 /**
5944 * @see android.telephony.TelephonyManager.WifiCallingChoices
5945 */
5946 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 final long identity = Binder.clearCallingIdentity();
5948 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005949 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5951 getWhenToMakeWifiCallsDefaultPreference());
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005955 }
5956
5957 /**
5958 * @see android.telephony.TelephonyManager.WifiCallingChoices
5959 */
5960 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 final long identity = Binder.clearCallingIdentity();
5962 try {
5963 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005964 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005969 }
5970
Sailesh Nepald1e68152013-12-12 19:08:02 -08005971 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005972 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005973 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005974 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005975
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005976 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5977 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5978 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005979 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005980 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005981 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005982 }
5983 return PhoneFactory.getPhone(phoneId);
5984 }
5985
Shishir Agrawal566b7612013-10-28 14:41:00 -07005986 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005987 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005988 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005989
Rambo Wanga1782702021-11-10 20:15:19 -08005990 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5991 /*message=*/ "iccOpenLogicalChannel");
5992
5993 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5994 // Verify that the callingPackage in the request belongs to the calling UID
5995 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5996
joonhunshin4ac60942023-11-15 15:23:39 +00005997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5998 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5999
Rambo Wanga1782702021-11-10 20:15:19 -08006000 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006001 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006002
Rambo Wanga1782702021-11-10 20:15:19 -08006003 private Phone getPhoneFromValidIccLogicalChannelRequest(
6004 @NonNull IccLogicalChannelRequest request, String message) {
6005 Phone phone;
6006 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6008 mApp, request.subId, message);
6009 phone = getPhoneFromSubId(request.subId);
6010 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6011 enforceModifyPermission();
6012 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6013 } else {
6014 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006015 }
Rambo Wanga1782702021-11-10 20:15:19 -08006016 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006017 }
6018
6019 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006020 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 final long identity = Binder.clearCallingIdentity();
6022 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006023 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006025 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6026 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006027 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6028 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 loge("The calling package is not allowed to access ISD-R.");
6030 throw new SecurityException(
6031 "The calling package is not allowed to access ISD-R.");
6032 }
Derek Tan740e1672017-06-27 14:56:27 -07006033 }
Derek Tan740e1672017-06-27 14:56:27 -07006034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006036 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6037 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 return response;
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006042 }
6043
6044 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006045 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006046 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6047 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6048
Rambo Wanga1782702021-11-10 20:15:19 -08006049 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6050 /*message=*/"iccCloseLogicalChannel");
6051
6052 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6053
6054 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006055 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006056
Rambo Wanga1782702021-11-10 20:15:19 -08006057 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6058 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006059 // before this feature is enabled, this API should only return false if
6060 // the operation fails instead of throwing runtime exception for
6061 // backward-compatibility.
6062 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6063 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 final long identity = Binder.clearCallingIdentity();
6065 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006066 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006067 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 }
Chen Xue9d737e2022-01-01 23:41:31 -08006069 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006070 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006071 Boolean success = false;
6072 if (result instanceof RuntimeException) {
6073 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006074 if (shouldThrowExceptionOnFailure) {
6075 throw (RuntimeException) result;
6076 } else {
6077 return false;
6078 }
Chen Xue9d737e2022-01-01 23:41:31 -08006079 } else if (result instanceof Boolean) {
6080 success = (Boolean) result;
6081 } else {
6082 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6083 }
Rambo Wanga1782702021-11-10 20:15:19 -08006084 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 return success;
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006088 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006089 }
6090
6091 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006092 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006093 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6095 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006096
6097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6098 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6099
Jordan Liu4c733742019-02-28 12:03:40 -08006100 if (DBG) {
6101 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6102 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6103 + p3 + " data=" + data);
6104 }
6105 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6106 command, p1, p2, p3, data);
6107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006108
Jordan Liu4c733742019-02-28 12:03:40 -08006109 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006110 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006111 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006112 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006113
6114 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6115 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6116 "iccTransmitApduLogicalChannelBySlot");
6117
Jordan Liu4c733742019-02-28 12:03:40 -08006118 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006119 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006120 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6121 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006122 }
6123 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006124 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6125 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006126 }
6127
6128 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6129 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 final long identity = Binder.clearCallingIdentity();
6131 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006132 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 return "";
6134 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006137 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6138 null /* workSource */);
6139 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 // Append the returned status code to the end of the response payload.
6142 String s = Integer.toHexString(
6143 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6144 if (response.payload != null) {
6145 s = IccUtils.bytesToHexString(response.payload) + s;
6146 }
6147 return s;
6148 } finally {
6149 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006150 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006151 }
Jake Hambye994d462014-02-03 13:10:13 -08006152
Evan Charltonc66da362014-05-16 14:06:40 -07006153 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006154 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6155 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6157 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006159
6160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6161 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6162
Jordan Liu4c733742019-02-28 12:03:40 -08006163 if (DBG) {
6164 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6165 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6166 }
6167 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6168 cla, command, p1, p2, p3, data);
6169 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006170
Jordan Liu4c733742019-02-28 12:03:40 -08006171 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006172 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006173 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006174 enforceModifyPermission();
6175 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006176
6177 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6178 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6179
Jordan Liu4c733742019-02-28 12:03:40 -08006180 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006181 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006182 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6183 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006184 }
6185
6186 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006187 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6188 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006189 }
6190
6191 // open APDU basic channel assuming the caller has sufficient permissions
6192 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6193 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6197 && TextUtils.equals(ISDR_AID, data)) {
6198 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006199 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6200 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 if (bestComponent == null
6202 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6203 loge("The calling package is not allowed to select ISD-R.");
6204 throw new SecurityException(
6205 "The calling package is not allowed to select ISD-R.");
6206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006207 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006210 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6211 null /* workSource */);
6212 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 // Append the returned status code to the end of the response payload.
6215 String s = Integer.toHexString(
6216 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6217 if (response.payload != null) {
6218 s = IccUtils.bytesToHexString(response.payload) + s;
6219 }
6220 return s;
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006223 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006224 }
6225
6226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006227 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006228 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6230 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006231
joonhunshin4ac60942023-11-15 15:23:39 +00006232 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6233 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 final long identity = Binder.clearCallingIdentity();
6236 try {
6237 if (DBG) {
6238 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6239 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6240 }
6241
6242 IccIoResult response =
6243 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6244 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6245 subId);
6246
6247 if (DBG) {
6248 log("Exchange SIM_IO [R]" + response);
6249 }
6250
6251 byte[] result = null;
6252 int length = 2;
6253 if (response.payload != null) {
6254 length = 2 + response.payload.length;
6255 result = new byte[length];
6256 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6257 } else {
6258 result = new byte[length];
6259 }
6260
6261 result[length - 1] = (byte) response.sw2;
6262 result[length - 2] = (byte) response.sw1;
6263 return result;
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006266 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006267 }
6268
Nathan Haroldb3014052017-01-25 15:57:32 -08006269 /**
6270 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6271 * on a particular subscription
6272 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006273 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6274 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006276 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006277 return null;
6278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279
joonhunshin4ac60942023-11-15 15:23:39 +00006280 enforceTelephonyFeatureWithException(callingPackage,
6281 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 final long identity = Binder.clearCallingIdentity();
6284 try {
6285 if (appType != TelephonyManager.APPTYPE_USIM
6286 && appType != TelephonyManager.APPTYPE_SIM) {
6287 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6288 return null;
6289 }
6290 Object response = sendRequest(
6291 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6292 if (response instanceof String[]) {
6293 return (String[]) response;
6294 }
yincheng zhao2737e882019-09-06 17:06:54 -07006295 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006297 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 } finally {
6299 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006300 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006301 }
6302
yincheng zhao2737e882019-09-06 17:06:54 -07006303 /**
6304 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6305 * subscription.
6306 *
6307 * @param subId the id of the subscription.
6308 * @param appType the uicc app type, must be USIM or SIM.
6309 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6310 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006311 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006312 * @return number of fplmns that is successfully written to the SIM.
6313 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006314 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6315 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6317 mApp, subId, "setForbiddenPlmns");
6318
joonhunshin4ac60942023-11-15 15:23:39 +00006319 enforceTelephonyFeatureWithException(callingPackage,
6320 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6321
yincheng zhao2737e882019-09-06 17:06:54 -07006322 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6323 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6324 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6325 }
6326 if (fplmns == null) {
6327 throw new IllegalArgumentException("Fplmn List provided is null");
6328 }
6329 for (String fplmn : fplmns) {
6330 if (!CellIdentity.isValidPlmn(fplmn)) {
6331 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6332 }
6333 }
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 Object response = sendRequest(
6337 CMD_SET_FORBIDDEN_PLMNS,
6338 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6339 subId);
6340 return (int) response;
6341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
6344 }
6345
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006346 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006347 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6349 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006350
joonhunshin4ac60942023-11-15 15:23:39 +00006351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6352 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6357 if (response.payload == null) {
6358 return "";
6359 }
Evan Charltonc66da362014-05-16 14:06:40 -07006360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 // Append the returned status code to the end of the response payload.
6362 String s = Integer.toHexString(
6363 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6364 s = IccUtils.bytesToHexString(response.payload) + s;
6365 return s;
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
Evan Charltonc66da362014-05-16 14:06:40 -07006369 }
6370
Jake Hambye994d462014-02-03 13:10:13 -08006371 /**
6372 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6373 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6374 *
6375 * @param itemID the ID of the item to read
6376 * @return the NV item as a String, or null on error.
6377 */
6378 @Override
6379 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006380 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
6384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006387 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6389 return value;
6390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
Jake Hambye994d462014-02-03 13:10:13 -08006393 }
6394
6395 /**
6396 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6397 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6398 *
6399 * @param itemID the ID of the item to read
6400 * @param itemValue the value to write, as a String
6401 * @return true on success; false on any failure
6402 */
6403 @Override
6404 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006405 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6407 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6412 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006413 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6415 return success;
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
Jake Hambye994d462014-02-03 13:10:13 -08006419 }
6420
6421 /**
6422 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6423 * Used for device configuration by some CDMA operators.
6424 *
6425 * @param preferredRoamingList byte array containing the new PRL
6426 * @return true on success; false on any failure
6427 */
6428 @Override
6429 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6431 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6436 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6437 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6438 return success;
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
Jake Hambye994d462014-02-03 13:10:13 -08006442 }
6443
6444 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006445 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006446 * Used for device configuration by some CDMA operators.
6447 *
chen xu6dac5ab2018-10-26 17:39:23 -07006448 * @param slotIndex - device slot.
6449 *
Jake Hambye994d462014-02-03 13:10:13 -08006450 * @return true on success; false on any failure
6451 */
6452 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006453 public boolean resetModemConfig(int slotIndex) {
6454 Phone phone = PhoneFactory.getPhone(slotIndex);
6455 if (phone != null) {
6456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6457 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458
joonhunshin4ac60942023-11-15 15:23:39 +00006459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6460 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6461
chen xu6dac5ab2018-10-26 17:39:23 -07006462 final long identity = Binder.clearCallingIdentity();
6463 try {
6464 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6465 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6466 return success;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470 }
chen xu6dac5ab2018-10-26 17:39:23 -07006471 return false;
6472 }
6473
6474 /**
6475 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6476 *
6477 * @param slotIndex - device slot.
6478 *
6479 * @return true on success; false on any failure
6480 */
6481 @Override
6482 public boolean rebootModem(int slotIndex) {
6483 Phone phone = PhoneFactory.getPhone(slotIndex);
6484 if (phone != null) {
6485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6486 mApp, phone.getSubId(), "rebootModem");
6487
joonhunshin4ac60942023-11-15 15:23:39 +00006488 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6489 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6490
chen xu6dac5ab2018-10-26 17:39:23 -07006491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6494 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6495 return success;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006501 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006502
Brad Ebinger51f743a2017-01-23 13:50:20 -08006503 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006504 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6505 * {@link #disableIms(int)}.
6506 * @param slotIndex device slot.
6507 */
6508 public void resetIms(int slotIndex) {
6509 enforceModifyPermission();
6510
joonhunshin4ac60942023-11-15 15:23:39 +00006511 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6512 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6513
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 if (mImsResolver == null) {
6517 // may happen if the does not support IMS.
6518 return;
6519 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006520 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006527 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6528 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006529 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006530 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532
6533 final long identity = Binder.clearCallingIdentity();
6534 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006535 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006536 // may happen if the device does not support IMS.
6537 return;
6538 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006539 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006543 }
6544
6545 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006546 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6547 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006548 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006549 public void disableIms(int slotId) {
6550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006554 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006555 // may happen if the device does not support IMS.
6556 return;
6557 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006558 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006562 }
6563
6564 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006565 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6566 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006567 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006568 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006569 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006574 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6576 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006577 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006578 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006582 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006583 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006584 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6585 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006586 @Override
6587 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006588 enforceModifyPermission();
6589
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006593 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
6598
6599 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006600 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006601 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006602 */
6603 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605
6606 final long identity = Binder.clearCallingIdentity();
6607 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006608 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006609 // may happen if the device does not support IMS.
6610 return null;
6611 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006612 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006616 }
6617
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006618 /**
6619 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006620 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006621 */
6622 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6623 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006627 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006628 // may happen if the device does not support IMS.
6629 return null;
6630 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006631 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006635 }
6636
Brad Ebinger884c07b2018-02-15 16:17:40 -08006637 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006638 * Sets the ImsService Package Name that Telephony will bind to.
6639 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006640 * @param slotIndex the slot ID that the ImsService should bind for.
6641 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006642 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006643 * @param featureTypes An integer array of feature types associated with a packageName.
6644 * @param packageName The name of the package that the current configuration will be replaced
6645 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006646 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006647 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006648 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6649 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006652 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006656 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006657 // may happen if the device does not support IMS.
6658 return false;
6659 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 Map<Integer, String> featureConfig = new HashMap<>();
6661 for (int featureType : featureTypes) {
6662 featureConfig.put(featureType, packageName);
6663 }
6664 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6665 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006669 }
6670
6671 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006672 * Clears any carrier ImsService overrides for the slot index specified that were previously
6673 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6674 *
6675 * This should only be used for testing.
6676 *
6677 * @param slotIndex the slot ID that the ImsService should bind for.
6678 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6679 */
6680 @Override
6681 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6683 "clearCarrierImsServiceOverride");
6684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006685 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 if (mImsResolver == null) {
6690 // may happen if the device does not support IMS.
6691 return false;
6692 }
6693 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
6697 }
6698
6699 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006700 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006701 *
6702 * @param slotId The slot that the ImsService is associated with.
6703 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6704 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006705 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006706 * @return the package name of the ImsService configuration.
6707 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006708 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6709 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006710 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006711 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6712 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006716 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006717 // may happen if the device does not support IMS.
6718 return "";
6719 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006720 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006721 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6722 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006726 }
6727
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006728 /**
6729 * Get the MmTelFeature state associated with the requested subscription id.
6730 * @param subId The subscription that the MmTelFeature is associated with.
6731 * @param callback A callback with an integer containing the
6732 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6733 */
6734 @Override
6735 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6736 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006737 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6739 "IMS not available on device.");
6740 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006741 final long token = Binder.clearCallingIdentity();
6742 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006743 int slotId = getSlotIndex(subId);
6744 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6745 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6746 + subId + "'");
6747 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6748 }
6749 verifyImsMmTelConfiguredOrThrow(slotId);
6750 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6751 try {
6752 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6753 } catch (RemoteException e) {
6754 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6755 + "Ignore");
6756 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006757 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006758 } catch (ImsException e) {
6759 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006760 } finally {
6761 Binder.restoreCallingIdentity(token);
6762 }
6763 }
6764
Daniel Brightbb5840b2021-01-12 15:48:18 -08006765 /**
6766 * Sets the ims registration state on all valid {@link Phone}s.
6767 */
6768 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770
6771 final long identity = Binder.clearCallingIdentity();
6772 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006773 // NOTE: Before S, this method only set the default phone.
6774 for (final Phone phone : PhoneFactory.getPhones()) {
6775 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6776 phone.setImsRegistrationState(registered);
6777 }
6778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 } finally {
6780 Binder.restoreCallingIdentity(identity);
6781 }
Wink Saville36469e72014-06-11 15:17:00 -07006782 }
6783
6784 /**
Stuart Scott54788802015-03-30 13:18:01 -07006785 * Set the network selection mode to automatic.
6786 *
6787 */
6788 @Override
6789 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6791 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792
joonhunshin4ac60942023-11-15 15:23:39 +00006793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6794 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 final long identity = Binder.clearCallingIdentity();
6797 try {
shilufc958392020-01-20 11:36:01 -08006798 if (!isActiveSubscription(subId)) {
6799 return;
6800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006802 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6803 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
Stuart Scott54788802015-03-30 13:18:01 -07006807 }
6808
Jack Yud10cdd42020-09-28 20:28:01 -07006809 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006810 * Ask the radio to connect to the input network and change selection mode to manual.
6811 *
6812 * @param subId the id of the subscription.
6813 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6814 * the operator to attach to.
6815 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6816 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6817 * normal network selection next time.
6818 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006819 */
6820 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006821 public boolean setNetworkSelectionModeManual(
6822 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6824 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006825
joonhunshin4ac60942023-11-15 15:23:39 +00006826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6827 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6828
Jack Yu285100e2022-12-02 22:48:35 -08006829 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006830 if (!isActiveSubscription(subId)) {
6831 return false;
6832 }
6833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006835 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006837 if (DBG) {
6838 log("setNetworkSelectionModeManual: subId: " + subId
6839 + " operator: " + operatorInfo);
6840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
6844 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006845 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006846 /**
shilu84f6e8b2019-12-19 13:58:01 -08006847 * Get the manual network selection
6848 *
6849 * @param subId the id of the subscription.
6850 *
6851 * @return the previously saved user selected PLMN
6852 */
6853 @Override
6854 public String getManualNetworkSelectionPlmn(int subId) {
6855 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006856 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6857 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006858
joonhunshin4ac60942023-11-15 15:23:39 +00006859 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6860 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6861
shilu84f6e8b2019-12-19 13:58:01 -08006862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006865 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006866 }
6867
6868 final Phone phone = getPhone(subId);
6869 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006870 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006871 }
6872 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6873 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006874 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006879
6880 /**
6881 * Scans for available networks.
6882 */
6883 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006884 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6885 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6887 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006888 LocationAccessPolicy.LocationPermissionResult locationResult =
6889 LocationAccessPolicy.checkLocationPermission(mApp,
6890 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6891 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006892 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006893 .setCallingPid(Binder.getCallingPid())
6894 .setCallingUid(Binder.getCallingUid())
6895 .setMethod("getCellNetworkScanResults")
6896 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006897 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6898 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006899 .build());
6900 switch (locationResult) {
6901 case DENIED_HARD:
6902 throw new SecurityException("Not allowed to access scan results -- location");
6903 case DENIED_SOFT:
6904 return null;
6905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906
Pengquan Menga1bb6272018-09-06 09:59:22 -07006907 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 try {
6909 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006910 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006915 }
6916
6917 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006918 * Get the call forwarding info, given the call forwarding reason.
6919 */
6920 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006921 public void getCallForwarding(int subId, int callForwardingReason,
6922 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006923 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006924
6925 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6926 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6927
Shuo Qian4a594052020-01-23 11:59:30 -08006928 long identity = Binder.clearCallingIdentity();
6929 try {
6930 if (DBG) {
6931 log("getCallForwarding: subId " + subId
6932 + " callForwardingReason" + callForwardingReason);
6933 }
Hall Liu27d24262020-09-18 19:04:59 -07006934
6935 Phone phone = getPhone(subId);
6936 if (phone == null) {
6937 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006938 callback.onError(
6939 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006940 } catch (RemoteException e) {
6941 // ignore
6942 }
6943 return;
6944 }
6945
6946 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6947 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6948 @Override
6949 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6950 try {
6951 callback.onCallForwardingInfoAvailable(info);
6952 } catch (RemoteException e) {
6953 // ignore
6954 }
6955 }
6956
6957 @Override
6958 public void onError(int error) {
6959 try {
6960 callback.onError(error);
6961 } catch (RemoteException e) {
6962 // ignore
6963 }
6964 }
6965 });
6966 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
6970 }
6971
6972 /**
6973 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6974 * reason, the number to forward, and the timeout before the forwarding is attempted.
6975 */
6976 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006977 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6978 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006979 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006980
6981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6982 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6983
Shuo Qian4a594052020-01-23 11:59:30 -08006984 long identity = Binder.clearCallingIdentity();
6985 try {
6986 if (DBG) {
6987 log("setCallForwarding: subId " + subId
6988 + " callForwardingInfo" + callForwardingInfo);
6989 }
Hall Liu27d24262020-09-18 19:04:59 -07006990
6991 Phone phone = getPhone(subId);
6992 if (phone == null) {
6993 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006994 callback.accept(
6995 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006996 } catch (RemoteException e) {
6997 // ignore
6998 }
6999 return;
7000 }
7001
7002 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7003 FunctionalUtils.ignoreRemoteException(callback::accept));
7004
7005 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
7009 }
7010
7011 /**
Hall Liu27d24262020-09-18 19:04:59 -07007012 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007013 */
7014 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007015 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007016 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007017
7018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7019 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7020
Shuo Qian4a594052020-01-23 11:59:30 -08007021 long identity = Binder.clearCallingIdentity();
7022 try {
Hall Liu27d24262020-09-18 19:04:59 -07007023 Phone phone = getPhone(subId);
7024 if (phone == null) {
7025 try {
7026 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7027 } catch (RemoteException e) {
7028 // ignore
7029 }
7030 return;
7031 }
SongFerngWang0e767992021-03-31 22:08:45 +08007032 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7033 PersistableBundle c = configManager.getConfigForSubId(subId);
7034 boolean requireUssd = c.getBoolean(
7035 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007036
Shuo Qian4a594052020-01-23 11:59:30 -08007037 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007038 if (requireUssd) {
7039 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7040 getSubscriptionCarrierId(subId));
7041 String newUssdCommand = "";
7042 try {
7043 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007044 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007045 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7046 } catch (NullPointerException e) {
7047 loge("Failed to generate USSD number" + e);
7048 }
7049 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7050 mMainThreadHandler, callback, carrierXmlParser,
7051 CarrierXmlParser.SsEntry.SSAction.QUERY);
7052 final String ussdCommand = newUssdCommand;
7053 Executors.newSingleThreadExecutor().execute(() -> {
7054 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7055 });
7056 } else {
7057 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7058 callback::accept);
7059 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7060 }
Shuo Qian4a594052020-01-23 11:59:30 -08007061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 }
7065
7066 /**
Hall Liu27d24262020-09-18 19:04:59 -07007067 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007068 */
7069 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007070 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007071 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007072
7073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7074 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7075
Shuo Qian4a594052020-01-23 11:59:30 -08007076 long identity = Binder.clearCallingIdentity();
7077 try {
Hall Liu27d24262020-09-18 19:04:59 -07007078 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7079
7080 Phone phone = getPhone(subId);
7081 if (phone == null) {
7082 try {
7083 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7084 } catch (RemoteException e) {
7085 // ignore
7086 }
7087 return;
7088 }
7089
SongFerngWang0e767992021-03-31 22:08:45 +08007090 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7091 PersistableBundle c = configManager.getConfigForSubId(subId);
7092 boolean requireUssd = c.getBoolean(
7093 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007094
SongFerngWang0e767992021-03-31 22:08:45 +08007095 if (DBG) log("getCallWaitingStatus: subId " + subId);
7096 if (requireUssd) {
7097 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7098 getSubscriptionCarrierId(subId));
7099 CarrierXmlParser.SsEntry.SSAction ssAction =
7100 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7101 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7102 String newUssdCommand = "";
7103 try {
7104 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007105 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007106 .makeCommand(ssAction, null);
7107 } catch (NullPointerException e) {
7108 loge("Failed to generate USSD number" + e);
7109 }
7110 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7111 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7112 final String ussdCommand = newUssdCommand;
7113 Executors.newSingleThreadExecutor().execute(() -> {
7114 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7115 });
7116 } else {
7117 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7118 FunctionalUtils.ignoreRemoteException(callback::accept));
7119
7120 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7121 }
Shuo Qian4a594052020-01-23 11:59:30 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
7125 }
7126
7127 /**
yinxub1bed742017-04-17 11:45:04 -07007128 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007129 *
yinxub1bed742017-04-17 11:45:04 -07007130 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007131 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7132 * location related information which will be sent if the caller already possess
7133 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007134 * @param request contains the radio access networks with bands/channels to scan
7135 * @param messenger callback messenger for scan results or errors
7136 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007137 * @return the id of the requested scan which can be used to stop the scan.
7138 */
7139 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007140 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7141 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007142 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7144 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007145 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007146 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7147 if (!renounceFineLocationAccess) {
7148 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007149 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7150 .setCallingPackage(callingPackage)
7151 .setCallingFeatureId(callingFeatureId)
7152 .setCallingPid(Binder.getCallingPid())
7153 .setCallingUid(Binder.getCallingUid())
7154 .setMethod("requestNetworkScan")
7155 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7156 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7157 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7158 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007159 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007161 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7162 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007163 if (e != null) {
7164 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7165 throw e;
7166 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007167 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007168 return TelephonyScanManager.INVALID_SCAN_ID;
7169 }
7170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 }
joonhunshin4ac60942023-11-15 15:23:39 +00007172
7173 enforceTelephonyFeatureWithException(callingPackage,
7174 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7175
Hall Liu912dfd32019-04-25 14:02:26 -07007176 int callingUid = Binder.getCallingUid();
7177 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007181 renounceFineLocationAccess, request, messenger, binder,
7182 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007183 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
yinxu504e1392017-04-12 16:03:22 -07007187 }
7188
Hall Liub2ac8ef2019-02-28 15:56:23 -08007189 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007190 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007191 boolean hasCarrierPriv;
7192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7195 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7196 } finally {
7197 Binder.restoreCallingIdentity(identity);
7198 }
Hall Liu558027f2019-05-15 19:14:05 -07007199 boolean hasNetworkScanPermission =
7200 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007201 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007202
7203 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7204 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7205 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007206 }
7207
7208 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7209 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007210 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7211 return new SecurityException("Specific channels must not be"
7212 + " scanned without location access.");
7213 }
7214 }
7215 }
7216
Hall Liub2ac8ef2019-02-28 15:56:23 -08007217 return null;
7218 }
7219
yinxu504e1392017-04-12 16:03:22 -07007220 /**
7221 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007222 *
7223 * @param subId id of the subscription
7224 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007225 */
7226 @Override
7227 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7229 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
Hall Liu912dfd32019-04-25 14:02:26 -07007231 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 final long identity = Binder.clearCallingIdentity();
7233 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007234 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
yinxu504e1392017-04-12 16:03:22 -07007238 }
7239
7240 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007241 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007242 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007243 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007244 */
7245 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007246 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007247 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007248 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007249 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250
joonhunshin4ac60942023-11-15 15:23:39 +00007251 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7252 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 final long identity = Binder.clearCallingIdentity();
7255 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007256 if (DBG) log("getAllowedNetworkTypesBitmask");
7257 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7258 int networkTypesBitmask = (result != null ? result[0] : -1);
7259 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7260 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007264 }
7265
7266 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007267 * Get the allowed network types for certain reason.
7268 *
7269 * @param subId the id of the subscription.
7270 * @param reason the reason the allowed network type change is taking place
7271 * @return the allowed network types.
7272 */
7273 @Override
7274 public long getAllowedNetworkTypesForReason(int subId,
7275 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007276 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007277 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007278
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007279 if (!mApp.getResources().getBoolean(
7280 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7282 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7283 "getAllowedNetworkTypesForReason");
7284 }
joonhunshin4ac60942023-11-15 15:23:39 +00007285
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007286 final long identity = Binder.clearCallingIdentity();
7287 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007288 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
7292 }
7293
7294 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007295 * Enable/Disable E-UTRA-NR Dual Connectivity
7296 * @param subId subscription id of the sim card
7297 * @param nrDualConnectivityState expected NR dual connectivity state
7298 * This can be passed following states
7299 * <ol>
7300 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7301 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7302 * <li>Disable NR dual connectivity and force secondary cell to be released
7303 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7304 * </ol>
7305 * @return operation result.
7306 */
7307 @Override
7308 public int setNrDualConnectivityState(int subId,
7309 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7311 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007312 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007313 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7314 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7315 }
7316
Sooraj Sasindran37444802020-08-11 10:40:43 -07007317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7321 nrDualConnectivityState, subId,
7322 workSource);
7323 if (DBG) log("enableNRDualConnectivity result: " + result);
7324 return result;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 }
7329
7330 /**
7331 * Is E-UTRA-NR Dual Connectivity enabled
7332 * @return true if dual connectivity is enabled else false
7333 */
7334 @Override
7335 public boolean isNrDualConnectivityEnabled(int subId) {
7336 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007337 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007338 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007339 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007340 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7341 return false;
7342 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7347 null, subId, workSource);
7348 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7349 return isEnabled;
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
7353 }
7354
7355 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007356 * Set the allowed network types of the device and
7357 * provide the reason triggering the allowed network change.
7358 *
7359 * @param subId the id of the subscription.
7360 * @param reason the reason the allowed network type change is taking place
7361 * @param allowedNetworkTypes the allowed network types.
7362 * @return true on success; false on any failure.
7363 */
7364 @Override
7365 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007366 @TelephonyManager.AllowedNetworkTypesReason int reason,
7367 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7369 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007370 // If the caller only has carrier privileges, then they should not be able to override
7371 // any network types which were set for security reasons.
7372 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7373 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007374 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007375 throw new SecurityException(
7376 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007377 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007378 }
joonhunshin4ac60942023-11-15 15:23:39 +00007379
7380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7381 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7382
SongFerngWang3ef3e072020-12-21 16:41:52 +08007383 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007384 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007385 return false;
7386 }
7387 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7388 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007389 return false;
7390 }
7391
Jack Yu5b494332023-01-23 18:18:04 +00007392 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7393 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007394
Jack Yue37dd262022-12-16 11:53:37 -08007395 Phone phone = getPhone(subId);
7396 if (phone == null) {
7397 return false;
7398 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007399
Jack Yue37dd262022-12-16 11:53:37 -08007400 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007401 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007402 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007403 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007404
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007405 final long identity = Binder.clearCallingIdentity();
7406 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007407 Boolean success = (Boolean) sendRequest(
7408 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7409 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7410
7411 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7412 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
7418 /**
Miaoa84611c2019-03-15 09:21:10 +08007419 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007420 *
Miaoa84611c2019-03-15 09:21:10 +08007421 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007422 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007423 * @hide
7424 */
7425 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007426 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007427 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007428
7429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7430 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007433 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 try {
Miaoa84611c2019-03-15 09:21:10 +08007435 if (phone != null) {
7436 return phone.hasMatchedTetherApnSetting();
7437 } else {
7438 return false;
7439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 } finally {
7441 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007442 }
Junda Liu475951f2014-11-07 16:45:03 -08007443 }
7444
7445 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007446 * Get the user enabled state of Mobile Data.
7447 *
7448 * TODO: remove and use isUserDataEnabled.
7449 * This can't be removed now because some vendor codes
7450 * calls through ITelephony directly while they should
7451 * use TelephonyManager.
7452 *
7453 * @return true on enabled
7454 */
7455 @Override
7456 public boolean getDataEnabled(int subId) {
7457 return isUserDataEnabled(subId);
7458 }
7459
7460 /**
7461 * Get whether mobile data is enabled per user setting.
7462 *
7463 * There are other factors deciding whether mobile data is actually enabled, but they are
7464 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007465 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007466 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7467 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007468 *
7469 * @return {@code true} if data is enabled else {@code false}
7470 */
7471 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007472 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007473 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007474 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007475 try {
7476 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7477 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007478 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007479 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7480 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007481 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007483 mApp, subId, functionName);
7484
Robert Greenwalt646120a2014-05-23 11:54:03 -07007485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
Jack Yu285100e2022-12-02 22:48:35 -08007489 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7491 Phone phone = PhoneFactory.getPhone(phoneId);
7492 if (phone != null) {
7493 boolean retVal = phone.isUserDataEnabled();
7494 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7495 return retVal;
7496 } else {
7497 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7498 return false;
7499 }
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007502 }
7503 }
7504
7505 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007506 * Checks if the device is capable of mobile data by considering whether whether the
7507 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7508 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007509 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007510 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007511 */
7512 @Override
7513 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007514 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007515 try {
7516 try {
7517 mApp.enforceCallingOrSelfPermission(
7518 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007519 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007520 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 try {
7522 mApp.enforceCallingOrSelfPermission(
7523 android.Manifest.permission.READ_PHONE_STATE,
7524 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007525 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 mApp.enforceCallingOrSelfPermission(
7527 permission.READ_BASIC_PHONE_STATE, functionName);
7528 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007529 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007530 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007531 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533
joonhunshin4ac60942023-11-15 15:23:39 +00007534 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7535 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
Jack Yu285100e2022-12-02 22:48:35 -08007539 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007541 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007542 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007543 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return retVal;
7545 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007546 if (DBG) {
7547 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7548 + subId + " retVal=false");
7549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 return false;
7551 }
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007554 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007555 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007556
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007557 /**
7558 * Check if data is enabled for a specific reason
7559 * @param subId Subscription index
7560 * @param reason the reason the data enable change is taking place
7561 * @return {@code true} if the overall data is enabled; {@code false} if not.
7562 */
7563 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007564 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007565 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007566 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007567 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007568 try {
7569 mApp.enforceCallingOrSelfPermission(
7570 android.Manifest.permission.ACCESS_NETWORK_STATE,
7571 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007572 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007573 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7574 functionName);
7575 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007576 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007577 try {
7578 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007579 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007580 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007582 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007583 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007584 }
7585
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007586 if (!mApp.getResources().getBoolean(
7587 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7588 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7589 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7590 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007591
7592 final long identity = Binder.clearCallingIdentity();
7593 try {
Jack Yu285100e2022-12-02 22:48:35 -08007594 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007595 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007596 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007597 + " reason=" + reason);
7598 }
7599 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007600 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007601 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007602 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007603 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007604 return retVal;
7605 } else {
7606 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007607 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007608 + subId + " retVal=false");
7609 }
7610 return false;
7611 }
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
7615 }
7616
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007617 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007618 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007619 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7620 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7621
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 // No permission needed; this only lets the caller inspect their own status.
7623 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007624 }
Junda Liu29340342014-07-10 15:23:27 -07007625
7626 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007627 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007628 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007629
7630 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7631 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7632
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007633 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7634 }
7635
7636 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7637 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007638 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007639 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007640 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7641 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007642 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7643 if (cpt == null) {
7644 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007645 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7646 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007647 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007648 }
7649
7650 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007651 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007652 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007653
7654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7655 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7656
chen xuf7e9fe82019-05-09 19:31:02 -07007657 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007658 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007659 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007660 Phone phone = getPhone(subId);
7661 if (phone == null) {
7662 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7663 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7664 }
7665 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7666 if (cpt == null) {
7667 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007668 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7669 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007670 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007671 }
7672
7673 @Override
7674 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007675 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007676
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007677 if (!mApp.getResources().getBoolean(
7678 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7679 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7680 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7681 "checkCarrierPrivilegesForPackageAnyPhone");
7682 }
joonhunshin4ac60942023-11-15 15:23:39 +00007683
Rambo Wange7209ce2022-02-23 13:41:02 -08007684 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7685 }
7686
7687 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007688 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007689 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007690 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007691 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7693 Phone phone = PhoneFactory.getPhone(phoneId);
7694 if (phone == null) {
7695 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007696 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007697 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7698 if (cpt == null) {
7699 continue;
7700 }
7701 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007702 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7703 break;
7704 }
7705 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007706 return result;
Junda Liu29340342014-07-10 15:23:27 -07007707 }
Derek Tan89e89d42014-07-08 17:00:10 -07007708
7709 @Override
Junda Liue64de782015-04-16 17:19:16 -07007710 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007711 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007712
7713 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7714 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7715 "getCarrierPackageNamesForIntentAndPhone");
7716
Rambo Wang8a247eb2022-02-08 21:11:18 +00007717 Phone phone = PhoneFactory.getPhone(phoneId);
7718 if (phone == null) {
7719 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007720 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007721 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7722 if (cpt == null) {
7723 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007724 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007725 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007726 }
7727
Amith Yamasani6e118872016-02-19 12:53:51 -08007728 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007729 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007730 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007731 Phone phone = PhoneFactory.getPhone(phoneId);
7732 if (phone == null) {
7733 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007734 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007735 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7736 if (cpt == null) {
7737 return Collections.emptyList();
7738 }
7739 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007740 }
7741
chen xuf7e9fe82019-05-09 19:31:02 -07007742 @Override
7743 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007744 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007745
7746 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7747 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7748 "getPackagesWithCarrierPrivilegesForAllPhones");
7749
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007750 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007751 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007752 try {
7753 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7754 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7755 }
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007758 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007759 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007760 }
7761
Rambo Wang6812ffb2022-03-15 16:54:17 -07007762 @Override
7763 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7764 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7765
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007766 if (!mApp.getResources().getBoolean(
7767 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7769 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7770 "getCarrierServicePackageNameForLogicalSlot");
7771 }
joonhunshin4ac60942023-11-15 15:23:39 +00007772
Rambo Wang6812ffb2022-03-15 16:54:17 -07007773 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7774 if (phone == null) {
7775 return null;
7776 }
7777 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7778 if (cpt == null) {
7779 return null;
7780 }
7781 return cpt.getCarrierServicePackageName();
7782 }
7783
Wink Savilleb564aae2014-10-23 10:18:09 -07007784 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007785 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007786 UiccPort port = phone == null ? null : phone.getUiccPort();
7787 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007788 return null;
7789 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007790 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007791 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007792 return null;
7793 }
7794 return iccId;
7795 }
7796
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007797 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007798 public void setCallComposerStatus(int subId, int status) {
7799 enforceModifyPermission();
7800
joonhunshin4ac60942023-11-15 15:23:39 +00007801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7802 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7803
Shuo Qiane4e11672020-12-15 22:15:33 -08007804 final long identity = Binder.clearCallingIdentity();
7805 try {
7806 Phone phone = getPhone(subId);
7807 if (phone != null) {
7808 Phone defaultPhone = phone.getImsPhone();
7809 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7810 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7811 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007812 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7813 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007814 }
7815 }
Shuo Qian284ae752020-12-22 19:10:14 -08007816 } catch (ImsException e) {
7817 throw new ServiceSpecificException(e.getCode());
7818 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007819 Binder.restoreCallingIdentity(identity);
7820 }
7821 }
7822
7823 @Override
7824 public int getCallComposerStatus(int subId) {
7825 enforceReadPrivilegedPermission("getCallComposerStatus");
7826
joonhunshin4ac60942023-11-15 15:23:39 +00007827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7828 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7829
Shuo Qiane4e11672020-12-15 22:15:33 -08007830 final long identity = Binder.clearCallingIdentity();
7831 try {
7832 Phone phone = getPhone(subId);
7833 if (phone != null) {
7834 Phone defaultPhone = phone.getImsPhone();
7835 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7836 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7837 return imsPhone.getCallComposerStatus();
7838 }
7839 }
7840 } finally {
7841 Binder.restoreCallingIdentity(identity);
7842 }
7843 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7844 }
7845
7846 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007847 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7848 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007849 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007850 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007851
joonhunshin4ac60942023-11-15 15:23:39 +00007852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7853 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7854 "setLine1NumberForDisplayForSubscriber");
7855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 final String iccId = getIccId(subId);
7859 final Phone phone = getPhone(subId);
7860 if (phone == null) {
7861 return false;
7862 }
arunvoddub1365e62024-07-31 09:42:31 +00007863 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7864 Rlog.e(LOG_TAG, "Number is too long");
7865 return false;
7866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 final String subscriberId = phone.getSubscriberId();
7868
7869 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007870 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 + subscriberId + " to " + number);
7872 }
7873
7874 if (TextUtils.isEmpty(iccId)) {
7875 return false;
7876 }
7877
7878 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7879
7880 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7881 if (alphaTag == null) {
7882 editor.remove(alphaTagPrefKey);
7883 } else {
7884 editor.putString(alphaTagPrefKey, alphaTag);
7885 }
7886
7887 // Record both the line number and IMSI for this ICCID, since we need to
7888 // track all merged IMSIs based on line number
7889 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7890 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7891 if (number == null) {
7892 editor.remove(numberPrefKey);
7893 editor.remove(subscriberPrefKey);
7894 } else {
7895 editor.putString(numberPrefKey, number);
7896 editor.putString(subscriberPrefKey, subscriberId);
7897 }
7898
7899 editor.commit();
7900 return true;
7901 } finally {
7902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007903 }
Derek Tan7226c842014-07-02 17:42:23 -07007904 }
7905
7906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007907 public String getLine1NumberForDisplay(int subId, String callingPackage,
7908 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007909 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007911 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007912 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007913 return null;
7914 }
Derek Tan97ebb422014-09-05 16:55:38 -07007915
joonhunshin4ac60942023-11-15 15:23:39 +00007916 enforceTelephonyFeatureWithException(callingPackage,
7917 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919 final long identity = Binder.clearCallingIdentity();
7920 try {
7921 String iccId = getIccId(subId);
7922 if (iccId != null) {
7923 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7924 if (DBG_MERGE) {
7925 log("getLine1NumberForDisplay returning "
7926 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7927 }
7928 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7931 return null;
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007934 }
Derek Tan7226c842014-07-02 17:42:23 -07007935 }
7936
7937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007938 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7939 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007941 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007942 return null;
7943 }
Derek Tan97ebb422014-09-05 16:55:38 -07007944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945 final long identity = Binder.clearCallingIdentity();
7946 try {
7947 String iccId = getIccId(subId);
7948 if (iccId != null) {
7949 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7950 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7951 }
7952 return null;
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007955 }
Derek Tan7226c842014-07-02 17:42:23 -07007956 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007957
7958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007959 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7960 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007961 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7962 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007964 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007965 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007966 return null;
7967 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007968
Jordan Liub49b04b2019-05-06 14:45:15 -07007969 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7970 // the process, where TelephonyManager was instantiated.
7971 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007972 final long identity = Binder.clearCallingIdentity();
7973 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007974 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 final TelephonyManager tele = TelephonyManager.from(context);
7976 final SubscriptionManager sub = SubscriptionManager.from(context);
7977
7978 // Figure out what subscribers are currently active
7979 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980
Jordan Liub49b04b2019-05-06 14:45:15 -07007981 // Only consider subs which match the current subId
7982 // This logic can be simplified. See b/131189269 for progress.
7983 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007984 activeSubscriberIds.add(tele.getSubscriberId(subId));
7985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986
7987 // First pass, find a number override for an active subscriber
7988 String mergeNumber = null;
7989 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7990 for (String key : prefs.keySet()) {
7991 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7992 final String subscriberId = (String) prefs.get(key);
7993 if (activeSubscriberIds.contains(subscriberId)) {
7994 final String iccId = key.substring(
7995 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7996 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7997 mergeNumber = (String) prefs.get(numberKey);
7998 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007999 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 + " for active subscriber " + subscriberId);
8001 }
8002 if (!TextUtils.isEmpty(mergeNumber)) {
8003 break;
8004 }
8005 }
8006 }
8007 }
8008
8009 // Shortcut when no active merged subscribers
8010 if (TextUtils.isEmpty(mergeNumber)) {
8011 return null;
8012 }
8013
8014 // Second pass, find all subscribers under that line override
8015 final ArraySet<String> result = new ArraySet<>();
8016 for (String key : prefs.keySet()) {
8017 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8018 final String number = (String) prefs.get(key);
8019 if (mergeNumber.equals(number)) {
8020 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8021 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8022 final String subscriberId = (String) prefs.get(subscriberKey);
8023 if (!TextUtils.isEmpty(subscriberId)) {
8024 result.add(subscriberId);
8025 }
8026 }
8027 }
8028 }
8029
8030 final String[] resultArray = result.toArray(new String[result.size()]);
8031 Arrays.sort(resultArray);
8032 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008033 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8035 }
8036 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008037 } finally {
8038 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008039 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008040 }
8041
8042 @Override
zoey chen38003472019-12-13 17:16:31 +08008043 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8044 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008045
joonhunshin4ac60942023-11-15 15:23:39 +00008046 enforceTelephonyFeatureWithException(callingPackage,
8047 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8048
Malcolm Chen6ca97372019-07-01 16:28:21 -07008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 final TelephonyManager telephonyManager = mApp.getSystemService(
8052 TelephonyManager.class);
8053 String subscriberId = telephonyManager.getSubscriberId(subId);
8054 if (subscriberId == null) {
8055 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008056 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008057 + subId);
8058 }
8059 return null;
8060 }
8061
Jack Yu3beaf9d2023-04-14 09:17:27 -07008062 final SubscriptionInfo info = getSubscriptionManagerService()
8063 .getSubscriptionInfo(subId);
8064 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008065 // If it doesn't belong to any group, return just subscriberId of itself.
8066 if (groupUuid == null) {
8067 return new String[]{subscriberId};
8068 }
8069
8070 // Get all subscriberIds from the group.
8071 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008072 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8073 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8074 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008075 for (SubscriptionInfo subInfo : groupInfos) {
8076 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8077 if (subscriberId != null) {
8078 mergedSubscriberIds.add(subscriberId);
8079 }
8080 }
8081
8082 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085
8086 }
8087 }
8088
8089 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008090 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008091 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008092 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
joonhunshin4ac60942023-11-15 15:23:39 +00008094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8095 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 final Phone phone = getPhone(subId);
8100 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008104 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008105
8106 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008107 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008108 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8109 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008110 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8111 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112
8113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 final Phone phone = getPhone(subId);
8116 if (phone == null) {
8117 return false;
8118 }
8119 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8120 cdmaNonRoamingList);
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008123 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008124 }
8125
8126 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008127 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008128 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008129 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008130 if (phone == null) {
8131 return raf;
8132 }
8133
Shuo Qiandee53402020-05-29 14:08:15 -07008134 try {
8135 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008136 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008137 mApp, phone.getSubId(), "getRadioAccessFamily");
8138 } catch (SecurityException e) {
8139 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8140 throw e;
8141 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008142
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008143 if (!mApp.getResources().getBoolean(
8144 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8145 enforceTelephonyFeatureWithException(callingPackage,
8146 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8147 }
joonhunshin4ac60942023-11-15 15:23:39 +00008148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149 final long identity = Binder.clearCallingIdentity();
8150 try {
chen xub97461a2018-10-26 14:17:57 -07008151 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
chen xub97461a2018-10-26 14:17:57 -07008155 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008156 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008157
8158 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008159 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008160 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Rambo Wang7eb26962024-07-11 19:48:30 +00008161 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8162 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8163 "Invalid package:" + callingPackage);
8164 } else {
8165 try {
8166 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8167 Binder.getCallingUid())) {
8168 throw new SecurityException("Invalid package:" + callingPackage);
8169 }
8170 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008171 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008172 }
Hall Liu82694d52020-12-11 18:22:04 -08008173 }
joonhunshin4ac60942023-11-15 15:23:39 +00008174
8175 enforceTelephonyFeatureWithException(callingPackage,
8176 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8177
Hall Liu82694d52020-12-11 18:22:04 -08008178 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008179 List<String> dialerRoleHolders;
8180 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8181 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8182 UserHandle.of(ActivityManager.getCurrentUser()));
8183 } else {
8184 dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8185 }
Hall Liu82694d52020-12-11 18:22:04 -08008186 if (!dialerRoleHolders.contains(callingPackage)) {
8187 throw new SecurityException("App must be the dialer role holder to"
8188 + " upload a call composer pic");
8189 }
8190
8191 Executors.newSingleThreadExecutor().execute(() -> {
8192 ByteArrayOutputStream output = new ByteArrayOutputStream(
8193 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8194 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8195 boolean readUntilEnd = false;
8196 int totalBytesRead = 0;
8197 byte[] buffer = new byte[16 * 1024];
8198 while (true) {
8199 int numRead;
8200 try {
8201 numRead = input.read(buffer);
8202 } catch (IOException e) {
8203 try {
8204 fd.checkError();
8205 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8206 null);
8207 } catch (IOException e1) {
8208 // This means that the other side closed explicitly with an error. If this
8209 // happens, log and ignore.
8210 loge("Remote end of call composer picture pipe closed: " + e1);
8211 }
8212 break;
8213 }
8214 if (numRead == -1) {
8215 readUntilEnd = true;
8216 break;
8217 }
8218 totalBytesRead += numRead;
8219 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8220 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8221 try {
8222 input.close();
8223 } catch (IOException e) {
8224 // ignore
8225 }
8226 break;
8227 }
8228 output.write(buffer, 0, numRead);
8229 }
8230 // Generally, the remote end will close the file descriptors. The only case where we
8231 // close is above, where the picture size is too big.
8232
8233 try {
8234 fd.checkError();
8235 } catch (IOException e) {
8236 loge("Remote end for call composer closed with an error: " + e);
8237 return;
8238 }
8239
Hall Liuaa4211e2021-01-20 15:43:39 -08008240 if (!readUntilEnd) {
8241 loge("Did not finish reading entire image; aborting");
8242 return;
8243 }
Hall Liu82694d52020-12-11 18:22:04 -08008244
Hall Liuaa4211e2021-01-20 15:43:39 -08008245 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8246 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8247 new CallComposerPictureTransfer.Factory() {},
8248 imageData,
8249 (result) -> {
8250 if (result.first != null) {
8251 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8252 Bundle outputResult = new Bundle();
8253 outputResult.putParcelable(
8254 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8255 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8256 outputResult);
8257 } else {
8258 callback.send(result.second, null);
8259 }
8260 }
8261 );
Hall Liu82694d52020-12-11 18:22:04 -08008262 });
8263 }
8264
8265 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008266 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008267 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008268 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269
joonhunshin4ac60942023-11-15 15:23:39 +00008270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8271 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 final long identity = Binder.clearCallingIdentity();
8274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008275 ImsManager.getInstance(defaultPhone.getContext(),
8276 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008280 }
8281
8282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008284 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8286 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008287 return false;
8288 }
Svet Ganovb320e182015-04-16 12:30:10 -07008289
joonhunshin4ac60942023-11-15 15:23:39 +00008290 enforceTelephonyFeatureWithException(callingPackage,
8291 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 // Check the user preference and the system-level IMS setting. Even if the user has
8296 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8297 // In the long run, we may instead need to check if there exists a connection service
8298 // which can support video calling.
8299 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 return imsManager.isVtEnabledByPlatform()
8302 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8303 && imsManager.isVtEnabledByUser();
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008307 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008308
Andrew Leea1239f22015-03-02 17:44:07 -08008309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008310 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8311 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008313 mApp, subId, callingPackage, callingFeatureId,
8314 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 return false;
8316 }
8317
joonhunshin4ac60942023-11-15 15:23:39 +00008318 enforceTelephonyFeatureWithException(callingPackage,
8319 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 final long identity = Binder.clearCallingIdentity();
8322 try {
8323 CarrierConfigManager configManager =
8324 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008325 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
Andrew Leea1239f22015-03-02 17:44:07 -08008330 }
8331
8332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008333 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008335 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 return false;
8337 }
8338
joonhunshin4ac60942023-11-15 15:23:39 +00008339 enforceTelephonyFeatureWithException(callingPackage,
8340 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008342 final long identity = Binder.clearCallingIdentity();
8343 try {
8344 CarrierConfigManager configManager =
8345 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008346 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
Andrew Leea1239f22015-03-02 17:44:07 -08008351 }
8352
Andrew Lee9431b832015-03-09 18:46:45 -07008353 @Override
8354 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008355 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008356 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008357 }
8358
8359 @Override
8360 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8362 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364 final long identity = Binder.clearCallingIdentity();
8365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008366 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Andrew Lee9431b832015-03-09 18:46:45 -07008370 }
8371
Hall Liuf6668912018-10-31 17:05:23 -07008372 /**
8373 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8374 * support for the feature and device firmware support.
8375 *
8376 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8377 */
8378 @Override
8379 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8381 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008384 final Phone phone = getPhone(subscriptionId);
8385 if (phone == null) {
8386 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8387 return false;
8388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008390 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008392 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8393 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8394 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 return isCarrierSupported && isDeviceSupported;
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
Hall Liu98187582018-01-22 19:15:32 -08008399 }
8400
Hall Liuf6668912018-10-31 17:05:23 -07008401 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008402 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8403 * RTT setting, will return true if the device and carrier both support RTT.
8404 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008405 */
8406 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 final long identity = Binder.clearCallingIdentity();
8408 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008409 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8410 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8411 return false;
8412 }
8413 }
8414
Hall Liu5bab75c2019-12-11 23:58:20 +00008415 boolean isRttSupported = isRttSupported(subscriptionId);
8416 boolean isUserRttSettingOn = Settings.Secure.getInt(
8417 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8418 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8419 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8420 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008424 }
8425
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008426 @Deprecated
8427 @Override
8428 public String getDeviceId(String callingPackage) {
8429 return getDeviceIdWithFeature(callingPackage, null);
8430 }
8431
Sanket Padawe7310cc72015-01-14 09:53:20 -08008432 /**
8433 * Returns the unique device ID of phone, for example, the IMEI for
8434 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8435 *
8436 * <p>Requires Permission:
8437 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8438 */
8439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008441 try {
8442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8443 } catch (SecurityException se) {
8444 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8445 throw new SecurityException("Package " + callingPackage + " does not belong to "
8446 + Binder.getCallingUid());
8447 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008448 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008449 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008450 return null;
8451 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008452 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008453 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008454 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008455 return null;
8456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return phone.getDeviceId();
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008464 }
8465
Ping Sunc67b7c22016-03-02 19:16:45 +08008466 /**
8467 * {@hide}
8468 * Returns the IMS Registration Status on a particular subid
8469 *
8470 * @param subId
8471 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008472 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008473 Phone phone = getPhone(subId);
8474 if (phone != null) {
8475 return phone.isImsRegistered();
8476 } else {
8477 return false;
8478 }
8479 }
8480
Santos Cordon7a1885b2015-02-03 11:15:19 -08008481 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008482 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008483 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008485 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008486 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8487 }
8488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
8496 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008497 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008498 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008499 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008500 mApp,
8501 subscriptionId,
8502 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8503 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008504
8505 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8506 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8507
Tyler Gunnf70ed162019-04-03 15:28:53 -07008508 final long identity = Binder.clearCallingIdentity();
8509 try {
8510 Phone phone = getPhone(subscriptionId);
8511 if (phone == null) {
8512 return null;
8513 }
8514 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
8519
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008520 /**
8521 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008522 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008523 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 final long identity = Binder.clearCallingIdentity();
8525 try {
8526 Phone phone = getPhone(subId);
8527 if (phone != null) {
8528 return phone.isWifiCallingEnabled();
8529 } else {
8530 return false;
8531 }
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008534 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008535 }
8536
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008537 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008538 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008539 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008540 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 Phone phone = getPhone(subId);
8544 if (phone != null) {
8545 return phone.isVideoEnabled();
8546 } else {
8547 return false;
8548 }
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008551 }
8552 }
8553
8554 /**
8555 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8556 * defined in {@link ImsRegistrationImplBase}.
8557 */
8558 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 final long identity = Binder.clearCallingIdentity();
8560 try {
8561 Phone phone = getPhone(subId);
8562 if (phone != null) {
8563 return phone.getImsRegistrationTech();
8564 } else {
8565 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8566 }
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008569 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008570 }
8571
Stuart Scott8eef64f2015-04-08 15:13:54 -07008572 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008573 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008574 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008575
8576 enforceTelephonyFeatureWithException(callingPackage,
8577 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8578
Stuart Scott981d8582015-04-21 14:09:50 -07008579 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8580 return;
8581 }
Kai Shif70f46f2021-03-03 13:59:46 -08008582 Phone defaultPhone = getDefaultPhone();
8583 if (defaultPhone != null) {
8584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8585 mApp, getDefaultPhone().getSubId(), "factoryReset");
8586 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008587 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008588
Svet Ganovcc087f82015-05-12 20:35:54 -07008589 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008590 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8591 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008592 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008593 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008594 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008595 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008596 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008597 setDataRoamingEnabled(subId, phone == null ? false
8598 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008599 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008600 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008601 // There has been issues when Sms raw table somehow stores orphan
8602 // fragments. They lead to garbled message when new fragments come
8603 // in and combined with those stale ones. In case this happens again,
8604 // user can reset all network settings which will clean up this table.
8605 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008606 // Clean up IMS settings as well here.
8607 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008608 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008609 ImsManager.getInstance(mApp, slotId).factoryReset();
8610 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008611
Kai Shif70f46f2021-03-03 13:59:46 -08008612 if (defaultPhone == null) {
8613 return;
8614 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008615 // Erase modem config if erase modem on network setting is enabled.
8616 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8617 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8618 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008619 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008620 }
Kai Shif70f46f2021-03-03 13:59:46 -08008621
8622 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008623 } finally {
8624 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008625 }
8626 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008627
SongFerngWangfd89b102021-05-27 22:44:54 +08008628 @VisibleForTesting
8629 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8630 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8631 return;
8632 }
8633 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8634 RILConstants.PREFERRED_NETWORK_MODE);
8635 SubscriptionManager.setSubscriptionProperty(subId,
8636 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8637 "user=" + defaultNetworkType);
8638 phone.loadAllowedNetworksFromSubscriptionDatabase();
8639 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8640 defaultNetworkType, null);
8641 }
8642
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008643 private void cleanUpSmsRawTable(Context context) {
8644 ContentResolver resolver = context.getContentResolver();
8645 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8646 resolver.delete(uri, null, null);
8647 }
8648
Narayan Kamath1c496c22015-04-16 14:40:19 +01008649 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008650 public String getSimLocaleForSubscriber(int subId) {
8651 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008652
8653 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8654 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8655
chen xu5d3637b2019-01-21 23:31:38 -08008656 final Phone phone = getPhone(subId);
8657 if (phone == null) {
8658 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008659 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661 final long identity = Binder.clearCallingIdentity();
8662 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008663 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8664 phone.getContext().getOpPackageName(),
8665 phone.getContext().getAttributionTag());
8666 if (info == null) {
8667 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8668 return null;
chen xu6291c472019-02-04 12:55:53 -08008669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 // Try and fetch the locale from the carrier properties or from the SIM language
8671 // preferences (EF-PL and EF-LI)...
8672 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008674 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8675 if (localeFromDefaultSim != null) {
8676 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8677 if (DBG) log("Using locale from subId: " + subId + " locale: "
8678 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008679 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008680 } else {
8681 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008682 }
8683 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008685 // The SIM language preferences only store a language (e.g. fr = French), not an
8686 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8687 // the SIM and carrier preferences does not include a country we add the country
8688 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008689 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008691 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008692 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008693 }
8694
8695 if (DBG) log("No locale found - returning null");
8696 return null;
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008700 }
8701
tom hsu0b59d292022-09-29 23:49:21 +08008702 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008703 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008704 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008705 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008706 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008707 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8708 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008709 Locale.forLanguageTag(localeTag).getCountry())) {
8710 return localeTag;
8711 }
8712 }
8713 return inputLocale.toLanguageTag();
8714 }
8715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008716 /**
8717 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8718 */
8719 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008720 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008721 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008722 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008723
Gary Jian3aa9a762022-01-24 16:41:19 +08008724 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8725 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008726
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008727 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008728 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8729 * representing the state of the modem.
8730 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008731 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8732 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008733 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008734 */
8735 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008736 public void requestModemActivityInfo(ResultReceiver result) {
8737 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008738
8739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8740 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8741
vagdeviaf9a5b92018-08-15 16:01:53 -07008742 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008746 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747 } finally {
8748 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008749 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008750 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008751
Gary Jian76280a42022-12-07 16:18:33 +08008752 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008753 // less than total activity duration.
8754 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8755 if (info == null) {
8756 return false;
8757 }
8758 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008759 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008760 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8761
Hall Liu49656c02020-10-09 19:00:11 -07008762 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8763
Siddharth Rayb8114062018-06-17 15:02:38 -07008764 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008765 && (info.getSleepTimeMillis() <= activityDurationMs)
8766 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008767 }
8768
Gary Jian3aa9a762022-01-24 16:41:19 +08008769 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8770 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8771 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8772 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8773
8774 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8775 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8776 }
8777
8778 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8779 mLastModemActivityInfo.setReceiveTimeMillis(
8780 rat,
8781 freq,
8782 info.getReceiveTimeMillis(rat, freq)
8783 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8784 }
8785
8786 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8787 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8788 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8789 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8790
8791 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8792 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8793 }
8794 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8795 mLastModemActivityInfo.setReceiveTimeMillis(
8796 rat,
8797 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8798 }
8799
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008800 /**
8801 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8802 * @param info recent ModemActivityInfo
8803 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008804 private void mergeModemActivityInfo(ModemActivityInfo info) {
8805 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008806 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008807 boolean matched;
8808 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8809 matched = false;
8810 int rat = info.getSpecificInfoRat(i);
8811 int freq = info.getSpecificInfoFrequencyRange(i);
8812 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8813 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8814 //if it already exists
8815 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8816 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8817 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8818 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8819 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8820 updateLastModemActivityInfo(info, rat, freq);
8821 matched = true;
8822 }
8823 } else {
8824 updateLastModemActivityInfo(info, rat);
8825 matched = true;
8826 }
8827 }
8828 }
8829
8830 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008831 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008832 new ActivityStatsTechSpecificInfo(
8833 rat,
8834 freq,
8835 info.getTransmitTimeMillis(rat, freq),
8836 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008837 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008838 }
8839 }
8840 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8841 mLastModemActivitySpecificInfo =
8842 new ActivityStatsTechSpecificInfo[merged.size()];
8843 merged.toArray(mLastModemActivitySpecificInfo);
8844
8845 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8846 mLastModemActivityInfo.setSleepTimeMillis(
8847 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008848 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008849 mLastModemActivityInfo.setIdleTimeMillis(
8850 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008851 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008852
8853 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008854 new ModemActivityInfo(
8855 mLastModemActivityInfo.getTimestampMillis(),
8856 mLastModemActivityInfo.getSleepTimeMillis(),
8857 mLastModemActivityInfo.getIdleTimeMillis(),
8858 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008859 }
8860
8861 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8862 ActivityStatsTechSpecificInfo[] info) {
8863 int infoSize = info.length;
8864 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8865 for (int i = 0; i < infoSize; i++) {
8866 ret[i] = new ActivityStatsTechSpecificInfo(
8867 info[i].getRat(), info[i].getFrequencyRange(),
8868 info[i].getTransmitTimeMillis(),
8869 (int) info[i].getReceiveTimeMillis());
8870 }
8871 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008872 }
8873
Jack Yu85bd38a2015-11-09 11:34:32 -08008874 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008875 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008876 */
8877 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008878 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8879 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8880 Phone phone = PhoneFactory.getPhone(slotIndex);
8881 if (phone == null) {
8882 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8883 return null;
8884 }
8885
8886 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008888 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008889 return null;
8890 }
8891
joonhunshin4ac60942023-11-15 15:23:39 +00008892 enforceTelephonyFeatureWithException(callingPackage,
8893 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8894
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008895 boolean hasFinePermission = false;
8896 boolean hasCoarsePermission = false;
8897 if (!renounceFineLocationAccess) {
8898 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8899 LocationAccessPolicy.checkLocationPermission(mApp,
8900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8901 .setCallingPackage(callingPackage)
8902 .setCallingFeatureId(callingFeatureId)
8903 .setCallingPid(Binder.getCallingPid())
8904 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008905 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008906 .setLogAsInfo(true)
8907 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8908 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8910 .build());
8911 hasFinePermission =
8912 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8913 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008914
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008915 if (!renounceCoarseLocationAccess) {
8916 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8917 LocationAccessPolicy.checkLocationPermission(mApp,
8918 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8919 .setCallingPackage(callingPackage)
8920 .setCallingFeatureId(callingFeatureId)
8921 .setCallingPid(Binder.getCallingPid())
8922 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008923 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008924 .setLogAsInfo(true)
8925 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8926 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8927 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8928 .build());
8929 hasCoarsePermission =
8930 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8931 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008932
Jordan Liu0f2bc442020-11-18 16:47:37 -08008933 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008935 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8936 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008937 if (subInfo != null && !subInfo.isActive()) {
8938 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008939 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008940 }
8941
Hall Liuf19c44f2018-11-27 14:38:17 -08008942 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008943 boolean isCallingPackageDataService = phone.getDataServicePackages()
8944 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008945
8946 // Scrub out the location info in ServiceState depending on what level of access
8947 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008948 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008949 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8950 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 } finally {
8952 Binder.restoreCallingIdentity(identity);
8953 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008954 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008955
8956 /**
8957 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8958 *
8959 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8960 * voicemail ringtone.
8961 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8962 * PhoneAccount.
8963 */
8964 @Override
8965 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8967 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8972 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008973 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008976 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
8979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008980 }
8981
8982 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008983 * Sets the per-account voicemail ringtone.
8984 *
8985 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8986 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8987 *
8988 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8989 * voicemail ringtone.
8990 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8991 * PhoneAccount.
8992 */
8993 @Override
8994 public void setVoicemailRingtoneUri(String callingPackage,
8995 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008996 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008998 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8999 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9001 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9002 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009004
joonhunshin4ac60942023-11-15 15:23:39 +00009005 enforceTelephonyFeatureWithException(callingPackage,
9006 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9011 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009012 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 }
9014 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9015 } finally {
9016 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009017 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009018 }
9019
9020 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009021 * Returns whether vibration is set for voicemail notification in Phone settings.
9022 *
9023 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9024 * voicemail vibration setting.
9025 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9026 */
9027 @Override
9028 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9030 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9035 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009036 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9040 } finally {
9041 Binder.restoreCallingIdentity(identity);
9042 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009043 }
9044
Youhan Wange64578a2016-05-02 15:32:42 -07009045 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009046 * Sets the per-account voicemail vibration.
9047 *
9048 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9049 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9050 *
9051 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9052 * voicemail vibration setting.
9053 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9054 * specific PhoneAccount.
9055 */
9056 @Override
9057 public void setVoicemailVibrationEnabled(String callingPackage,
9058 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009059 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009061 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9062 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9064 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9065 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009066 }
9067
joonhunshin4ac60942023-11-15 15:23:39 +00009068 enforceTelephonyFeatureWithException(callingPackage,
9069 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071 final long identity = Binder.clearCallingIdentity();
9072 try {
9073 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9074 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009075 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 }
9077 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009080 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009081 }
9082
9083 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009084 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9085 *
9086 * @throws SecurityException if the caller does not have the required permission
9087 */
arunvoddud7401012022-12-15 16:08:12 +00009088 @VisibleForTesting
9089 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009090 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009091 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009092 }
9093
9094 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009095 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9096 * permission.
9097 *
9098 * @throws SecurityException if the caller does not have the required permission
9099 */
9100 private void enforceSendSmsPermission() {
9101 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9102 }
9103
9104 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009105 * Make sure either called from same process as self (phone) or IPC caller has interact across
9106 * users permission.
9107 *
9108 * @throws SecurityException if the caller does not have the required permission
9109 */
9110 private void enforceInteractAcrossUsersPermission(String message) {
9111 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9112 }
9113
9114 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009115 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009116 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009117 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009118 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009119 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009123 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009124 if (componentName == null) {
9125 throw new SecurityException(
9126 "Caller not current active visual voicemail package[null]");
9127 }
9128 String vvmPackage = componentName.getPackageName();
9129 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009130 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 }
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009134 }
9135 }
9136
9137 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009138 * Return the application ID for the app type.
9139 *
9140 * @param subId the subscription ID that this request applies to.
9141 * @param appType the uicc app type.
9142 * @return Application ID for specificied app type, or null if no uicc.
9143 */
9144 @Override
9145 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009146 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009147
9148 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9149 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9150
Youhan Wange64578a2016-05-02 15:32:42 -07009151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009152
9153 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009154 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155 if (phone == null) {
9156 return null;
9157 }
9158 String aid = null;
9159 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009160 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161 .getApplicationByType(appType).getAid();
9162 } catch (Exception e) {
9163 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9164 }
9165 return aid;
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009168 }
Youhan Wange64578a2016-05-02 15:32:42 -07009169 }
9170
Youhan Wang4001d252016-05-11 10:29:41 -07009171 /**
9172 * Return the Electronic Serial Number.
9173 *
9174 * @param subId the subscription ID that this request applies to.
9175 * @return ESN or null if error.
9176 */
9177 @Override
9178 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009179 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009180 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009181
9182 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009183 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009184 if (phone == null) {
9185 return null;
9186 }
9187 String esn = null;
9188 try {
9189 esn = phone.getEsn();
9190 } catch (Exception e) {
9191 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9192 }
9193 return esn;
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009196 }
Youhan Wang4001d252016-05-11 10:29:41 -07009197 }
9198
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009199 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009200 * Return the Preferred Roaming List Version.
9201 *
9202 * @param subId the subscription ID that this request applies to.
9203 * @return PRLVersion or null if error.
9204 */
9205 @Override
9206 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009207 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009208
9209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9210 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9211
Youhan Wang66ad5d72016-07-18 17:56:58 -07009212 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009213
9214 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009215 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009216 if (phone == null) {
9217 return null;
9218 }
9219 String cdmaPrlVersion = null;
9220 try {
9221 cdmaPrlVersion = phone.getCdmaPrlVersion();
9222 } catch (Exception e) {
9223 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9224 }
9225 return cdmaPrlVersion;
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009228 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009229 }
9230
9231 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009232 * Get snapshot of Telephony histograms
9233 * @return List of Telephony histograms
9234 * @hide
9235 */
9236 @Override
9237 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9239 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009240
9241 final long identity = Binder.clearCallingIdentity();
9242 try {
9243 return RIL.getTelephonyRILTimingHistograms();
9244 } finally {
9245 Binder.restoreCallingIdentity(identity);
9246 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009247 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009248
9249 /**
9250 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009251 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9252 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009253 * Require system privileges. In the future we may add this to carrier APIs.
9254 *
Michele Berionne482f8202018-11-27 18:57:59 -08009255 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009256 */
9257 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009258 @TelephonyManager.SetCarrierRestrictionResult
9259 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009260 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009261
9262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9263 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9264
vagdeviaf9a5b92018-08-15 16:01:53 -07009265 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009266
Michele Berionne482f8202018-11-27 18:57:59 -08009267 if (carrierRestrictionRules == null) {
9268 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009269 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009271 final long identity = Binder.clearCallingIdentity();
9272 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009273 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009274 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009275 } finally {
9276 Binder.restoreCallingIdentity(identity);
9277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009278 }
9279
9280 /**
9281 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009282 * Get the allowed carrier list and the excluded carrier list, including the priority between
9283 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009284 * Require system privileges. In the future we may add this to carrier APIs.
9285 *
Michele Berionne482f8202018-11-27 18:57:59 -08009286 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009287 */
9288 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009289 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009290 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009291
9292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9293 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9294
vagdeviaf9a5b92018-08-15 16:01:53 -07009295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009299 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9300 if (response instanceof CarrierRestrictionRules) {
9301 return (CarrierRestrictionRules) response;
9302 }
9303 // Response is an Exception of some kind,
9304 // which is signalled to the user as a NULL retval
9305 return null;
9306 } catch (Exception e) {
9307 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9308 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009312 }
9313
fionaxu59545b42016-05-25 15:53:37 -07009314 /**
arunvoddud7401012022-12-15 16:08:12 +00009315 * Fetches the carrier restriction status of the device and sends the status to the caller
9316 * through the callback.
9317 *
9318 * @param callback The callback that will be used to send the result.
9319 * @throws SecurityException if the caller does not have the required permission/privileges or
9320 * the caller is not allowlisted.
9321 */
9322 @Override
9323 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9324 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009325
9326 enforceTelephonyFeatureWithException(packageName,
9327 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9328
Steve Statia28b7cb32024-03-11 23:58:50 +00009329 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9330 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009331 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9332 throw new SecurityException("Not an authorized caller");
9333 }
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
9336 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009337 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009338 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9339 } finally {
9340 Binder.restoreCallingIdentity(identity);
9341 }
9342 }
9343
arunvoddu567f2b42023-04-25 17:22:00 +00009344 @Override
9345 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9346 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9347 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9348 return allowListInfo.getShaIdList(pkgName, carrierId);
9349 }
9350
arunvoddud7401012022-12-15 16:08:12 +00009351 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009352 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009353 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009354 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009355 }
9356
9357 /**
fionaxu59545b42016-05-25 15:53:37 -07009358 * Action set from carrier signalling broadcast receivers to enable/disable radio
9359 * @param subId the subscription ID that this action applies to.
9360 * @param enabled control enable or disable radio.
9361 * {@hide}
9362 */
9363 @Override
9364 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9365 enforceModifyPermission();
9366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009367
9368 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009369 if (phone == null) {
9370 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9371 return;
9372 }
9373 try {
9374 phone.carrierActionSetRadioEnabled(enabled);
9375 } catch (Exception e) {
9376 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009377 } finally {
9378 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009379 }
9380 }
9381
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009382 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009383 * Enable or disable Voice over NR (VoNR)
9384 * @param subId the subscription ID that this action applies to.
9385 * @param enabled enable or disable VoNR.
9386 * @return operation result.
9387 */
9388 @Override
9389 public int setVoNrEnabled(int subId, boolean enabled) {
9390 enforceModifyPermission();
9391 final Phone phone = getPhone(subId);
9392
9393 final long identity = Binder.clearCallingIdentity();
9394 if (phone == null) {
9395 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9396 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9397 }
9398
9399 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9400 try {
9401 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9402 workSource);
9403 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009404
9405 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9406 if (DBG) {
9407 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9408 }
9409 SubscriptionManager.setSubscriptionProperty(
9410 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9411 (enabled ? "1" : "0"));
9412 }
9413
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009414 return result;
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
9420 /**
9421 * Is voice over NR enabled
9422 * @return true if VoNR is enabled else false
9423 */
9424 @Override
9425 public boolean isVoNrEnabled(int subId) {
9426 enforceReadPrivilegedPermission("isVoNrEnabled");
9427 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
9430 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9431 null, subId, workSource);
9432 if (DBG) log("isVoNrEnabled: " + isEnabled);
9433 return isEnabled;
9434 } finally {
9435 Binder.restoreCallingIdentity(identity);
9436 }
9437 }
9438
9439 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009440 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9441 * network status based on which carrier apps could apply actions accordingly,
9442 * enable/disable default url handler for example.
9443 *
9444 * @param subId the subscription ID that this action applies to.
9445 * @param report control start/stop reporting the default network status.
9446 * {@hide}
9447 */
9448 @Override
9449 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9450 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009451
9452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9453 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9454 "carrierActionReportDefaultNetworkStatus");
9455
fionaxu8da9cb12017-05-23 15:02:46 -07009456 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009457
9458 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009459 if (phone == null) {
9460 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9461 return;
9462 }
9463 try {
9464 phone.carrierActionReportDefaultNetworkStatus(report);
9465 } catch (Exception e) {
9466 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009467 } finally {
9468 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009469 }
9470 }
9471
9472 /**
fionaxud9622282017-07-17 17:51:30 -07009473 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9474 * @param subId the subscription ID that this action applies to.
9475 * {@hide}
9476 */
9477 @Override
9478 public void carrierActionResetAll(int subId) {
9479 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009480
9481 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9482 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9483
fionaxud9622282017-07-17 17:51:30 -07009484 final Phone phone = getPhone(subId);
9485 if (phone == null) {
9486 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9487 return;
9488 }
9489 try {
9490 phone.carrierActionResetAll();
9491 } catch (Exception e) {
9492 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9493 }
9494 }
9495
9496 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009497 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9498 * bug report is being generated.
9499 */
9500 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009501 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009502 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9503 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009504 writer.println("Permission Denial: can't dump Phone from pid="
9505 + Binder.getCallingPid()
9506 + ", uid=" + Binder.getCallingUid()
9507 + "without permission "
9508 + android.Manifest.permission.DUMP);
9509 return;
9510 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009511 try {
9512 DumpsysHandler.dump(mApp, fd, writer, args);
9513 } catch (Exception e) {
9514 writer.println("Failed to dump phone information: " + e);
9515 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009516 }
Jack Yueb89b242016-06-22 13:27:47 -07009517
Brad Ebingerdac2f002018-04-03 15:17:52 -07009518 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009519 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9520 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9521 @NonNull String[] args) {
9522 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9523 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009524 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009525 }
9526
Jack Yueb89b242016-06-22 13:27:47 -07009527 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009528 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009529 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009530 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009531 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009532 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009533 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009534 */
9535 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009536 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009537 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009538 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9539 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9540 try {
9541 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009542 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009543 } catch (SecurityException se) {
9544 enforceModifyPermission();
9545 }
9546 } else {
9547 enforceModifyPermission();
9548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009549
joonhunshin4ac60942023-11-15 15:23:39 +00009550 enforceTelephonyFeatureWithException(callingPackage,
9551 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9552
Nate Myren116695d2024-02-09 09:36:01 -08009553 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009554 final long identity = Binder.clearCallingIdentity();
9555 try {
Nate Myren116695d2024-02-09 09:36:01 -08009556 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9557 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009558 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009559 callingUid, callingPackage, null, null);
9560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009561 Phone phone = getPhone(subId);
9562 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009563 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9564 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009565 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009566 phone.getDataSettingsManager().setDataEnabled(
9567 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009569 }
9570 } finally {
9571 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009572 }
9573 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009574
9575 /**
9576 * Get Client request stats
9577 * @return List of Client Request Stats
9578 * @hide
9579 */
9580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009581 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9582 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009584 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009585 return null;
9586 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009587 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009589 final long identity = Binder.clearCallingIdentity();
9590 try {
9591 if (phone != null) {
9592 return phone.getClientRequestStats();
9593 }
9594
9595 return null;
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
9598 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009599 }
9600
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009601 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009602 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009603 if (uid == Process.ROOT_UID && packageName == null) {
9604 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9605 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9606 // exception. ROOT_UID seems not to have a valid package name returned by
9607 // PackageManager, so just fake it here to avoid issues when running telephony shell
9608 // commands that plumb through the RIL as root, like so:
9609 // $ adb root
9610 // $ adb shell cmd phone ...
9611 packageName = "root";
9612 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009613 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009614 }
Jack Yueb4124c2017-02-16 15:32:43 -08009615
9616 /**
Grace Chen70990072017-03-24 17:21:30 -07009617 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009618 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009619 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009620 * @param state State of SIM (power down, power up, pass through)
9621 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9622 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9623 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009624 *
9625 **/
9626 @Override
Grace Chen70990072017-03-24 17:21:30 -07009627 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009628 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009629
9630 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9631 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9632
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009633 Phone phone = PhoneFactory.getPhone(slotIndex);
9634
vagdeviaf9a5b92018-08-15 16:01:53 -07009635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009637 final long identity = Binder.clearCallingIdentity();
9638 try {
9639 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009640 phone.setSimPowerState(state, null, workSource);
9641 }
9642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
9646
9647 /**
9648 * Set SIM card power state.
9649 *
9650 * @param slotIndex SIM slot id.
9651 * @param state State of SIM (power down, power up, pass through)
9652 * @param callback callback to trigger after success or failure
9653 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9654 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9655 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9656 *
9657 **/
9658 @Override
9659 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9660 IIntegerConsumer callback) {
9661 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009662
9663 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9664 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9665 "setSimPowerStateForSlotWithCallback");
9666
Jordan Liu109698e2020-11-24 14:50:34 -08009667 Phone phone = PhoneFactory.getPhone(slotIndex);
9668
9669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9670
9671 final long identity = Binder.clearCallingIdentity();
9672 try {
9673 if (phone != null) {
9674 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9675 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009676 }
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009679 }
9680 }
Shuo Qiandd210312017-04-12 22:11:33 +00009681
Tyler Gunn65d45c22017-06-05 11:22:26 -07009682 private boolean isUssdApiAllowed(int subId) {
9683 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009684 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009685 if (configManager == null) {
9686 return false;
9687 }
9688 PersistableBundle pb = configManager.getConfigForSubId(subId);
9689 if (pb == null) {
9690 return false;
9691 }
9692 return pb.getBoolean(
9693 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9694 }
9695
Shuo Qiandd210312017-04-12 22:11:33 +00009696 /**
Ling Mac28f0212023-03-24 16:07:15 -07009697 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009698 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009699 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009700 */
goneil9c5f4872017-12-05 14:07:56 -08009701 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009702 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009703 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009704
9705 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9706 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009708 final long identity = Binder.clearCallingIdentity();
9709 try {
Ling Mac28f0212023-03-24 16:07:15 -07009710 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009711 } finally {
9712 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009713 }
9714 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009715
9716 /**
9717 * Get the current signal strength information for the given subscription.
9718 * Because this information is not updated when the device is in a low power state
9719 * it should not be relied-upon to be current.
9720 * @param subId Subscription index
9721 * @return the most recent cached signal strength info from the modem
9722 */
9723 @Override
9724 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009725 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9726 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009728 final long identity = Binder.clearCallingIdentity();
9729 try {
9730 Phone p = getPhone(subId);
9731 if (p == null) {
9732 return null;
9733 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009735 return p.getSignalStrength();
9736 } finally {
9737 Binder.restoreCallingIdentity(identity);
9738 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009739 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009740
Pengquan Meng77b7f132018-08-22 14:49:57 -07009741 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009742 * Get the current modem radio state for the given slot.
9743 * @param slotIndex slot index.
9744 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009745 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009746 * @return the current radio power state from the modem
9747 */
9748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009749 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009750 Phone phone = PhoneFactory.getPhone(slotIndex);
9751 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9753 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009754 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9755 }
9756
joonhunshin4ac60942023-11-15 15:23:39 +00009757 enforceTelephonyFeatureWithException(callingPackage,
9758 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9759
Chen Xuf792fd62018-10-17 17:54:36 +00009760 final long identity = Binder.clearCallingIdentity();
9761 try {
9762 return phone.getRadioPowerState();
9763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9768 }
9769
9770 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009771 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9772 *
9773 * <p>Requires one of the following permissions:
9774 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009775 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009776 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9777 * privileges.
9778 *
9779 * @param subId subscription id
9780 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9781 * {@code false}.
9782 */
9783 @Override
9784 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009785 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009786 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009787 try {
9788 mApp.enforceCallingOrSelfPermission(
9789 android.Manifest.permission.ACCESS_NETWORK_STATE,
9790 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009791 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009792 mApp.enforceCallingOrSelfPermission(
9793 permission.READ_BASIC_PHONE_STATE, functionName);
9794 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009795 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009796 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009797 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009798 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009799
joonhunshin4ac60942023-11-15 15:23:39 +00009800 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9801 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9802
Pengquan Menga1bb6272018-09-06 09:59:22 -07009803 boolean isEnabled = false;
9804 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009805 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009806 Phone phone = getPhone(subId);
9807 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009808 } finally {
9809 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009810 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009811 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009812 }
9813
9814
9815 /**
9816 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9817 *
9818 * <p> Requires permission:
9819 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9820 * privileges.
9821 *
9822 * @param subId subscription id
9823 * @param isEnabled {@code true} means enable, {@code false} means disable.
9824 */
9825 @Override
9826 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9828 mApp, subId, "setDataRoamingEnabled");
9829
joonhunshin4ac60942023-11-15 15:23:39 +00009830 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9831 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9832
Pengquan Menga1bb6272018-09-06 09:59:22 -07009833 final long identity = Binder.clearCallingIdentity();
9834 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009835 Phone phone = getPhone(subId);
9836 if (phone != null) {
9837 phone.setDataRoamingEnabled(isEnabled);
9838 }
9839 } finally {
9840 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009841 }
9842 }
9843
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009844 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009845 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009846 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009847 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009848 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009849
joonhunshin4ac60942023-11-15 15:23:39 +00009850 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9851 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9852
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009853 boolean isAllowed = true;
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009856 Phone phone = getPhone(subId);
9857 if (phone != null) {
9858 isAllowed = phone.isCspPlmnEnabled();
9859 }
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 return isAllowed;
9864 }
9865
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009866 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9867 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009868 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009869 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009870 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009871 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9872 if (phone == null) {
9873 return false;
9874 }
9875 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9876 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9877 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009878 }
9879
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009880 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009881 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009882 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009883 mApp.getSystemService(AppOpsManager.class)
9884 .checkPackage(Binder.getCallingUid(), callingPackage);
9885
Jordan Liu1e142fc2019-04-22 15:10:43 -07009886 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009887 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009888 try {
9889 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009890 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009891 } catch (SecurityException e) {
9892 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9893 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009894 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009895 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009896 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009897 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009898 }
joonhunshin4ac60942023-11-15 15:23:39 +00009899
9900 enforceTelephonyFeatureWithException(callingPackage,
9901 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9902
sandeepjsb6c87872021-09-27 15:34:44 +00009903 // checking compatibility, if calling app's target SDK is T and beyond.
9904 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9905 Binder.getCallingUid())) {
9906 isIccIdAccessRestricted = true;
9907 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009908 final long identity = Binder.clearCallingIdentity();
9909 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009910 UiccController uiccController = UiccController.getInstance();
9911 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009912 if (hasReadPermission) {
9913 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009914 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009915
9916 // Remove private info if the caller doesn't have access
9917 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9918 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009919 //setting the value after compatibility check
9920 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009921 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9922 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009923 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009924 if (card == null) {
9925 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009926 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009927 continue;
9928 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009929 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9930 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009931 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009932 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009933 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009934 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9935 for (UiccPortInfo portInfo : portInfos) {
9936 UiccPort port = uiccController.getUiccPortForSlot(
9937 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9938 if (port == null) {
9939 // assume no access if port is null
9940 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9941 continue;
9942 }
9943 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9944 uiccPortInfos.add(portInfo);
9945 } else {
9946 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9947 }
9948 }
9949 filteredInfos.add(new UiccCardInfo(
9950 cardInfo.isEuicc(),
9951 cardInfo.getCardId(),
9952 null,
9953 cardInfo.getPhysicalSlotIndex(),
9954 cardInfo.isRemovable(),
9955 cardInfo.isMultipleEnabledProfilesSupported(),
9956 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009957 }
9958 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
sandeepjsb6c87872021-09-27 15:34:44 +00009964 /**
9965 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9966 * generally private and require carrier privileges to view.
9967 *
9968 * @hide
9969 */
9970 @NonNull
9971 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9972 List<UiccPortInfo> portinfo = new ArrayList<>();
9973 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9974 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9975 }
9976 return new UiccCardInfo(
9977 cardInfo.isEuicc(),
9978 cardInfo.getCardId(),
9979 null,
9980 cardInfo.getPhysicalSlotIndex(),
9981 cardInfo.isRemovable(),
9982 cardInfo.isMultipleEnabledProfilesSupported(),
9983 portinfo
9984 );
9985 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009986
sandeepjsb6c87872021-09-27 15:34:44 +00009987 /**
9988 * @hide
9989 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9990 * These values are generally private and require carrier privileges to view.
9991 */
9992 @NonNull
9993 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9994 return new UiccPortInfo(
9995 UiccPortInfo.ICCID_REDACTED,
9996 portInfo.getPortIndex(),
9997 portInfo.getLogicalSlotIndex(),
9998 portInfo.isActive()
9999 );
10000 }
10001 @Override
10002 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010003 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010004 mApp.getSystemService(AppOpsManager.class)
10005 .checkPackage(Binder.getCallingUid(), callingPackage);
10006
sandeepjsb6c87872021-09-27 15:34:44 +000010007 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010008
Aman Guptaf3c90b32022-03-17 04:54:16 +000010009 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10010 // we are reading iccId which is PII data.
10011 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010012
joonhunshin4ac60942023-11-15 15:23:39 +000010013 enforceTelephonyFeatureWithException(callingPackage,
10014 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10015
sandeepjsb6c87872021-09-27 15:34:44 +000010016 // checking compatibility, if calling app's target SDK is T and beyond.
10017 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10018 Binder.getCallingUid())) {
10019 isLogicalSlotAccessRestricted = true;
10020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010021 final long identity = Binder.clearCallingIdentity();
10022 try {
10023 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010024 if (slots == null || slots.length == 0) {
10025 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010026 return null;
10027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010028 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10029 for (int i = 0; i < slots.length; i++) {
10030 UiccSlot slot = slots[i];
10031 if (slot == null) {
10032 continue;
10033 }
10034
Jordan Liu7be7e652019-05-06 18:55:02 +000010035 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036 UiccCard card = slot.getUiccCard();
10037 if (card != null) {
10038 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010039 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010040 cardId = slot.getEid();
10041 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010042 // If cardId is null, use iccId of default port as cardId.
10043 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010045 }
10046
Jordan Liu857451f2019-05-09 16:35:35 -070010047 if (cardId != null) {
10048 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10049 // if cardId is an EID, it's all digits so this is fine
10050 cardId = IccUtils.stripTrailingFs(cardId);
10051 }
10052
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010053 int cardState = 0;
10054 switch (slot.getCardState()) {
10055 case CARDSTATE_ABSENT:
10056 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10057 break;
10058 case CARDSTATE_PRESENT:
10059 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10060 break;
10061 case CARDSTATE_ERROR:
10062 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10063 break;
10064 case CARDSTATE_RESTRICTED:
10065 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10066 break;
10067 default:
10068 break;
10069
10070 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010071 List<UiccPortInfo> portInfos = new ArrayList<>();
10072 int[] portIndexes = slot.getPortList();
10073 for (int portIdx : portIndexes) {
10074 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010075 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010076 portInfos.add(new UiccPortInfo(iccId, portIdx,
10077 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010079 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010080 slot.isEuicc(),
10081 cardId,
10082 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010083 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010084 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010085 //setting the value after compatibility check
10086 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010087 }
10088 return infos;
10089 } finally {
10090 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010091 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010092 }
10093
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010094 /* Returns null if doesn't have read permission or carrier privilege access. */
10095 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10096 boolean hasReadPermission) {
10097 String iccId = slot.getIccId(portIndex);
10098 if (hasReadPermission) { // if has read permission
10099 return iccId;
10100 } else {
10101 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10102 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10103 // if no read permission, checking carrier privilege access
10104 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10105 return iccId;
10106 }
10107 }
10108 }
10109 // No read permission or carrier privilege access.
10110 return UiccPortInfo.ICCID_REDACTED;
10111 }
10112
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010113 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010114 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010115 public boolean switchSlots(int[] physicalSlots) {
10116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010117
joonhunshin4ac60942023-11-15 15:23:39 +000010118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10119 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10120
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010121 final long identity = Binder.clearCallingIdentity();
10122 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010123 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10124 for (int i = 0; i < physicalSlots.length; i++) {
10125 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10126 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10127 physicalSlots[i], i));
10128 }
10129 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010130 } finally {
10131 Binder.restoreCallingIdentity(identity);
10132 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010133 }
Jack Yu4c988042018-02-27 15:30:01 -080010134
10135 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010136 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10137 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10138 enforceModifyPermission();
10139
joonhunshin4ac60942023-11-15 15:23:39 +000010140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10141 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10142
sandeepjsb6c87872021-09-27 15:34:44 +000010143 final long identity = Binder.clearCallingIdentity();
10144 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010145 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010146 } finally {
10147 Binder.restoreCallingIdentity(identity);
10148 }
10149 }
10150
10151 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010152 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010153 enforceTelephonyFeatureWithException(callingPackage,
10154 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10155
Jordan Liu7de49fa2018-12-06 14:48:49 -080010156 final long identity = Binder.clearCallingIdentity();
10157 try {
10158 return UiccController.getInstance().getCardIdForDefaultEuicc();
10159 } finally {
10160 Binder.restoreCallingIdentity(identity);
10161 }
10162 }
10163
Pengquan Meng85728fb2018-03-12 16:31:21 -070010164 /**
goneil47ffb6e2018-04-06 15:40:58 -070010165 * A test API to reload the UICC profile.
10166 *
10167 * <p>Requires that the calling app has permission
10168 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10169 * @hide
10170 */
10171 @Override
10172 public void refreshUiccProfile(int subId) {
10173 enforceModifyPermission();
10174
10175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 Phone phone = getPhone(subId);
10178 if (phone == null) {
10179 return;
10180 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010181 UiccPort uiccPort = phone.getUiccPort();
10182 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010183 return;
10184 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010185 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010186 if (uiccProfile == null) {
10187 return;
10188 }
10189 uiccProfile.refresh();
10190 } finally {
10191 Binder.restoreCallingIdentity(identity);
10192 }
10193 }
10194
10195 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010196 * Returns false if the mobile data is disabled by default, otherwise return true.
10197 */
10198 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010199 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010200 }
10201
10202 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010203 * Returns the default network type for the given {@code subId}, if the default network type is
10204 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10205 */
10206 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010207 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010208 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010209 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10210 return list.get(phoneId);
10211 }
10212 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010213 }
fionaxua13278b2018-03-21 00:08:13 -070010214
10215 @Override
10216 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010217 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010219
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 final Phone phone = getPhone(subId);
10223 if (phone == null) {
10224 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10225 return;
10226 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010227 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10228 if (cpt != null) {
10229 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10230 }
10231 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010232 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10233 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010234 if (carrierPrivilegeRules == null) {
10235 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10236 } else {
10237 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010239 } finally {
10240 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010241 }
fionaxua13278b2018-03-21 00:08:13 -070010242 }
10243
10244 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010245 public void setCarrierServicePackageOverride(
10246 int subId, String carrierServicePackage, String callingPackage) {
10247 TelephonyPermissions.enforceShellOnly(
10248 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10249
Benedict Wong66477622023-02-03 23:30:57 +000010250 final long identity = Binder.clearCallingIdentity();
10251 try {
10252 final Phone phone = getPhone(subId);
10253 if (phone == null || phone.getSubId() != subId) {
10254 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10255 throw new IllegalArgumentException("No phone for subid");
10256 }
10257 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10258 if (cpt == null) {
10259 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10260 throw new IllegalStateException("No CPT for phone");
10261 }
10262 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
10268 @Override
fionaxua13278b2018-03-21 00:08:13 -070010269 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010270 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010271
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 final Phone phone = getPhone(subId);
10275 if (phone == null) {
10276 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10277 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10278 }
10279 return phone.getCarrierIdListVersion();
10280 } finally {
10281 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010282 }
fionaxua13278b2018-03-21 00:08:13 -070010283 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010284
10285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010286 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10287 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010289 mApp, subId, callingPackage, callingFeatureId,
10290 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010291 return -1;
10292 }
10293
10294 final long identity = Binder.clearCallingIdentity();
10295 try {
10296 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
10300 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010301
10302 @Override
10303 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010304 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010305 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010306 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010307
joonhunshin4ac60942023-11-15 15:23:39 +000010308 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10309 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10310
Pengquan Menga1bb6272018-09-06 09:59:22 -070010311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
10318
10319 @Override
10320 public boolean setCdmaRoamingMode(int subId, int mode) {
10321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10322 mApp, subId, "setCdmaRoamingMode");
10323
joonhunshin4ac60942023-11-15 15:23:39 +000010324 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10325 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10326
Pengquan Menga1bb6272018-09-06 09:59:22 -070010327 final long identity = Binder.clearCallingIdentity();
10328 try {
10329 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10330 } finally {
10331 Binder.restoreCallingIdentity(identity);
10332 }
10333 }
10334
10335 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010336 public int getCdmaSubscriptionMode(int subId) {
10337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010339 mApp, subId, "getCdmaSubscriptionMode");
10340
joonhunshin4ac60942023-11-15 15:23:39 +000010341 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10342 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10343
Sarah Chinbaab1432020-10-28 13:46:24 -070010344 final long identity = Binder.clearCallingIdentity();
10345 try {
10346 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350 }
10351
10352 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010353 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10355 mApp, subId, "setCdmaSubscriptionMode");
10356
joonhunshin4ac60942023-11-15 15:23:39 +000010357 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10358 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10359
Pengquan Menga1bb6272018-09-06 09:59:22 -070010360 final long identity = Binder.clearCallingIdentity();
10361 try {
10362 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10363 } finally {
10364 Binder.restoreCallingIdentity(identity);
10365 }
10366 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010367
sqianc5eccab2018-10-19 18:46:41 -070010368 @Override
sqian8c685422019-02-22 15:55:18 -080010369 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010370 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010372 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10373 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010374 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10375 }
joonhunshin4ac60942023-11-15 15:23:39 +000010376
10377 enforceTelephonyFeatureWithException(callingPackage,
10378 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10379
sqian11b7a0e2018-12-05 18:48:28 -080010380 final long identity = Binder.clearCallingIdentity();
10381 try {
sqian854d44b2018-12-12 16:48:18 -080010382 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10383 for (Phone phone: PhoneFactory.getPhones()) {
10384 if (phone.getEmergencyNumberTracker() != null
10385 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10386 emergencyNumberListInternal.put(
10387 phone.getSubId(),
10388 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10389 }
sqian11b7a0e2018-12-05 18:48:28 -080010390 }
sqian854d44b2018-12-12 16:48:18 -080010391 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010392 } finally {
10393 Binder.restoreCallingIdentity(identity);
10394 }
sqianc5eccab2018-10-19 18:46:41 -070010395 }
10396
10397 @Override
sqian8c685422019-02-22 15:55:18 -080010398 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010399 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010400 if (!exactMatch) {
10401 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010402 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010403 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010404 }
joonhunshin4ac60942023-11-15 15:23:39 +000010405
10406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10407 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10408
sqian11b7a0e2018-12-05 18:48:28 -080010409 final long identity = Binder.clearCallingIdentity();
10410 try {
sqian854d44b2018-12-12 16:48:18 -080010411 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010412 //Note: we ignore passed in param exactMatch. We can remove it once
10413 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010414 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010415 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010416 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010417 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010418 }
sqian11b7a0e2018-12-05 18:48:28 -080010419 }
10420 return false;
10421 } finally {
10422 Binder.restoreCallingIdentity(identity);
10423 }
10424 }
10425
sqianf4ca7ed2019-01-15 18:32:07 -080010426 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010427 * Start emergency callback mode for GsmCdmaPhone for testing.
10428 */
10429 @Override
10430 public void startEmergencyCallbackMode() {
10431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10432 "startEmergencyCallbackMode");
10433 enforceModifyPermission();
10434 final long identity = Binder.clearCallingIdentity();
10435 try {
10436 for (Phone phone : PhoneFactory.getPhones()) {
10437 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10438 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10439 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10440 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10441 gsmCdmaPhone.obtainMessage(
10442 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10443 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10444 }
10445 }
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
10450
10451 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010452 * Update emergency number list for test mode.
10453 */
10454 @Override
10455 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10457 "updateEmergencyNumberListTestMode");
10458
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 for (Phone phone: PhoneFactory.getPhones()) {
10462 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10463 if (tracker != null) {
10464 tracker.executeEmergencyNumberTestModeCommand(action, num);
10465 }
10466 }
10467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
10471
10472 /**
10473 * Get the full emergency number list for test mode.
10474 */
10475 @Override
10476 public List<String> getEmergencyNumberListTestMode() {
10477 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10478 "getEmergencyNumberListTestMode");
10479
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
10482 Set<String> emergencyNumbers = new HashSet<>();
10483 for (Phone phone: PhoneFactory.getPhones()) {
10484 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10485 if (tracker != null) {
10486 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10487 emergencyNumbers.add(num.getNumber());
10488 }
10489 }
10490 }
10491 return new ArrayList<>(emergencyNumbers);
10492 } finally {
10493 Binder.restoreCallingIdentity(identity);
10494 }
10495 }
10496
chen xud6b45bd2018-10-30 22:27:10 -070010497 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010498 public int getEmergencyNumberDbVersion(int subId) {
10499 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10500
joonhunshin4ac60942023-11-15 15:23:39 +000010501 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10502 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10503
Shuo Qian3b6ee772019-11-13 17:43:31 -080010504 final long identity = Binder.clearCallingIdentity();
10505 try {
10506 final Phone phone = getPhone(subId);
10507 if (phone == null) {
10508 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10509 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10510 }
10511 return phone.getEmergencyNumberDbVersion();
10512 } finally {
10513 Binder.restoreCallingIdentity(identity);
10514 }
10515 }
10516
10517 @Override
10518 public void notifyOtaEmergencyNumberDbInstalled() {
10519 enforceModifyPermission();
10520
joonhunshin4ac60942023-11-15 15:23:39 +000010521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10522 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10523
Shuo Qian3b6ee772019-11-13 17:43:31 -080010524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 for (Phone phone: PhoneFactory.getPhones()) {
10527 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10528 if (tracker != null) {
10529 tracker.updateOtaEmergencyNumberDatabase();
10530 }
10531 }
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010538 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010539 enforceActiveEmergencySessionPermission();
10540
joonhunshin4ac60942023-11-15 15:23:39 +000010541 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10542 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10543
Shuo Qian3b6ee772019-11-13 17:43:31 -080010544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 for (Phone phone: PhoneFactory.getPhones()) {
10547 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10548 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010549 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10550 }
10551 }
10552 } finally {
10553 Binder.restoreCallingIdentity(identity);
10554 }
10555 }
10556
10557 @Override
10558 public void resetOtaEmergencyNumberDbFilePath() {
10559 enforceActiveEmergencySessionPermission();
10560
joonhunshin4ac60942023-11-15 15:23:39 +000010561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10562 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10563
Shuo Qianc373f112020-03-05 17:55:34 -080010564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 for (Phone phone: PhoneFactory.getPhones()) {
10567 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10568 if (tracker != null) {
10569 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010570 }
10571 }
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
10577 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010578 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10579 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10580 Phone phone = getPhone(subId);
10581 if (phone == null) {
10582 return null;
10583 }
10584 final long identity = Binder.clearCallingIdentity();
10585 try {
10586 UiccProfile profile = UiccController.getInstance()
10587 .getUiccProfileForPhone(phone.getPhoneId());
10588 if (profile != null) {
10589 return profile.getCertsFromCarrierPrivilegeAccessRules();
10590 }
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 return null;
10595 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010596
10597 /**
10598 * Enable or disable a modem stack.
10599 */
10600 @Override
10601 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10602 enforceModifyPermission();
10603
joonhunshin4ac60942023-11-15 15:23:39 +000010604 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10605 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10606
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 Phone phone = PhoneFactory.getPhone(slotIndex);
10610 if (phone == null) {
10611 return false;
10612 } else {
10613 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10614 }
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
Michelecea4cf22018-12-21 15:00:11 -080010619
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010620 /**
10621 * Whether a modem stack is enabled or not.
10622 */
10623 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010624 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10625 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010626 Phone phone = PhoneFactory.getPhone(slotIndex);
10627 if (phone == null) return false;
10628
10629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010630 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10631 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010632 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10633 }
10634
joonhunshin4ac60942023-11-15 15:23:39 +000010635 enforceTelephonyFeatureWithException(callingPackage,
10636 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10637
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010638 final long identity = Binder.clearCallingIdentity();
10639 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010640 try {
10641 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10642 } catch (NoSuchElementException ex) {
10643 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10644 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
Michelecea4cf22018-12-21 15:00:11 -080010650 @Override
Michele0ea7d782019-03-19 14:58:42 -070010651 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010652 enforceModifyPermission();
10653
joonhunshin4ac60942023-11-15 15:23:39 +000010654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10655 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10656
Michelecea4cf22018-12-21 15:00:11 -080010657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010660 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010661 .commit();
10662 } finally {
10663 Binder.restoreCallingIdentity(identity);
10664 }
10665 }
10666
10667 @Override
Michele0ea7d782019-03-19 14:58:42 -070010668 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010669 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010671 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10672 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010673 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010674 }
Michelecea4cf22018-12-21 15:00:11 -080010675
joonhunshin4ac60942023-11-15 15:23:39 +000010676 enforceTelephonyFeatureWithException(callingPackage,
10677 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10678
Michelecea4cf22018-12-21 15:00:11 -080010679 final long identity = Binder.clearCallingIdentity();
10680 try {
Michele0ea7d782019-03-19 14:58:42 -070010681 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010682 } finally {
10683 Binder.restoreCallingIdentity(identity);
10684 }
10685 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010686
Michele0ea7d782019-03-19 14:58:42 -070010687 @TelephonyManager.IsMultiSimSupportedResult
10688 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010689 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10690 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10691 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010692 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10693 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010694 }
10695 // Check if the hardware supports multisim functionality. If usage of multisim is not
10696 // supported by the modem, indicate that it is restricted.
10697 PhoneCapability staticCapability =
10698 mPhoneConfigurationManager.getStaticPhoneCapability();
10699 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010700 loge("isMultiSimSupportedInternal: no static configuration available");
10701 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010702 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010703 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010704 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10705 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010706 }
10707 // Check if support of multiple SIMs is restricted by carrier
10708 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010709 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010710 }
10711
Michele0ea7d782019-03-19 14:58:42 -070010712 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010713 }
10714
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010715 /**
10716 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010717 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10718 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10719 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010720 * @param numOfSims number of active sims we want to switch to
10721 */
10722 @Override
10723 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010724 if (numOfSims == 1) {
10725 enforceModifyPermission();
10726 } else {
10727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10728 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10729 }
joonhunshin4ac60942023-11-15 15:23:39 +000010730
10731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10732 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10733
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010734 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010735
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010736 try {
Michele30b57b22019-03-01 12:01:14 -080010737 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010738 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010739 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10740 return;
10741 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010742 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746 }
10747
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010748 @Override
10749 public boolean isApplicationOnUicc(int subId, int appType) {
10750 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010751
10752 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10753 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10754
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010755 Phone phone = getPhone(subId);
10756 if (phone == null) {
10757 return false;
10758 }
10759 final long identity = Binder.clearCallingIdentity();
10760 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010761 UiccPort uiccPort = phone.getUiccPort();
10762 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010763 return false;
10764 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010765 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010766 if (uiccProfile == null) {
10767 return false;
10768 }
10769 if (TelephonyManager.APPTYPE_SIM <= appType
10770 && appType <= TelephonyManager.APPTYPE_ISIM) {
10771 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10772 }
10773 return false;
10774 } finally {
10775 Binder.restoreCallingIdentity(identity);
10776 }
10777 }
10778
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010779 /**
chen xub4baa772019-04-03 10:23:41 -070010780 * Get whether making changes to modem configurations will trigger reboot.
10781 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010782 */
10783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010784 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10785 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010787 mApp, subId, callingPackage, callingFeatureId,
10788 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010789 return false;
10790 }
joonhunshin4ac60942023-11-15 15:23:39 +000010791
10792 enforceTelephonyFeatureWithException(callingPackage,
10793 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10794 "doesSwitchMultiSimConfigTriggerReboot");
10795
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010796 final long identity = Binder.clearCallingIdentity();
10797 try {
10798 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
Nathan Harold29f5f052019-02-15 13:41:57 -080010804 private void updateModemStateMetrics() {
10805 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10806 // TODO: check the state for each modem if the api is ready.
10807 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10808 }
10809
Pengquan Meng3889a572019-01-23 11:16:29 -080010810 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010811 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010812 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010813 // Verify that the callingPackage belongs to the calling UID
10814 mApp.getSystemService(AppOpsManager.class)
10815 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010816
10817 enforceTelephonyFeatureWithException(callingPackage,
10818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10819
Pengquan Meng3889a572019-01-23 11:16:29 -080010820 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010821 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010822 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010823 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10824 if (slotInfos != null) {
10825 for (int i = 0; i < slotInfos.length; i++) {
10826 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10827 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10828 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10829 portInfo.getLogicalSlotIndex()));
10830 }
10831 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010832 }
10833 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010834 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010835 } finally {
10836 Binder.restoreCallingIdentity(identity);
10837 }
10838 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010839
10840 /**
10841 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010842 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010843 */
jimsunf9ec1622022-09-13 21:18:43 +080010844 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010845 @Override
10846 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010847 return getHalVersion(HAL_SERVICE_RADIO);
10848 }
10849
10850 /**
10851 * Get the HAL Version of a specific service
10852 */
10853 @Override
10854 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010855 Phone phone = getDefaultPhone();
10856 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010857 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010858 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10859 return hv.major * 100 + hv.minor;
10860 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010861
10862 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010863 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010864 *
10865 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010866 */
10867 @Override
sangyun097dcf72024-01-04 10:35:49 +090010868 public @Nullable String getCurrentPackageName() {
10869 PackageManager pm = mApp.getPackageManager();
10870 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10871 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010872 }
10873
10874 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010875 * @return The calling package name or "phone" if the caller is the phone process. This is done
10876 * because multiple Phone has multiple packages in it and the first element in the array is not
10877 * actually always the caller.
10878 * Note: This is for logging purposes only and should not be used for security checks.
10879 */
10880 private String getCurrentPackageNameOrPhone() {
10881 PackageManager pm = mApp.getPackageManager();
10882 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10883 if (uidName != null && !uidName.isEmpty()) return uidName;
10884 return getCurrentPackageName();
10885 }
10886
10887 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010888 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10889 * corresponding network requests on a subId.
10890 *
10891 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010892 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010893 * 2) APN is un-metered for this subscription, or
10894 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010895 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010896 *
10897 * @return whether data is allowed for a apn type.
10898 *
10899 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010900 */
10901 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010902 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010903 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10904 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010905
joonhunshin4ac60942023-11-15 15:23:39 +000010906 enforceTelephonyFeatureWithException(callingPackage,
10907 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10908
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010909 // Now that all security checks passes, perform the operation as ourselves.
10910 final long identity = Binder.clearCallingIdentity();
10911 try {
10912 Phone phone = getPhone(subId);
10913 if (phone == null) return false;
10914
Jack Yu27422a52022-03-21 10:38:05 -070010915 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010916 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010917 isMetered = phone.getDataNetworkController().getDataConfigManager()
10918 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10919 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010920 isDataEnabled = (phone.getDataSettingsManager() != null)
10921 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010922 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010929 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010930 enforceReadPrivilegedPermission("isApnMetered");
10931
joonhunshin4ac60942023-11-15 15:23:39 +000010932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10933 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10934
Malcolm Chene5ad5792019-04-18 13:51:02 -070010935 // Now that all security checks passes, perform the operation as ourselves.
10936 final long identity = Binder.clearCallingIdentity();
10937 try {
10938 Phone phone = getPhone(subId);
10939 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010940 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10941 DataUtils.apnTypeToNetworkCapability(apnType),
10942 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010947
10948 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010949 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10950 int subscriptionId, IBooleanConsumer resultCallback) {
10951 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010952
10953 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10954 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10955
Hall Liu73f5d362020-01-20 13:42:00 -080010956 long token = Binder.clearCallingIdentity();
10957 try {
10958 Phone phone = getPhone(subscriptionId);
10959 if (phone == null) {
10960 try {
10961 if (resultCallback != null) {
10962 resultCallback.accept(false);
10963 }
10964 } catch (RemoteException e) {
10965 // ignore
10966 }
10967 return;
10968 }
10969 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10970 Pair.create(specifiers, (x) -> {
10971 try {
10972 if (resultCallback != null) {
10973 resultCallback.accept(x);
10974 }
10975 } catch (RemoteException e) {
10976 // ignore
10977 }
10978 });
10979 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10980 } finally {
10981 Binder.restoreCallingIdentity(token);
10982 }
10983 }
10984
10985 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010986 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10987 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010988 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010989 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010990
10991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10992 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10993
Sarah Chin679c08a2020-11-18 13:39:35 -080010994 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10995 final long identity = Binder.clearCallingIdentity();
10996 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010997 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10998 if (result instanceof IllegalStateException) {
10999 throw (IllegalStateException) result;
11000 }
11001 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011002 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11003 return specifiers;
11004 } finally {
11005 Binder.restoreCallingIdentity(identity);
11006 }
11007 }
11008
11009 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011010 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011011 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011012
11013 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11014 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11015
Jack Yu8b766fc2022-03-21 09:42:33 -070011016 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011017 }
11018
11019 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011020 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11021 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011022 if (callingPackage == null) {
11023 callingPackage = getCurrentPackageName();
11024 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011025 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11026 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011027 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11028 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011029 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11030 }
11031 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11032 Intent intent = new Intent();
11033 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11034 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11035 // Bring up choose default SMS subscription dialog right now
11036 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11037 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11038 mApp.startActivity(intent);
11039 }
chen xud5ca2d52019-05-28 15:20:57 -070011040
11041 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011042 public void showSwitchToManagedProfileDialog() {
11043 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011044 try {
11045 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11046 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11047 // for work telephony.
11048 Intent intent = new Intent(Intent.ACTION_SENDTO);
11049 intent.setData(Uri.parse("smsto:"));
11050 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11051 mApp.startActivity(intent);
11052 } catch (ActivityNotFoundException e) {
11053 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11054 Intent intent = new Intent();
11055 intent.setClass(mApp, ErrorDialogActivity.class);
11056 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11057 mApp.startActivity(intent);
11058 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011059 }
11060
11061 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011062 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011063 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11064 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11065
chen xud5ca2d52019-05-28 15:20:57 -070011066 //TODO investigate if this API should require proper permission check in R b/133791609
11067 final long identity = Binder.clearCallingIdentity();
11068 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011069 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11070 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11071 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11072 return carrierUAProfUrl;
11073 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011074 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11075 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011076 } finally {
11077 Binder.restoreCallingIdentity(identity);
11078 }
11079 }
11080
11081 @Override
11082 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011083 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11084 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11085
chen xud5ca2d52019-05-28 15:20:57 -070011086 //TODO investigate if this API should require proper permission check in R b/133791609
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011089 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11090 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11091 if (!TextUtils.isEmpty(carrierUserAgent)) {
11092 return carrierUserAgent;
11093 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011094 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11095 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011096 } finally {
11097 Binder.restoreCallingIdentity(identity);
11098 }
11099 }
Jack Yub07d4972019-05-28 16:12:25 -070011100
11101 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011102 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11103 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011104
joonhunshin4ac60942023-11-15 15:23:39 +000011105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11106 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11107
Jack Yub07d4972019-05-28 16:12:25 -070011108 final long identity = Binder.clearCallingIdentity();
11109 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011110 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011111 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011112
Ling Maf188d502022-09-16 15:22:36 -070011113 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011114 } finally {
11115 Binder.restoreCallingIdentity(identity);
11116 }
11117 }
11118
11119 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011120 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011121 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011122 enforceModifyPermission();
11123
joonhunshin4ac60942023-11-15 15:23:39 +000011124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11125 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11126
changbettyd5c246e2019-12-24 15:40:37 +080011127 final long identity = Binder.clearCallingIdentity();
11128 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011129 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011130 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011131
Ling Maf188d502022-09-16 15:22:36 -070011132 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011133 } finally {
11134 Binder.restoreCallingIdentity(identity);
11135 }
11136 }
11137
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011138 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011139 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011140 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11141 * otherwise.
11142 */
11143 @Override
11144 public void setCepEnabled(boolean isCepEnabled) {
11145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11146
11147 final long identity = Binder.clearCallingIdentity();
11148 try {
11149 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11150 for (Phone phone : PhoneFactory.getPhones()) {
11151 Phone defaultPhone = phone.getImsPhone();
11152 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11153 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11154 ImsPhoneCallTracker imsPhoneCallTracker =
11155 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11156 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11157 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11158 + imsPhone.getMsisdn());
11159 }
11160 }
11161 } finally {
11162 Binder.restoreCallingIdentity(identity);
11163 }
11164 }
allenwtsu46dcc572020-01-08 18:24:03 +080011165
11166 /**
11167 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11168 *
11169 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11170 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11171 * before being read.
11172 */
11173 @Override
11174 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11175 isCompressed) {
11176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11177 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11180 }
joonhunshin4ac60942023-11-15 15:23:39 +000011181
11182 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11183 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11184 Binder.getCallingUserHandle())) {
11185 if (!isImsAvailableOnDevice()) {
11186 // ProvisioningManager can not handle ServiceSpecificException.
11187 // Throw the IllegalStateException and annotate ProvisioningManager.
11188 throw new IllegalStateException("IMS not available on device.");
11189 }
11190 } else {
11191 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11192 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11193 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011194 }
11195
11196 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011197 try {
Hui Wang761a6682020-10-31 05:12:53 +000011198 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11199 } finally {
11200 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011201 }
11202 }
zoey chene02881a2019-12-30 16:11:23 +080011203
11204 @Override
11205 public boolean isIccLockEnabled(int subId) {
11206 enforceReadPrivilegedPermission("isIccLockEnabled");
11207
joonhunshin4ac60942023-11-15 15:23:39 +000011208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11209 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11210
zoey chene02881a2019-12-30 16:11:23 +080011211 // Now that all security checks passes, perform the operation as ourselves.
11212 final long identity = Binder.clearCallingIdentity();
11213 try {
11214 Phone phone = getPhone(subId);
11215 if (phone != null && phone.getIccCard() != null) {
11216 return phone.getIccCard().getIccLockEnabled();
11217 } else {
11218 return false;
11219 }
11220 } finally {
11221 Binder.restoreCallingIdentity(identity);
11222 }
11223 }
11224
11225 /**
11226 * Set the ICC pin lock enabled or disabled.
11227 *
11228 * @return an integer representing the status of IccLock enabled or disabled in the following
11229 * three cases:
11230 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11231 * successfully.
11232 * - Positive number and zero for remaining password attempts.
11233 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11234 *
11235 */
11236 @Override
11237 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11238 enforceModifyPermission();
11239
joonhunshin4ac60942023-11-15 15:23:39 +000011240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11241 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11242
zoey chene02881a2019-12-30 16:11:23 +080011243 Phone phone = getPhone(subId);
11244 if (phone == null) {
11245 return 0;
11246 }
11247 // Now that all security checks passes, perform the operation as ourselves.
11248 final long identity = Binder.clearCallingIdentity();
11249 try {
11250 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11251 new Pair<Boolean, String>(enabled, password), phone, null);
11252 return attemptsRemaining;
11253
11254 } catch (Exception e) {
11255 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 return 0;
11260 }
11261
11262 /**
11263 * Change the ICC password used in ICC pin lock.
11264 *
11265 * @return an integer representing the status of IccLock changed in the following three cases:
11266 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11267 * - Positive number and zero for remaining password attempts.
11268 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11269 *
11270 */
11271 @Override
11272 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11273 enforceModifyPermission();
11274
joonhunshin4ac60942023-11-15 15:23:39 +000011275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11276 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11277
zoey chene02881a2019-12-30 16:11:23 +080011278 Phone phone = getPhone(subId);
11279 if (phone == null) {
11280 return 0;
11281 }
11282 // Now that all security checks passes, perform the operation as ourselves.
11283 final long identity = Binder.clearCallingIdentity();
11284 try {
11285 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11286 new Pair<String, String>(oldPassword, newPassword), phone, null);
11287 return attemptsRemaining;
11288
11289 } catch (Exception e) {
11290 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 return 0;
11295 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011296
11297 /**
11298 * Request for receiving user activity notification
11299 */
11300 @Override
11301 public void requestUserActivityNotification() {
11302 if (!mNotifyUserActivity.get()
11303 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11304 mNotifyUserActivity.set(true);
11305 }
11306 }
11307
11308 /**
11309 * Called when userActivity is signalled in the power manager.
11310 * This is safe to call from any thread, with any window manager locks held or not.
11311 */
11312 @Override
11313 public void userActivity() {
11314 // ***************************************
11315 // * Inherited from PhoneWindowManager *
11316 // ***************************************
11317 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11318 // WITH ITS LOCKS HELD.
11319 //
11320 // This code must be VERY careful about the locks
11321 // it acquires.
11322 // In fact, the current code acquires way too many,
11323 // and probably has lurking deadlocks.
11324
11325 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11326 throw new SecurityException("Only the OS may call notifyUserActivity()");
11327 }
11328
11329 if (mNotifyUserActivity.getAndSet(false)) {
11330 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11331 USER_ACTIVITY_NOTIFICATION_DELAY);
11332 }
11333 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011334
11335 @Override
11336 public boolean canConnectTo5GInDsdsMode() {
11337 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11338 }
Jack Yud10cdd42020-09-28 20:28:01 -070011339
11340 @Override
11341 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11342 String callingFeatureId) {
11343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11344 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11345 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11346 }
11347
joonhunshin4ac60942023-11-15 15:23:39 +000011348 enforceTelephonyFeatureWithException(callingPackage,
11349 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11350
Jack Yud10cdd42020-09-28 20:28:01 -070011351 Phone phone = getPhone(subId);
11352 if (phone == null) {
11353 throw new RuntimeException("phone is not available");
11354 }
11355 // Now that all security checks passes, perform the operation as ourselves.
11356 final long identity = Binder.clearCallingIdentity();
11357 try {
11358 return phone.getEquivalentHomePlmns();
11359 } finally {
11360 Binder.restoreCallingIdentity(identity);
11361 }
11362 }
Daniel Bright59e67312020-11-13 11:49:37 -080011363
11364 @Override
11365 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011366 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011367 if (!mApp.getResources().getBoolean(
11368 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11369 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11370 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11371 "isRadioInterfaceCapabilitySupported");
11372 }
joonhunshin4ac60942023-11-15 15:23:39 +000011373
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011374 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011375 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011376 if (radioInterfaceCapabilities == null) {
11377 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011378 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011379 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011380 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011381
Hui Wang641e81c2020-10-12 12:14:23 -070011382 @Override
11383 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11384 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011385 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11386 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11387 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11388 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11389 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011390
11391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11392 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11393
Hui Wang641e81c2020-10-12 12:14:23 -070011394 if (DBG) {
11395 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11396 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11397 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11398 }
11399
11400 if (!SubscriptionManager.isValidSubscriptionId(subId)
11401 || appType < TelephonyManager.APPTYPE_UNKNOWN
11402 || appType > TelephonyManager.APPTYPE_ISIM
11403 || nafUrl == null || securityProtocol == null || callback == null) {
11404 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11405 if (callback != null) {
11406 try {
11407 callback.onAuthenticationFailure(
11408 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11409 } catch (RemoteException exception) {
11410 log("Fail to notify onAuthenticationFailure due to " + exception);
11411 }
11412 return;
11413 }
11414 }
11415
11416 final long token = Binder.clearCallingIdentity();
11417 try {
11418 getGbaManager(subId).bootstrapAuthenticationRequest(
11419 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011420 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011421 } finally {
11422 Binder.restoreCallingIdentity(token);
11423 }
11424 }
11425
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011426 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011427 * Attempts to set the radio power state for all phones for thermal reason.
11428 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011429 * requested radio power state will actually be set. See {@link
11430 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11431 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011432 * @param enable {@code true} if trying to turn radio on.
11433 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11434 * false}.
11435 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011436 private boolean setRadioPowerForThermal(boolean enable) {
11437 boolean isPhoneAvailable = false;
11438 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11439 Phone phone = PhoneFactory.getPhone(i);
11440 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011441 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011442 isPhoneAvailable = true;
11443 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011444 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011445
11446 // return true if successfully informed the phone object about the thermal radio power
11447 // request.
11448 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011449 }
11450
11451 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011452 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011453 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11454 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11455 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11456 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11457 throw new IllegalArgumentException("modem does not support data throttling");
11458 }
11459
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011460 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11461 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011462 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011463 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11464 }
11465
Sarah Chinecc78c42022-03-31 21:16:48 -070011466 setDataEnabledForReason(
11467 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011468
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011469 if (isDataThrottlingSupported) {
11470 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011471 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011472 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11473 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11474 } else if (thermalMitigationResult
11475 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011476 log("Modem likely does not support data throttling on secondary carrier. Data " +
11477 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11478 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011479 }
11480 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011481 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011482
11483 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011484 }
11485
Jack Nudelman644b91a2021-03-12 14:09:48 -080011486 private static List<String> getThermalMitigationAllowlist(Context context) {
11487 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11488 for (String pckg : context.getResources()
11489 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11490 sThermalMitigationAllowlistedPackages.add(pckg);
11491 }
11492 }
11493
11494 return sThermalMitigationAllowlistedPackages;
11495 }
11496
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011497 private boolean isAnyPhoneInEmergencyState() {
11498 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11499 if (tm.isInEmergencyCall()) {
11500 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11501 return true;
11502 }
11503 for (Phone phone : PhoneFactory.getPhones()) {
11504 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11505 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11507 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011508 return true;
11509 }
11510 }
11511
11512 return false;
11513 }
11514
Jack Nudelman644b91a2021-03-12 14:09:48 -080011515 /**
11516 * Used by shell commands to add an authorized package name for thermal mitigation.
11517 * @param packageName name of package to be allowlisted
11518 * @param context
11519 */
11520 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11521 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11522 sThermalMitigationAllowlistedPackages.add(packageName);
11523 }
11524
11525 /**
11526 * Used by shell commands to remove an authorized package name for thermal mitigation.
11527 * @param packageName name of package to remove from allowlist
11528 * @param context
11529 */
11530 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11531 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11532 sThermalMitigationAllowlistedPackages.remove(packageName);
11533 }
11534
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011535 /**
11536 * Thermal mitigation request to control functionalities at modem.
11537 *
11538 * @param subId the id of the subscription.
11539 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011540 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011541 *
11542 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11543 */
11544 @Override
11545 @ThermalMitigationResult
11546 public int sendThermalMitigationRequest(
11547 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011548 ThermalMitigationRequest thermalMitigationRequest,
11549 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011550 enforceModifyPermission();
11551
Jack Nudelman644b91a2021-03-12 14:09:48 -080011552 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011553
11554 enforceTelephonyFeatureWithException(callingPackage,
11555 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11556
Jack Nudelman644b91a2021-03-12 14:09:48 -080011557 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11558 .contains(callingPackage)) {
11559 throw new SecurityException("Calling package must be configured in the device config. "
11560 + "calling package: " + callingPackage);
11561 }
11562
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11564 final long identity = Binder.clearCallingIdentity();
11565
11566 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11567 try {
11568 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11569 switch (thermalMitigationAction) {
11570 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11571 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011572 handleDataThrottlingRequest(subId,
11573 thermalMitigationRequest.getDataThrottlingRequest(),
11574 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011575 break;
11576 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11577 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11578 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11579 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11580 }
11581
11582 // Ensure that radio is on. If not able to power on due to phone being
11583 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011584 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011585 thermalMitigationResult =
11586 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11587 break;
11588 }
11589
11590 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011591 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011592 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11593 break;
11594 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11595 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11596 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11597 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11598 }
11599
11600 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11601 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011602 Phone phone = getPhone(subId);
11603 if (phone == null) {
11604 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011605 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011606 break;
11607 }
11608
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011609 TelephonyConnectionService service =
11610 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011611 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011612 Log.e(LOG_TAG, "An emergency call is pending");
11613 thermalMitigationResult =
11614 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11615 break;
11616 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011617 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011618 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011619 break;
11620 }
11621 } else {
11622 thermalMitigationResult =
11623 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11624 break;
11625 }
11626
11627 // Turn radio off. If not able to power off due to phone being unavailable,
11628 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011629 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011630 thermalMitigationResult =
11631 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11632 break;
11633 }
11634 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011635 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011636 break;
11637 default:
11638 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11639 + "not exist. Requested action: " + thermalMitigationAction);
11640 }
11641 } catch (IllegalArgumentException e) {
11642 throw e;
11643 } catch (Exception e) {
11644 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11645 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11646 } finally {
11647 Binder.restoreCallingIdentity(identity);
11648 }
11649
11650 if (DBG) {
11651 log("thermalMitigationRequest returning with thermalMitigationResult: "
11652 + thermalMitigationResult);
11653 }
11654
11655 return thermalMitigationResult;
11656 }
Hui Wang641e81c2020-10-12 12:14:23 -070011657
11658 /**
11659 * Set the GbaService Package Name that Telephony will bind to.
11660 *
11661 * @param subId The sim that the GbaService is associated with.
11662 * @param packageName The name of the package to be replaced with.
11663 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11664 */
11665 @Override
11666 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11667 enforceModifyPermission();
11668
11669 final long identity = Binder.clearCallingIdentity();
11670 try {
11671 return getGbaManager(subId).overrideServicePackage(packageName);
11672 } finally {
11673 Binder.restoreCallingIdentity(identity);
11674 }
11675 }
11676
11677 /**
11678 * Return the package name of the currently bound GbaService.
11679 *
11680 * @param subId The sim that the GbaService is associated with.
11681 * @return the package name of the GbaService configuration, null if GBA is not supported.
11682 */
11683 @Override
11684 public String getBoundGbaService(int subId) {
11685 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11686
11687 final long identity = Binder.clearCallingIdentity();
11688 try {
11689 return getGbaManager(subId).getServicePackage();
11690 } finally {
11691 Binder.restoreCallingIdentity(identity);
11692 }
11693 }
11694
11695 /**
11696 * Set the release time for telephony to unbind GbaService.
11697 *
11698 * @param subId The sim that the GbaService is associated with.
11699 * @param interval The release time to unbind GbaService by millisecond.
11700 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11701 */
11702 @Override
11703 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11704 enforceModifyPermission();
11705
11706 final long identity = Binder.clearCallingIdentity();
11707 try {
11708 return getGbaManager(subId).overrideReleaseTime(interval);
11709 } finally {
11710 Binder.restoreCallingIdentity(identity);
11711 }
11712 }
11713
11714 /**
11715 * Return the release time for telephony to unbind GbaService.
11716 *
11717 * @param subId The sim that the GbaService is associated with.
11718 * @return The release time to unbind GbaService by millisecond.
11719 */
11720 @Override
11721 public int getGbaReleaseTime(int subId) {
11722 enforceReadPrivilegedPermission("getGbaReleaseTime");
11723
11724 final long identity = Binder.clearCallingIdentity();
11725 try {
11726 return getGbaManager(subId).getReleaseTime();
11727 } finally {
11728 Binder.restoreCallingIdentity(identity);
11729 }
11730 }
11731
11732 private GbaManager getGbaManager(int subId) {
11733 GbaManager instance = GbaManager.getInstance(subId);
11734 if (instance == null) {
11735 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11736 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11737 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11738 }
11739 return instance;
11740 }
Hui Wang761a6682020-10-31 05:12:53 +000011741
11742 /**
11743 * indicate whether the device and the carrier can support
11744 * RCS VoLTE single registration.
11745 */
11746 @Override
11747 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011748 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11749 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11750 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11751 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011752
11753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11754 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11755 }
11756
11757 final long identity = Binder.clearCallingIdentity();
11758 try {
11759 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11760 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011761 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11762 if (isCapable != null) {
11763 return isCapable;
11764 }
Hui Wang761a6682020-10-31 05:12:53 +000011765 }
Hui Wang67af90e2021-06-04 16:57:15 -070011766 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11767 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011768 } finally {
11769 Binder.restoreCallingIdentity(identity);
11770 }
11771 }
11772
11773 /**
11774 * Register RCS provisioning callback.
11775 */
11776 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011777 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011778 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011779 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011780 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011781 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11782 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011783
11784 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11785 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11786 }
joonhunshin4ac60942023-11-15 15:23:39 +000011787 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11788 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11789 Binder.getCallingUserHandle())) {
11790 if (!isImsAvailableOnDevice()) {
11791 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11792 "IMS not available on device.");
11793 }
11794 } else {
11795 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11796 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011797 }
11798
11799 final long identity = Binder.clearCallingIdentity();
11800 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011801 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011802 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011803 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11804 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011805 }
Hui Wang761a6682020-10-31 05:12:53 +000011806 } finally {
11807 Binder.restoreCallingIdentity(identity);
11808 }
11809 }
11810
11811 /**
11812 * Unregister RCS provisioning callback.
11813 */
11814 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011815 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011816 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011817 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011818 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011819 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11820 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011821
11822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11824 }
joonhunshin4ac60942023-11-15 15:23:39 +000011825
11826 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11827 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11828 Binder.getCallingUserHandle())) {
11829 if (!isImsAvailableOnDevice()) {
11830 // operation failed silently
11831 Rlog.w(LOG_TAG, "IMS not available on device.");
11832 return;
11833 }
11834 } else {
11835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11836 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11837 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011838 }
11839
11840 final long identity = Binder.clearCallingIdentity();
11841 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011842 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011843 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011844 } finally {
11845 Binder.restoreCallingIdentity(identity);
11846 }
11847 }
11848
11849 /**
11850 * trigger RCS reconfiguration.
11851 */
11852 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011853 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11854 "triggerRcsReconfiguration",
11855 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011856
11857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11859 }
joonhunshin4ac60942023-11-15 15:23:39 +000011860 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11861 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11862 Binder.getCallingUserHandle())) {
11863 if (!isImsAvailableOnDevice()) {
11864 // ProvisioningManager can not handle ServiceSpecificException.
11865 // Throw the IllegalStateException and annotate ProvisioningManager.
11866 throw new IllegalStateException("IMS not available on device.");
11867 }
11868 } else {
11869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11870 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011871 }
11872
11873 final long identity = Binder.clearCallingIdentity();
11874 try {
11875 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11876 } finally {
11877 Binder.restoreCallingIdentity(identity);
11878 }
11879 }
11880
11881 /**
11882 * Provide the client configuration parameters of the RCS application.
11883 */
11884 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011885 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11886 "setRcsClientConfiguration",
11887 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011888
11889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11891 }
joonhunshin4ac60942023-11-15 15:23:39 +000011892 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11893 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11894 Binder.getCallingUserHandle())) {
11895 if (!isImsAvailableOnDevice()) {
11896 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11897 "IMS not available on device.");
11898 }
11899 } else {
11900 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11901 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011902 }
11903
11904 final long identity = Binder.clearCallingIdentity();
11905
11906 try {
11907 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11908 if (configBinder == null) {
11909 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011910 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11911 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011912 } else {
11913 configBinder.setRcsClientConfiguration(rcc);
11914 }
joonhunshin3e154242021-09-17 06:33:39 +000011915
11916 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11917 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011918 } catch (RemoteException e) {
11919 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011920 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11921 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011922 } finally {
11923 Binder.restoreCallingIdentity(identity);
11924 }
11925 }
11926
11927 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011928 * Enables or disables the test mode for RCS VoLTE single registration.
11929 */
11930 @Override
11931 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11933 "setRcsSingleRegistrationTestModeEnabled");
11934
11935 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11936 }
11937
11938 /**
11939 * Gets the test mode for RCS VoLTE single registration.
11940 */
11941 @Override
11942 public boolean getRcsSingleRegistrationTestModeEnabled() {
11943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11944 "getRcsSingleRegistrationTestModeEnabled");
11945
11946 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11947 }
11948
11949 /**
Hui Wang761a6682020-10-31 05:12:53 +000011950 * Overrides the config of RCS VoLTE single registration enabled for the device.
11951 */
11952 @Override
11953 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11955 "setDeviceSingleRegistrationEnabledOverride");
11956 enforceModifyPermission();
11957
11958 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11959 : Boolean.parseBoolean(enabledStr);
11960 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011961 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011962 }
11963
11964 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011965 * Sends a device to device communication message. Only usable via shell.
11966 * @param message message to send.
11967 * @param value message value.
11968 */
11969 @Override
11970 public void sendDeviceToDeviceMessage(int message, int value) {
11971 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011972 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011973 enforceModifyPermission();
11974
11975 final long identity = Binder.clearCallingIdentity();
11976 try {
11977 TelephonyConnectionService service =
11978 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11979 if (service == null) {
11980 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11981 return;
11982 }
11983 service.sendTestDeviceToDeviceMessage(message, value);
11984 } finally {
11985 Binder.restoreCallingIdentity(identity);
11986 }
11987 }
11988
Tyler Gunnbabbda02021-02-10 11:05:02 -080011989 /**
11990 * Sets the specified device to device transport active.
11991 * @param transport The transport to set active.
11992 */
11993 @Override
11994 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11996 "setActiveDeviceToDeviceTransport");
11997 enforceModifyPermission();
11998
11999 final long identity = Binder.clearCallingIdentity();
12000 try {
12001 TelephonyConnectionService service =
12002 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12003 if (service == null) {
12004 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12005 return;
12006 }
12007 service.setActiveDeviceToDeviceTransport(transport);
12008 } finally {
12009 Binder.restoreCallingIdentity(identity);
12010 }
12011 }
Tyler Gunn92479152021-01-20 16:30:10 -080012012
Tyler Gunnd4339262021-05-03 14:46:49 -070012013 @Override
12014 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12015 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12016 "setDeviceToDeviceForceEnabled");
12017
12018 final long identity = Binder.clearCallingIdentity();
12019 try {
12020 Arrays.stream(PhoneFactory.getPhones()).forEach(
12021 p -> {
12022 Phone thePhone = p.getImsPhone();
12023 if (thePhone != null && thePhone instanceof ImsPhone) {
12024 ImsPhone imsPhone = (ImsPhone) thePhone;
12025 CallTracker tracker = imsPhone.getCallTracker();
12026 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12027 ImsPhoneCallTracker imsPhoneCallTracker =
12028 (ImsPhoneCallTracker) tracker;
12029 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12030 }
12031 }
12032 }
12033 );
12034 } finally {
12035 Binder.restoreCallingIdentity(identity);
12036 }
12037 }
12038
Tyler Gunn92479152021-01-20 16:30:10 -080012039 /**
Hui Wang761a6682020-10-31 05:12:53 +000012040 * Gets the config of RCS VoLTE single registration enabled for the device.
12041 */
12042 @Override
12043 public boolean getDeviceSingleRegistrationEnabled() {
12044 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12045 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12046 }
12047
12048 /**
12049 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12050 */
12051 @Override
12052 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12054 "setCarrierSingleRegistrationEnabledOverride");
12055 enforceModifyPermission();
12056
12057 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12058 : Boolean.parseBoolean(enabledStr);
12059 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12060 subId, enabled);
12061 }
12062
12063 /**
12064 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12065 */
12066 @Override
12067 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12068 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12069 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12070 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012071
12072 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012073 * Overrides the ims feature validation result
12074 */
12075 @Override
12076 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12078 "setImsFeatureValidationOverride");
12079
12080 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12081 : Boolean.parseBoolean(enabledStr);
12082 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12083 subId, enabled);
12084 }
12085
12086 /**
12087 * Gets the ims feature validation override value
12088 */
12089 @Override
12090 public boolean getImsFeatureValidationOverride(int subId) {
12091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12092 "getImsFeatureValidationOverride");
12093 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12094 }
12095
12096 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012097 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12098 * their mobile plan.
12099 */
12100 @Override
12101 public String getMobileProvisioningUrl() {
12102 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12103 final long identity = Binder.clearCallingIdentity();
12104 try {
12105 return getDefaultPhone().getMobileProvisioningUrl();
12106 } finally {
12107 Binder.restoreCallingIdentity(identity);
12108 }
12109 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012110
James.cf Linbcdf8b32021-01-14 16:44:13 +080012111 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012112 * Get the EAB contact from the EAB database.
12113 */
12114 @Override
12115 public String getContactFromEab(String contact) {
12116 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12117 enforceModifyPermission();
12118 final long identity = Binder.clearCallingIdentity();
12119 try {
12120 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12121 } finally {
12122 Binder.restoreCallingIdentity(identity);
12123 }
12124 }
12125
12126 /**
Calvin Pana1434322021-07-01 19:27:01 +080012127 * Get the EAB capability from the EAB database.
12128 */
12129 @Override
12130 public String getCapabilityFromEab(String contact) {
12131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12132 enforceModifyPermission();
12133 final long identity = Binder.clearCallingIdentity();
12134 try {
12135 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12136 } finally {
12137 Binder.restoreCallingIdentity(identity);
12138 }
12139 }
12140
12141 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012142 * Remove the EAB contacts from the EAB database.
12143 */
12144 @Override
12145 public int removeContactFromEab(int subId, String contacts) {
12146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12147 enforceModifyPermission();
12148 final long identity = Binder.clearCallingIdentity();
12149 try {
12150 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12151 } finally {
12152 Binder.restoreCallingIdentity(identity);
12153 }
12154 }
12155
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012156 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012157 public boolean getDeviceUceEnabled() {
12158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12159 final long identity = Binder.clearCallingIdentity();
12160 try {
12161 return mApp.getDeviceUceEnabled();
12162 } finally {
12163 Binder.restoreCallingIdentity(identity);
12164 }
12165 }
12166
12167 @Override
12168 public void setDeviceUceEnabled(boolean isEnabled) {
12169 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12170 final long identity = Binder.clearCallingIdentity();
12171 try {
12172 mApp.setDeviceUceEnabled(isEnabled);
12173 } finally {
12174 Binder.restoreCallingIdentity(identity);
12175 }
12176 }
12177
Brad Ebinger14d467f2021-02-12 06:18:28 +000012178 /**
12179 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12180 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12181 */
12182 // Used for SHELL command only right now.
12183 @Override
12184 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12185 List<String> featureTags) {
12186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12187 "addUceRegistrationOverrideShell");
12188 final long identity = Binder.clearCallingIdentity();
12189 try {
12190 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12191 new ArraySet<>(featureTags));
12192 } catch (ImsException e) {
12193 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12194 } finally {
12195 Binder.restoreCallingIdentity(identity);
12196 }
12197 }
12198
12199 /**
12200 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12201 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12202 */
12203 // Used for SHELL command only right now.
12204 @Override
12205 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12206 List<String> featureTags) {
12207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12208 "removeUceRegistrationOverrideShell");
12209 final long identity = Binder.clearCallingIdentity();
12210 try {
12211 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12212 new ArraySet<>(featureTags));
12213 } catch (ImsException e) {
12214 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12215 } finally {
12216 Binder.restoreCallingIdentity(identity);
12217 }
12218 }
12219
12220 /**
12221 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12222 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12223 */
12224 // Used for SHELL command only right now.
12225 @Override
12226 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12227 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12228 "clearUceRegistrationOverrideShell");
12229 final long identity = Binder.clearCallingIdentity();
12230 try {
12231 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12232 } catch (ImsException e) {
12233 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12234 } finally {
12235 Binder.restoreCallingIdentity(identity);
12236 }
12237 }
12238
12239 /**
12240 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12241 */
12242 // Used for SHELL command only right now.
12243 @Override
12244 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12246 "getLatestRcsContactUceCapabilityShell");
12247 final long identity = Binder.clearCallingIdentity();
12248 try {
12249 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12250 } catch (ImsException e) {
12251 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12252 } finally {
12253 Binder.restoreCallingIdentity(identity);
12254 }
12255 }
12256
12257 /**
12258 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12259 * device does not have an active PUBLISH.
12260 */
12261 // Used for SHELL command only right now.
12262 @Override
12263 public String getLastUcePidfXmlShell(int subId) {
12264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12265 final long identity = Binder.clearCallingIdentity();
12266 try {
12267 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12268 } catch (ImsException e) {
12269 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12270 } finally {
12271 Binder.restoreCallingIdentity(identity);
12272 }
12273 }
12274
James.cf Line8713a42021-04-29 16:04:26 +080012275 /**
12276 * Remove UCE requests cannot be sent to the network status.
12277 */
12278 // Used for SHELL command only right now.
12279 @Override
12280 public boolean removeUceRequestDisallowedStatus(int subId) {
12281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12282 final long identity = Binder.clearCallingIdentity();
12283 try {
12284 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12285 } catch (ImsException e) {
12286 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12287 } finally {
12288 Binder.restoreCallingIdentity(identity);
12289 }
12290 }
12291
James.cf Lin18bb9002021-05-25 01:37:38 +080012292 /**
12293 * Remove UCE requests cannot be sent to the network status.
12294 */
12295 // Used for SHELL command only.
12296 @Override
12297 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12299 final long identity = Binder.clearCallingIdentity();
12300 try {
12301 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12302 } catch (ImsException e) {
12303 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12304 } finally {
12305 Binder.restoreCallingIdentity(identity);
12306 }
12307 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012308
James.cf Lin4b784aa2021-01-31 03:25:15 +080012309 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012310 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12311 String callingPackage) {
12312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12313 mApp, subId, "setSignalStrengthUpdateRequest");
12314
joonhunshin4ac60942023-11-15 15:23:39 +000012315 enforceTelephonyFeatureWithException(callingPackage,
12316 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12317
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012318 final int callingUid = Binder.getCallingUid();
12319 // Verify that tha callingPackage belongs to the calling UID
12320 mApp.getSystemService(AppOpsManager.class)
12321 .checkPackage(callingUid, callingPackage);
12322
Rambo Wang3607f502021-02-01 21:51:40 -080012323 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012324
12325 final long identity = Binder.clearCallingIdentity();
12326 try {
12327 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12328 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12329
12330 if (result instanceof IllegalStateException) {
12331 throw (IllegalStateException) result;
12332 }
12333 } finally {
12334 Binder.restoreCallingIdentity(identity);
12335 }
12336 }
12337
12338 @Override
12339 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12340 String callingPackage) {
12341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12342 mApp, subId, "clearSignalStrengthUpdateRequest");
12343
joonhunshin4ac60942023-11-15 15:23:39 +000012344 enforceTelephonyFeatureWithException(callingPackage,
12345 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12346
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012347 final int callingUid = Binder.getCallingUid();
12348 // Verify that tha callingPackage belongs to the calling UID
12349 mApp.getSystemService(AppOpsManager.class)
12350 .checkPackage(callingUid, callingPackage);
12351
12352 final long identity = Binder.clearCallingIdentity();
12353 try {
12354 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12355 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12356
12357 if (result instanceof IllegalStateException) {
12358 throw (IllegalStateException) result;
12359 }
12360 } finally {
12361 Binder.restoreCallingIdentity(identity);
12362 }
12363 }
12364
Rambo Wang3607f502021-02-01 21:51:40 -080012365 private static void validateSignalStrengthUpdateRequest(Context context,
12366 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012367 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012368 // phone/system process do not have further restriction on request
12369 return;
12370 }
12371
12372 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012373 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012374 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012375 context.enforceCallingOrSelfPermission(
12376 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12377 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012378 }
12379
12380 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012381 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012382 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012383 || info.isEnabled()) {
12384 throw new IllegalArgumentException(
12385 "Only system can set hide fields in SignalThresholdInfo");
12386 }
12387
12388 // Thresholds length for each RAN need in range. This has been validated in
12389 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12390 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12391 final int[] thresholds = info.getThresholds();
12392 Objects.requireNonNull(thresholds);
12393 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12394 || thresholds.length
12395 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12396 throw new IllegalArgumentException(
12397 "thresholds length is out of range: " + thresholds.length);
12398 }
12399 }
12400 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012401
12402 /**
12403 * Gets the current phone capability.
12404 *
12405 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12406 * @return the PhoneCapability which describes the data connection capability of modem.
12407 * It's used to evaluate possible phone config change, for example from single
12408 * SIM device to multi-SIM device.
12409 */
12410 @Override
12411 public PhoneCapability getPhoneCapability() {
12412 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012413
12414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12415 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12416
SongFerngWang8236caa2021-01-17 21:51:44 +080012417 final long identity = Binder.clearCallingIdentity();
12418 try {
12419 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12420 } finally {
12421 Binder.restoreCallingIdentity(identity);
12422 }
12423 }
Michele Berionne5e411512020-11-13 02:36:59 +000012424
12425 /**
12426 * Prepare TelephonyManager for an unattended reboot. The reboot is
12427 * required to be done shortly after the API is invoked.
12428 */
12429 @Override
12430 @TelephonyManager.PrepareUnattendedRebootResult
12431 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012432 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012433 enforceRebootPermission();
12434
joonhunshin4ac60942023-11-15 15:23:39 +000012435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12436 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12437
Michele Berionne5e411512020-11-13 02:36:59 +000012438 final long identity = Binder.clearCallingIdentity();
12439 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012440 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012441 } finally {
12442 Binder.restoreCallingIdentity(identity);
12443 }
12444 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012445
12446 /**
12447 * Request to get the current slicing configuration including URSP rules and
12448 * NSSAIs (configured, allowed and rejected).
12449 *
12450 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12451 */
12452 @Override
12453 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012454 TelephonyPermissions
12455 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12456 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012457
joonhunshin4ac60942023-11-15 15:23:39 +000012458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12459 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12460 "getSlicingConfig");
12461
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012462 final long identity = Binder.clearCallingIdentity();
12463 try {
12464 Phone phone = getDefaultPhone();
12465 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12466 } finally {
12467 Binder.restoreCallingIdentity(identity);
12468 }
12469 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012470
12471 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012472 * Check whether the given premium capability is available for purchase from the carrier.
12473 *
12474 * @param capability The premium capability to check.
12475 * @param subId The subId to check the premium capability for.
12476 *
12477 * @return Whether the given premium capability is available to purchase.
12478 */
12479 @Override
12480 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12481 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12482 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12483 log("Premium capability "
12484 + TelephonyManager.convertPremiumCapabilityToString(capability)
12485 + " is not available for purchase due to missing permissions.");
12486 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12487 + "permission READ_BASIC_PHONE_STATE.");
12488 }
12489
joonhunshin4ac60942023-11-15 15:23:39 +000012490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12491 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12492
Sarah Chin2ec39f62022-08-31 17:03:26 -070012493 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012494 if (phone == null) {
12495 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12496 return false;
12497 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012498 final long identity = Binder.clearCallingIdentity();
12499 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012500 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012501 .isPremiumCapabilityAvailableForPurchase(capability);
12502 } finally {
12503 Binder.restoreCallingIdentity(identity);
12504 }
12505 }
12506
12507 /**
12508 * Purchase the given premium capability from the carrier.
12509 *
12510 * @param capability The premium capability to purchase.
12511 * @param callback The result of the purchase request.
12512 * @param subId The subId to purchase the premium capability for.
12513 */
12514 @Override
12515 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12516 log("purchasePremiumCapability: capability="
12517 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12518 + getCurrentPackageName());
12519
12520 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12521 mApp, "purchasePremiumCapability")) {
12522 log("purchasePremiumCapability "
12523 + TelephonyManager.convertPremiumCapabilityToString(capability)
12524 + " failed due to missing permissions.");
12525 throw new SecurityException("purchasePremiumCapability requires permission "
12526 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012527 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12528 mApp, "purchasePremiumCapability")) {
12529 log("purchasePremiumCapability "
12530 + TelephonyManager.convertPremiumCapabilityToString(capability)
12531 + " failed due to missing permissions.");
12532 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012533 }
12534
joonhunshin4ac60942023-11-15 15:23:39 +000012535 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12536 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12537
Sarah Chin2ec39f62022-08-31 17:03:26 -070012538 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012539 if (phone == null) {
12540 try {
12541 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12542 callback.accept(result);
12543 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12544 } catch (RemoteException e) {
12545 String logStr = "Purchase premium capability "
12546 + TelephonyManager.convertPremiumCapabilityToString(capability)
12547 + " failed due to RemoteException handling null phone: " + e;
12548 if (DBG) log(logStr);
12549 AnomalyReporter.reportAnomaly(
12550 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12551 }
12552 return;
12553 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012554
12555 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012556 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012557 callingProcess = mApp.getPackageManager().getApplicationInfo(
12558 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012559 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012560 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012561 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012562
12563 boolean isVisible = false;
12564 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12565 if (am != null) {
12566 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12567 if (processes != null) {
12568 for (ActivityManager.RunningAppProcessInfo process : processes) {
12569 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012570 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012571 if (process.processName.equals(callingProcess) && process.importance
12572 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12573 isVisible = true;
12574 break;
12575 }
12576 }
12577 }
12578 }
12579
12580 if (!isVisible) {
12581 try {
12582 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12583 callback.accept(result);
12584 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12585 } catch (RemoteException e) {
12586 String logStr = "Purchase premium capability "
12587 + TelephonyManager.convertPremiumCapabilityToString(capability)
12588 + " failed due to RemoteException handling background application: " + e;
12589 if (DBG) log(logStr);
12590 AnomalyReporter.reportAnomaly(
12591 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12592 }
12593 return;
12594 }
12595
Sarah Chin71b3a852022-09-28 15:54:19 -070012596 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012597 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012598 }
12599
12600 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012601 * Register an IMS connection state callback
12602 */
12603 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012604 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12605 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012606 if (feature == ImsFeature.FEATURE_MMTEL) {
12607 // ImsMmTelManager
12608 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12609 TelephonyPermissions
12610 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12611 mApp, subId, "registerImsStateCallback");
12612 } else if (feature == ImsFeature.FEATURE_RCS) {
12613 // ImsRcsManager or SipDelegateManager
12614 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12615 Binder.getCallingUid(), "registerImsStateCallback",
12616 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12617 Manifest.permission.READ_PRECISE_PHONE_STATE,
12618 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12619 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12620 }
12621
12622 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12623 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12624 "IMS not available on device.");
12625 }
12626
12627 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12628 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12629 }
12630
12631 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12632 if (controller == null) {
12633 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12634 "IMS not available on device.");
12635 }
12636
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012637 if (callingPackage == null) {
12638 callingPackage = getCurrentPackageName();
12639 }
12640
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012641 final long token = Binder.clearCallingIdentity();
12642 try {
12643 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012644 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012645 } catch (ImsException e) {
12646 throw new ServiceSpecificException(e.getCode());
12647 } finally {
12648 Binder.restoreCallingIdentity(token);
12649 }
12650 }
12651
12652 /**
12653 * Unregister an IMS connection state callback
12654 */
12655 @Override
12656 public void unregisterImsStateCallback(IImsStateCallback cb) {
12657 final long token = Binder.clearCallingIdentity();
12658 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12659 if (controller == null) {
12660 return;
12661 }
12662 try {
12663 controller.unregisterImsStateCallback(cb);
12664 } finally {
12665 Binder.restoreCallingIdentity(token);
12666 }
12667 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012668
12669 /**
12670 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12671 *
12672 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012673 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012674 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012675 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012676 * If there is current registered network this value will be same as the registered cell
12677 * identity. If the device goes out of service the previous cell identity is cached and
12678 * will be returned. If the cache age of the Cell identity is more than 24 hours
12679 * it will be cleared and null will be returned.
12680 *
12681 */
12682 @Override
12683 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12684 String callingFeatureId) {
12685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12686 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12687 LocationAccessPolicy.checkLocationPermission(mApp,
12688 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12689 .setCallingPackage(callingPackage)
12690 .setCallingFeatureId(callingFeatureId)
12691 .setCallingPid(Binder.getCallingPid())
12692 .setCallingUid(Binder.getCallingUid())
12693 .setMethod("getLastKnownCellIdentity")
12694 .setLogAsInfo(true)
12695 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12696 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12697 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12698 .build());
12699
12700 boolean hasFinePermission =
12701 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12702 if (!hasFinePermission
12703 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12704 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012705 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012706 }
12707
12708 final long identity = Binder.clearCallingIdentity();
12709 try {
Ling Mac28f0212023-03-24 16:07:15 -070012710 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012711 if (sst == null) return null;
12712 return sst.getLastKnownCellIdentity();
12713 } finally {
12714 Binder.restoreCallingIdentity(identity);
12715 }
12716 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012717
jimsun3b9ccac2021-10-26 15:01:23 +080012718 /**
12719 * Sets the modem service class Name that Telephony will bind to.
12720 *
12721 * @param serviceName The class name of the modem service.
12722 * @return true if the operation is succeed, otherwise false.
12723 */
12724 public boolean setModemService(String serviceName) {
12725 Log.d(LOG_TAG, "setModemService - " + serviceName);
12726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012728 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12729 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012730 return mPhoneConfigurationManager.setModemService(serviceName);
12731 }
12732
12733 /**
12734 * Return the class name of the currently bounded modem service.
12735 *
12736 * @return the class name of the modem service.
12737 */
12738 public String getModemService() {
12739 String result;
12740 Log.d(LOG_TAG, "getModemService");
12741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12742 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012743 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012744 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12745 "getModemService");
12746 result = mPhoneConfigurationManager.getModemService();
12747 Log.d(LOG_TAG, "result = " + result);
12748 return result;
12749 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012750
Hakjun Choi3ee81112023-12-19 15:40:58 +000012751 /**
12752 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12753 * including carrier config, entitlement server, and config update.
12754 *
12755 * @param subId subId The subscription ID of the carrier.
12756 *
12757 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12758 * be returned.
12759 *
12760 * @throws SecurityException if the caller doesn't have the required permission.
12761 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012762 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12763 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012764 final long identity = Binder.clearCallingIdentity();
12765 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012766 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012767 } finally {
12768 Binder.restoreCallingIdentity(identity);
12769 }
12770 }
12771
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012772 @Override
12773 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12774 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12775 mApp.enforceCallingOrSelfPermission(
12776 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12778
12779 final long identity = Binder.clearCallingIdentity();
12780 try {
12781 Phone phone = getPhone(subId);
12782 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012783 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12784 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012785 phone.setVoiceServiceStateOverride(hasService);
12786 } finally {
12787 Binder.restoreCallingIdentity(identity);
12788 }
12789 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012790
12791 /**
12792 * set removable eSIM as default eUICC.
12793 *
12794 * @hide
12795 */
12796 @Override
12797 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12798 enforceModifyPermission();
12799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12800
12801 final long identity = Binder.clearCallingIdentity();
12802 try {
12803 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12804 } finally {
12805 Binder.restoreCallingIdentity(identity);
12806 }
12807 }
12808
12809 /**
12810 * Returns whether the removable eSIM is default eUICC or not.
12811 *
12812 * @hide
12813 */
12814 @Override
12815 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12816 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12817 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12818
12819 final long identity = Binder.clearCallingIdentity();
12820 try {
12821 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12822 } finally {
12823 Binder.restoreCallingIdentity(identity);
12824 }
12825 }
12826
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012827 /**
12828 * Get the component name of the default app to direct respond-via-message intent for the
12829 * user associated with this subscription, update the cache if there is no respond-via-message
12830 * application currently configured for this user.
12831 * @return component name of the app and class to direct Respond Via Message intent to, or
12832 * {@code null} if the functionality is not supported.
12833 * @hide
12834 */
12835 @Override
12836 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12837 boolean updateIfNeeded) {
12838 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012839
joonhunshin4ac60942023-11-15 15:23:39 +000012840 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12841 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12842 "getDefaultRespondViaMessageApplication");
12843
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012844 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12845
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012846 UserHandle userHandle = null;
12847 final long identity = Binder.clearCallingIdentity();
12848 try {
12849 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12850 } finally {
12851 Binder.restoreCallingIdentity(identity);
12852 }
12853 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12854 updateIfNeeded, userHandle);
12855 }
Jack Yuf5badd92022-12-08 00:50:53 -080012856
12857 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012858 * Set whether the device is able to connect with null ciphering or integrity
12859 * algorithms. This is a global setting and will apply to all active subscriptions
12860 * and all new subscriptions after this.
12861 *
12862 * @param enabled when true, null cipher and integrity algorithms are allowed.
12863 * @hide
12864 */
12865 @Override
12866 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12867 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12868 enforceModifyPermission();
12869 checkForNullCipherAndIntegritySupport();
12870
12871 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12872 // for listening to these preference changes and applying them immediately.
12873 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12874 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12875 editor.apply();
12876
12877 for (Phone phone: PhoneFactory.getPhones()) {
12878 phone.handleNullCipherEnabledChange();
12879 }
12880 }
12881
12882
12883 /**
12884 * Get whether the device is able to connect with null ciphering or integrity
12885 * algorithms. Note that this retrieves the phone-global preference and not
12886 * the state of the radio.
12887 *
12888 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12889 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12890 * version for this feature.
12891 * @hide
12892 */
12893 @Override
12894 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12895 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12896 enforceReadPermission();
12897 checkForNullCipherAndIntegritySupport();
12898 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12899 }
12900
12901 private void checkForNullCipherAndIntegritySupport() {
12902 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12903 throw new UnsupportedOperationException(
12904 "Null cipher and integrity operations require HAL 2.1 or above");
12905 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012906 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12907 throw new UnsupportedOperationException(
12908 "Null cipher and integrity operations unsupported by modem");
12909 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012910 }
12911
Gil Cukierman06403e12023-11-29 16:33:03 +000012912 private void checkForIdentifierDisclosureNotificationSupport() {
12913 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12914 throw new UnsupportedOperationException(
12915 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12916 + "above");
12917 }
12918 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12919 throw new UnsupportedOperationException(
12920 "Cellular identifier disclosure transparency operations unsupported by modem");
12921 }
12922 }
12923
Michael Groover826b71d2023-12-21 22:08:06 -060012924 private void checkForNullCipherNotificationSupport() {
12925 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12926 throw new UnsupportedOperationException(
12927 "Null cipher notification operations require HAL 2.2 or above");
12928 }
12929 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12930 throw new UnsupportedOperationException(
12931 "Null cipher notification operations unsupported by modem");
12932 }
12933 }
12934
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012935 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012936 * Get the SIM state for the slot index.
12937 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12938 *
12939 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12940 */
12941 @Override
12942 @SimState
12943 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012944 if (!mApp.getResources().getBoolean(
12945 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12947 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12948 }
joonhunshin4ac60942023-11-15 15:23:39 +000012949
Jack Yuf5badd92022-12-08 00:50:53 -080012950 IccCardConstants.State simState;
12951 if (slotIndex < 0) {
12952 simState = IccCardConstants.State.UNKNOWN;
12953 } else {
12954 Phone phone = null;
12955 try {
12956 phone = PhoneFactory.getPhone(slotIndex);
12957 } catch (IllegalStateException e) {
12958 // ignore
12959 }
12960 if (phone == null) {
12961 simState = IccCardConstants.State.UNKNOWN;
12962 } else {
12963 IccCard icc = phone.getIccCard();
12964 if (icc == null) {
12965 simState = IccCardConstants.State.UNKNOWN;
12966 } else {
12967 simState = icc.getState();
12968 }
12969 }
12970 }
12971 return simState.ordinal();
12972 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012973
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012974 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12975 boolean enableLogcat,
12976 long logcatStartTimestampMillis, boolean enableTelecomDump,
12977 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012978 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012979 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12980 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12981 ecdDataBuilder
12982 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12983 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012984 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012985 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012986 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012987 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12988 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012989 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12990 Executors.newCachedThreadPool(), db,
12991 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012992 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012993 }
12994
12995 /**
12996 * Request telephony to persist state for debugging emergency call failures.
12997 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012998 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012999 * @param enableLogcat whether to collect logcat output
13000 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13001 * @param enableTelecomDump whether to collect telecom dumpsys
13002 * @param enableTelephonyDump whether to collect telephony dumpsys
13003 */
13004 @Override
13005 @RequiresPermission(android.Manifest.permission.DUMP)
13006 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13007 long logcatStartTimestampMillis, boolean enableTelecomDump,
13008 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013009 // Verify that the caller has READ_DROPBOX_DATA permission.
13010 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13011 && Flags.enableReadDropboxPermission()) {
13012 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13013 "persistEmergencyCallDiagnosticData");
13014 } else {
13015 // Otherwise, enforce legacy permission.
13016 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13017 "persistEmergencyCallDiagnosticData");
13018 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013019 final long identity = Binder.clearCallingIdentity();
13020 try {
13021 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13022 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13023
13024 } finally {
13025 Binder.restoreCallingIdentity(identity);
13026 }
13027 }
13028
Hui Wang9b5793a2022-12-05 14:38:06 -060013029 /**
13030 * Get current cell broadcast ranges.
13031 */
13032 @Override
13033 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13034 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13035 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13036 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013037
13038 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13039 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13040
Hui Wang9b5793a2022-12-05 14:38:06 -060013041 final long identity = Binder.clearCallingIdentity();
13042 try {
13043 return getPhone(subId).getCellBroadcastIdRanges();
13044 } finally {
13045 Binder.restoreCallingIdentity(identity);
13046 }
13047 }
13048
13049 /**
13050 * Set reception of cell broadcast messages with the list of the given ranges
13051 *
13052 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13053 */
13054 @Override
13055 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13056 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13057 @Nullable IIntegerConsumer callback) {
13058 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13059 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013060
13061 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13062 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13063
Hui Wang9b5793a2022-12-05 14:38:06 -060013064 final long identity = Binder.clearCallingIdentity();
13065 try {
13066 Phone phone = getPhoneFromSubId(subId);
13067 if (DBG) {
13068 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13069 }
13070 phone.setCellBroadcastIdRanges(ranges, result -> {
13071 if (callback != null) {
13072 try {
13073 callback.accept(result);
13074 } catch (RemoteException e) {
13075 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13076 }
13077 }
13078 });
13079 } finally {
13080 Binder.restoreCallingIdentity(identity);
13081 }
13082 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013083
13084 /**
13085 * Returns whether the device supports the domain selection service.
13086 *
13087 * @return {@code true} if the device supports the domain selection service.
13088 */
13089 @Override
13090 public boolean isDomainSelectionSupported() {
13091 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13092 "isDomainSelectionSupported");
13093
13094 final long identity = Binder.clearCallingIdentity();
13095 try {
13096 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13097 } finally {
13098 Binder.restoreCallingIdentity(identity);
13099 }
13100 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013101
13102 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013103 * Returns whether the AOSP domain selection service is supported.
13104 *
13105 * @return {@code true} if the AOSP domain selection service is supported,
13106 * {@code false} otherwise.
13107 */
13108 @Override
13109 public boolean isAospDomainSelectionService() {
13110 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13111 "isAospDomainSelectionService");
13112
13113 final long identity = Binder.clearCallingIdentity();
13114 try {
13115 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13116 String dssComponentName = mApp.getResources().getString(
13117 R.string.config_domain_selection_service_component_name);
13118 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13119 TelephonyDomainSelectionService.class.getName());
13120 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13121 + ", aosp=" + componentName.flattenToString());
13122 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13123 }
13124 } finally {
13125 Binder.restoreCallingIdentity(identity);
13126 }
13127 return false;
13128 }
13129
13130 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013131 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13132 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13133 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013134 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013135 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013136 * @param enableSatellite {@code true} to enable the satellite modem and
13137 * {@code false} to disable.
13138 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013139 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013140 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013141 *
13142 * @throws SecurityException if the caller doesn't have the required permission.
13143 */
13144 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013145 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013146 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013147 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013148 if (enableSatellite) {
13149 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13150 @Override
13151 protected void onReceiveResult(int resultCode, Bundle resultData) {
13152 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13153 + ", resultData=" + resultData);
13154 boolean isAllowed = false;
13155 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13156 callback::accept);
13157 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13158 if (resultData != null
13159 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13160 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13161 } else {
13162 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13163 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013164 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013165 result.accept(resultCode);
13166 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013167 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013168 if (isAllowed) {
13169 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013170 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013171 } else {
13172 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13173 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013174 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013175 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013176 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013177 subId, resultReceiver);
13178 } else {
13179 // No need to check if satellite is allowed at current location when disabling satellite
13180 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013181 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013182 }
Sarah Chin503828c2023-02-01 23:54:20 -080013183 }
13184
13185 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013186 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013187 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013188 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013189 * @param result The result receiver that returns whether the satellite modem is enabled
13190 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013191 *
13192 * @throws SecurityException if the caller doesn't have the required permission.
13193 */
13194 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013195 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13196 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013197 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013198 }
13199
13200 /**
Sarah Chin43457982023-02-15 17:50:38 -080013201 * Request to get whether the satellite service demo mode is enabled.
13202 *
13203 * @param subId The subId of the subscription to check whether the satellite demo mode
13204 * is enabled for.
13205 * @param result The result receiver that returns whether the satellite demo mode is enabled
13206 * if the request is successful or an error code if the request failed.
13207 *
13208 * @throws SecurityException if the caller doesn't have the required permission.
13209 */
13210 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013211 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13212 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13213 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013214 }
13215
13216 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013217 * Request to get whether the satellite service is enabled with emergency mode.
13218 *
13219 * @param subId The subId of the subscription to check whether the satellite demo mode
13220 * is enabled for.
13221 * @param result The result receiver that returns whether the satellite emergency mode is
13222 * enabled if the request is successful or an error code if the request failed.
13223 *
13224 * @throws SecurityException if the caller doesn't have the required permission.
13225 */
13226 @Override
13227 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13228 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshinfd78fd52024-07-11 05:28:13 +000013229 mSatelliteController.requestIsEmergencyModeEnabled(subId, result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013230 }
13231
13232 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013233 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013234 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013235 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013236 * @param result The result receiver that returns whether the satellite service is supported on
13237 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013238 */
13239 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013240 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013241 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013242 }
13243
13244 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013245 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013246 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013247 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013248 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13249 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013250 *
13251 * @throws SecurityException if the caller doesn't have required permission.
13252 */
13253 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013254 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13255 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013256 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013257 }
13258
13259 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013260 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013261 * This can be called by the pointing UI when the user starts pointing to the satellite.
13262 * Modem should continue to report the pointing input as the device or satellite moves.
13263 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013264 * @param subId The subId of the subscription to start satellite transmission updates for.
13265 * @param resultCallback The callback to get the result of the request.
13266 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013267 *
13268 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013269 */
13270 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013271 public void startSatelliteTransmissionUpdates(int subId,
13272 @NonNull IIntegerConsumer resultCallback,
13273 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13274 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13275 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013276 }
13277
13278 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013279 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013280 * This can be called by the pointing UI when the user stops pointing to the satellite.
13281 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013282 * @param subId The subId of the subscription to stop satellite transmission updates for.
13283 * @param resultCallback The callback to get the result of the request.
13284 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13285 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013286 *
13287 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013288 */
13289 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013290 public void stopSatelliteTransmissionUpdates(int subId,
13291 @NonNull IIntegerConsumer resultCallback,
13292 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13293 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13294 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013295 }
13296
13297 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013298 * Register the subscription with a satellite provider.
13299 * This is needed to register the subscription if the provider allows dynamic registration.
13300 *
13301 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013302 * @param token The token to be used as a unique identifier for provisioning with satellite
13303 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013304 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013305 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013306 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013307 * @return The signal transport used by the caller to cancel the provision request,
13308 * or {@code null} if the request failed.
13309 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013310 * @throws SecurityException if the caller doesn't have the required permission.
13311 */
13312 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013313 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013314 @NonNull String token, @NonNull byte[] provisionData,
13315 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013316 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013317 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13318 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013319 }
13320
13321 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013322 * Unregister the device/subscription with the satellite provider.
13323 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013324 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013325 * should report as deprovisioned.
13326 *
13327 * @param subId The subId of the subscription to be deprovisioned.
13328 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013329 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013330 *
13331 * @throws SecurityException if the caller doesn't have the required permission.
13332 */
13333 @Override
13334 public void deprovisionSatelliteService(int subId,
13335 @NonNull String token, @NonNull IIntegerConsumer callback) {
13336 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013337 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013338 }
13339
13340 /**
Sarah Chin43457982023-02-15 17:50:38 -080013341 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013342 *
Sarah Chin43457982023-02-15 17:50:38 -080013343 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013344 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013345 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013346 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013347 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013348 * @throws SecurityException if the caller doesn't have the required permission.
13349 */
13350 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013351 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13352 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013353 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013354 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013355 }
13356
13357 /**
Sarah Chin43457982023-02-15 17:50:38 -080013358 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013359 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013360 *
Sarah Chin43457982023-02-15 17:50:38 -080013361 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013362 * @param callback The callback that was passed to
13363 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013364 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013365 * @throws SecurityException if the caller doesn't have the required permission.
13366 */
13367 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013368 public void unregisterForSatelliteProvisionStateChanged(
13369 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013370 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013371 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013372 }
13373
13374 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013375 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013376 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013377 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013378 * @param result The result receiver that returns whether the device is provisioned with a
13379 * satellite provider if the request is successful or an error code if the
13380 * request failed.
13381 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013382 * @throws SecurityException if the caller doesn't have the required permission.
13383 */
13384 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013385 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13386 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013387 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013388 }
13389
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013390 /**
Sarah Chin43457982023-02-15 17:50:38 -080013391 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013392 *
Sarah Chin43457982023-02-15 17:50:38 -080013393 * @param subId The subId of the subscription to register for satellite modem state changed.
13394 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013395 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013396 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013397 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013398 * @throws SecurityException if the caller doesn't have the required permission.
13399 */
13400 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013401 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013402 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013403 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013404 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013405 }
13406
13407 /**
Sarah Chin43457982023-02-15 17:50:38 -080013408 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013409 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013410 *
Sarah Chin43457982023-02-15 17:50:38 -080013411 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013412 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013413 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013414 *
13415 * @throws SecurityException if the caller doesn't have the required permission.
13416 */
13417 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013418 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013419 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013420 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13421 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013422 }
13423
13424 /**
13425 * Register to receive incoming datagrams over satellite.
13426 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013427 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013428 * @param callback The callback to handle incoming datagrams over satellite.
13429 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013430 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013431 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013432 * @throws SecurityException if the caller doesn't have the required permission.
13433 */
13434 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013435 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013436 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013437 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13438 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013439 }
13440
13441 /**
13442 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013443 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013444 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013445 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13446 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013447 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013448 *
13449 * @throws SecurityException if the caller doesn't have the required permission.
13450 */
13451 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013452 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013453 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013454 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13455 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013456 }
13457
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013458 /**
13459 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013460 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013461 * This method requests modem to check if there are any pending datagrams to be received over
13462 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013463 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013464 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013465 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013466 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013467 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013468 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013469 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013470 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13471 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13472 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013473 }
13474
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013475 /**
13476 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013477 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013478 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13479 * input to this method. Datagram received here will be passed down to modem without any
13480 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013481 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013482 * @param subId The subId of the subscription to send satellite datagrams for.
13483 * @param datagramType datagram type indicating whether the datagram is of type
13484 * SOS_SMS or LOCATION_SHARING.
13485 * @param datagram encoded gateway datagram which is encrypted by the caller.
13486 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013487 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13488 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013489 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013490 *
13491 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013492 */
13493 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013494 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013495 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13496 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013497 enforceSatelliteCommunicationPermission("sendDatagram");
13498 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13499 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013500 }
13501
Sarah Chindf715ec2023-02-13 13:46:24 -080013502 /**
13503 * Request to get whether satellite communication is allowed for the current location.
13504 *
13505 * @param subId The subId of the subscription to check whether satellite communication is
13506 * allowed for the current location for.
13507 * @param result The result receiver that returns whether satellite communication is allowed
13508 * for the current location if the request is successful or an error code
13509 * if the request failed.
13510 *
13511 * @throws SecurityException if the caller doesn't have the required permission.
13512 */
13513 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013514 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013515 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013516 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13517 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13518 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013519 }
13520
13521 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013522 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013523 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013524 * @param subId The subId to get the time after which the satellite will be visible for.
13525 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013526 * be visible if the request is successful or an error code if the request failed.
13527 *
13528 * @throws SecurityException if the caller doesn't have the required permission.
13529 */
13530 @Override
13531 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13532 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013533 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013534 }
13535
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013536 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013537 * Inform that Device is aligned to satellite for demo mode.
13538 *
13539 * @param subId The subId to get the time after which the satellite will be visible for.
13540 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13541 * {@code false} Device fails to align with the satellite for demo mode.
13542 *
13543 * @throws SecurityException if the caller doesn't have required permission.
13544 */
13545 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13546
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013547 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013548 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013549 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013550 }
13551
13552 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013553 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13554 * by modem.
13555 *
13556 * @param subId The subId of the subscription to request for.
13557 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013558 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013559 * operation.
13560 *
13561 * @throws SecurityException if the caller doesn't have required permission.
13562 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013563 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013564 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13565 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013566 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013567 final long identity = Binder.clearCallingIdentity();
13568 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013569 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013570 } finally {
13571 Binder.restoreCallingIdentity(identity);
13572 }
13573 }
13574
13575 /**
13576 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13577 * by modem.
13578 *
13579 * @param subId The subId of the subscription to request for.
13580 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013581 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013582 * operation.
13583 *
13584 * @throws SecurityException if the caller doesn't have required permission.
13585 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013586 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013587 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13588 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013589 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013590 final long identity = Binder.clearCallingIdentity();
13591 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013592 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013593 } finally {
13594 Binder.restoreCallingIdentity(identity);
13595 }
13596 }
13597
13598 /**
13599 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013600 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013601 *
13602 * @param subId The subId of the subscription to request for.
13603 *
13604 * @return Integer array of reasons for disallowing satellite communication.
13605 *
13606 * @throws SecurityException if the caller doesn't have the required permission.
13607 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013608 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013609 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013610 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013611 final long identity = Binder.clearCallingIdentity();
13612 try {
13613 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013614 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013615 return reasonSet.stream().mapToInt(i->i).toArray();
13616 } finally {
13617 Binder.restoreCallingIdentity(identity);
13618 }
13619 }
13620
13621 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013622 * Request to get the signal strength of the satellite connection.
13623 *
13624 * @param subId The subId of the subscription to request for.
13625 * @param result Result receiver to get the error code of the request and the current signal
13626 * strength of the satellite connection.
13627 *
13628 * @throws SecurityException if the caller doesn't have required permission.
13629 */
13630 @Override
13631 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13632 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13633 final long identity = Binder.clearCallingIdentity();
13634 try {
13635 mSatelliteController.requestNtnSignalStrength(subId, result);
13636 } finally {
13637 Binder.restoreCallingIdentity(identity);
13638 }
13639 }
13640
13641 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013642 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13643 * is not successful, a {@link ServiceSpecificException} that contains
13644 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013645 *
13646 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013647 * @param callback The callback to handle the NTN signal strength changed event. If the
13648 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13649 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13650 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13651 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013652 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013653 * @throws SecurityException If the caller doesn't have the required permission.
13654 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013655 */
13656 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013657 public void registerForNtnSignalStrengthChanged(int subId,
13658 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013659 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13660 final long identity = Binder.clearCallingIdentity();
13661 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013662 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013663 } finally {
13664 Binder.restoreCallingIdentity(identity);
13665 }
13666 }
13667
13668 /**
13669 * Unregisters for NTN signal strength changed from satellite modem.
13670 * If callback was not registered before, the request will be ignored.
13671 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013672 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13673 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013674 * @param callback The callback that was passed to
13675 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13676 *
13677 * @throws SecurityException if the caller doesn't have the required permission.
13678 */
13679 @Override
13680 public void unregisterForNtnSignalStrengthChanged(
13681 int subId, @NonNull INtnSignalStrengthCallback callback) {
13682 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13683 final long identity = Binder.clearCallingIdentity();
13684 try {
13685 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13686 } finally {
13687 Binder.restoreCallingIdentity(identity);
13688 }
13689 }
13690
13691 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013692 * Registers for satellite capabilities change event from the satellite service.
13693 *
13694 * @param subId The subId of the subscription to request for.
13695 * @param callback The callback to handle the satellite capabilities changed event.
13696 *
13697 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13698 *
13699 * @throws SecurityException if the caller doesn't have required permission.
13700 */
13701 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013702 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013703 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013704 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013705 final long identity = Binder.clearCallingIdentity();
13706 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013707 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013708 } finally {
13709 Binder.restoreCallingIdentity(identity);
13710 }
13711 }
13712
13713 /**
13714 * Unregisters for satellite capabilities change event from the satellite service.
13715 * If callback was not registered before, the request will be ignored.
13716 *
13717 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13718 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013719 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013720 *
13721 * @throws SecurityException if the caller doesn't have required permission.
13722 */
13723 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013724 public void unregisterForCapabilitiesChanged(int subId,
13725 @NonNull ISatelliteCapabilitiesCallback callback) {
13726 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013727 final long identity = Binder.clearCallingIdentity();
13728 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013729 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013730 } finally {
13731 Binder.restoreCallingIdentity(identity);
13732 }
13733 }
13734
13735 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013736 * Registers for the satellite supported state changed.
13737 *
13738 * @param subId The subId of the subscription to register for supported state changed.
13739 * @param callback The callback to handle the satellite supported state changed event.
13740 *
13741 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13742 *
13743 * @throws SecurityException if the caller doesn't have the required permission.
13744 */
13745 @Override
13746 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13747 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13748 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13749 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13750 }
13751
13752 /**
13753 * Unregisters for the satellite supported state changed.
13754 * If callback was not registered before, the request will be ignored.
13755 *
13756 * @param subId The subId of the subscription to unregister for supported state changed.
13757 * @param callback The callback that was passed to
13758 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13759 *
13760 * @throws SecurityException if the caller doesn't have the required permission.
13761 */
13762 @Override
13763 public void unregisterForSatelliteSupportedStateChanged(
13764 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13765 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13766 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13767 }
13768
13769 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013770 * This API can be used by only CTS to update satellite vendor service package name.
13771 *
13772 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013773 * @param provisioned Whether satellite should be provisioned or not.
13774 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013775 * @return {@code true} if the satellite vendor service is set successfully,
13776 * {@code false} otherwise.
13777 */
Hakjun Choic3393242024-06-26 18:02:08 +000013778 public boolean setSatelliteServicePackageName(String servicePackageName,
13779 String provisioned) {
13780 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13781 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013782 TelephonyPermissions.enforceShellOnly(
13783 Binder.getCallingUid(), "setSatelliteServicePackageName");
13784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13785 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13786 "setSatelliteServicePackageName");
Hakjun Choic3393242024-06-26 18:02:08 +000013787 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13788 provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013789 }
13790
13791 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013792 * This API can be used by only CTS to update satellite gateway service package name.
13793 *
13794 * @param servicePackageName The package name of the satellite gateway service.
13795 * @return {@code true} if the satellite gateway service is set successfully,
13796 * {@code false} otherwise.
13797 */
13798 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13799 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13800 TelephonyPermissions.enforceShellOnly(
13801 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13803 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13804 "setSatelliteGatewayServicePackageName");
13805 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13806 }
13807
13808 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013809 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13810 *
13811 * @param packageName The package name of the satellite pointing UI app.
13812 * @param className The class name of the satellite pointing UI app.
13813 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13814 * {@code false} otherwise.
13815 */
13816 public boolean setSatellitePointingUiClassName(
13817 @Nullable String packageName, @Nullable String className) {
13818 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13819 + ", className=" + className);
13820 TelephonyPermissions.enforceShellOnly(
13821 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13823 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13824 "setSatelliteGatewayServicePackageName");
13825 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13826 }
13827
13828 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013829 * This API can be used by only CTS to update the timeout duration in milliseconds that
13830 * satellite should stay at listening mode to wait for the next incoming page before disabling
13831 * listening mode.
13832 *
13833 * @param timeoutMillis The timeout duration in millisecond.
13834 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13835 */
13836 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13837 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13838 TelephonyPermissions.enforceShellOnly(
13839 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13841 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13842 "setSatelliteListeningTimeoutDuration");
13843 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13844 }
13845
13846 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013847 * This API can be used by only CTS to override the timeout durations used by the
13848 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013849 *
13850 * @param timeoutMillis The timeout duration in millisecond.
13851 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13852 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013853 public boolean setDatagramControllerTimeoutDuration(
13854 boolean reset, int timeoutType, long timeoutMillis) {
13855 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13856 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013857 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013858 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13860 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013861 "setDatagramControllerTimeoutDuration");
13862 return mSatelliteController.setDatagramControllerTimeoutDuration(
13863 reset, timeoutType, timeoutMillis);
13864 }
13865
13866 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013867 * This API can be used by only CTS to override the boolean configs used by the
13868 * DatagramController module.
13869 *
13870 * @param enable Whether to enable or disable boolean config.
13871 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13872 */
13873 public boolean setDatagramControllerBooleanConfig(
13874 boolean reset, int booleanType, boolean enable) {
13875 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13876 + ", reset=" + reset + ", enable=" + enable);
13877 TelephonyPermissions.enforceShellOnly(
13878 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13880 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13881 "ssetDatagramControllerBooleanConfig");
13882 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13883 }
13884
13885
13886 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013887 * This API can be used by only CTS to override the timeout durations used by the
13888 * SatelliteController module.
13889 *
13890 * @param timeoutMillis The timeout duration in millisecond.
13891 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13892 */
13893 public boolean setSatelliteControllerTimeoutDuration(
13894 boolean reset, int timeoutType, long timeoutMillis) {
13895 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13896 + reset + ", timeoutMillis=" + timeoutMillis);
13897 TelephonyPermissions.enforceShellOnly(
13898 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13900 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13901 "setSatelliteControllerTimeoutDuration");
13902 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13903 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013904 }
13905
13906 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013907 * This API can be used in only testing to override connectivity status in monitoring emergency
13908 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13909 *
13910 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13911 * of the following values to enable the override:
13912 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13913 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13914 * To disable the override, use -1 for handoverType.
13915 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13916 * delaySeconds after the emergency call starts.
13917 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13918 */
13919 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13920 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13921 TelephonyPermissions.enforceShellOnly(
13922 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13924 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13925 "setEmergencyCallToSatelliteHandoverType");
13926 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13927 handoverType, delaySeconds);
13928 }
13929
13930 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013931 * This API can be used in only testing to override oem-enabled satellite provision status.
13932 *
13933 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13934 * otherwise.
13935 * @param isProvisioned The overriding provision status.
13936 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13937 */
13938 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13939 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13940 + ", isProvisioned=" + isProvisioned);
13941 TelephonyPermissions.enforceShellOnly(
13942 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13944 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13945 "setOemEnabledSatelliteProvisionStatus");
13946 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13947 }
13948
13949 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013950 * This API should be used by only CTS tests to forcefully set telephony country codes.
13951 *
13952 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13953 */
13954 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13955 Map cachedNetworkCountryCodes, String locationCountryCode,
13956 long locationCountryCodeTimestampNanos) {
13957 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13958 + String.join(", ", currentNetworkCountryCodes)
13959 + ", locationCountryCode=" + locationCountryCode
13960 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13961 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13962 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13963 TelephonyPermissions.enforceShellOnly(
13964 Binder.getCallingUid(), "setCachedLocationCountryCode");
13965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13966 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13967 "setCachedLocationCountryCode");
13968 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13969 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13970 locationCountryCodeTimestampNanos);
13971 }
13972
13973 /**
13974 * This API should be used by only CTS tests to override the overlay configs of satellite
13975 * access controller.
13976 *
13977 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13978 * otherwise.
13979 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13980 */
13981 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13982 String s2CellFile, long locationFreshDurationNanos,
13983 List<String> satelliteCountryCodes) {
13984 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13985 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13986 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13987 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13988 ? String.join(", ", satelliteCountryCodes) : null));
13989 TelephonyPermissions.enforceShellOnly(
13990 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13992 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13993 "setSatelliteAccessControlOverlayConfigs");
13994 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13995 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13996 }
13997
13998 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013999 * This API can be used by only CTS to override the cached value for the device overlay config
14000 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14001 * outgoing satellite datagrams should be sent to modem in demo mode.
14002 *
14003 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14004 * satellite modem or not.
14005 *
14006 * @return {@code true} if the operation is successful, {@code false} otherwise.
14007 */
14008 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14009 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14010 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14011 + "disabled");
14012 return false;
14013 }
14014 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14015 TelephonyPermissions.enforceShellOnly(
14016 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14018 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14019 "setShouldSendDatagramToModemInDemoMode");
14020 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14021 shouldSendToModemInDemoMode);
14022 }
14023
14024 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014025 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14026 *
14027 * @param state a state indicates whether satellite access allowed state should be cached and
14028 * the allowed state.
14029 * @return {@code true} if the setting is successful, {@code false} otherwise.
14030 */
14031 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14032 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14033 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14034 + "oemEnabledSatelliteFlag is disabled");
14035 return false;
14036 }
14037
14038 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14039 + "state=" + state);
14040 TelephonyPermissions.enforceShellOnly(
14041 Binder.getCallingUid(),
14042 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14044 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14045 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14046 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14047 state);
14048 }
14049
14050 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014051 * Sets the service defined in ComponentName to be bound.
14052 *
14053 * This should only be used for testing.
14054 * @return {@code true} if the DomainSelectionService to bind to was set,
14055 * {@code false} otherwise.
14056 */
14057 @Override
14058 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14059 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14060
14061 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14062 "setDomainSelectionServiceOverride");
14063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14064 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14065
14066 final long identity = Binder.clearCallingIdentity();
14067 try {
14068 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14069 return DomainSelectionResolver.getInstance()
14070 .setDomainSelectionServiceOverride(componentName);
14071 }
14072 } finally {
14073 Binder.restoreCallingIdentity(identity);
14074 }
14075 return false;
14076 }
14077
14078 /**
14079 * Clears the DomainSelectionService override.
14080 *
14081 * This should only be used for testing.
14082 * @return {@code true} if the DomainSelectionService override was cleared,
14083 * {@code false} otherwise.
14084 */
14085 @Override
14086 public boolean clearDomainSelectionServiceOverride() {
14087 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14088
14089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14090 "clearDomainSelectionServiceOverride");
14091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14092 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14093
14094 final long identity = Binder.clearCallingIdentity();
14095 try {
14096 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14097 return DomainSelectionResolver.getInstance()
14098 .clearDomainSelectionServiceOverride();
14099 }
14100 } finally {
14101 Binder.restoreCallingIdentity(identity);
14102 }
14103 return false;
14104 }
14105
14106 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014107 * Enable or disable notifications sent for cellular identifier disclosure events.
14108 *
14109 * Disclosure events are defined as instances where a device has sent a cellular identifier
14110 * on the Non-access stratum (NAS) before a security context is established. As a result the
14111 * identifier is sent in the clear, which has privacy implications for the user.
14112 *
14113 * @param enable if notifications about disclosure events should be enabled
14114 * @throws SecurityException if the caller does not have the required privileges
14115 * @throws UnsupportedOperationException if the modem does not support this feature.
14116 */
14117 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014118 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014119 enforceModifyPermission();
14120 checkForIdentifierDisclosureNotificationSupport();
14121
14122 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14123 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14124 editor.apply();
14125
14126 // Each phone instance is responsible for updating its respective modem immediately
14127 // after we've made a preference change.
14128 for (Phone phone : PhoneFactory.getPhones()) {
14129 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14130 }
14131 }
14132
14133 /**
14134 * Get whether or not cellular identifier disclosure notifications are enabled.
14135 *
14136 * @throws SecurityException if the caller does not have the required privileges
14137 * @throws UnsupportedOperationException if the modem does not support this feature.
14138 */
14139 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014140 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014141 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14142 checkForIdentifierDisclosureNotificationSupport();
14143 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14144 }
14145
14146 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014147 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14148 * are in use by the cellular modem.
14149 *
14150 * @throws IllegalStateException if the Telephony process is not currently available
14151 * @throws SecurityException if the caller does not have the required privileges
14152 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14153 * and integrity algorithms in use
14154 * @hide
14155 */
14156 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014157 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014158 enforceModifyPermission();
14159 checkForNullCipherNotificationSupport();
14160
14161 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14162 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14163 editor.apply();
14164
14165 // Each phone instance is responsible for updating its respective modem immediately
14166 // after a preference change.
14167 for (Phone phone : PhoneFactory.getPhones()) {
14168 phone.handleNullCipherNotificationPreferenceChanged();
14169 }
14170 }
14171
14172 /**
14173 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14174 * cellular modem.
14175 *
14176 * @throws IllegalStateException if the Telephony process is not currently available
14177 * @throws SecurityException if the caller does not have the required privileges
14178 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14179 * and integrity algorithms in use
14180 * @hide
14181 */
14182 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14183 public boolean isNullCipherNotificationsEnabled() {
14184 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14185 checkForNullCipherNotificationSupport();
14186 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14187 }
14188
14189 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014190 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14191 *
14192 * <p>This method behaves in one of the following ways:
14193 * <ul>
14194 * <li>return true : if the calling package has the appop permission {@link
14195 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14196 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14197 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14198 * Owner device identifier access check, or the calling package has carrier privileges</>
14199 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14200 * </ul>
14201 */
14202 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14203 String callingPackage, @Nullable String callingFeatureId, String message) {
14204 for (Phone phone : PhoneFactory.getPhones()) {
14205 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14206 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14207 return true;
14208 }
14209 }
14210 return false;
14211 }
arunvoddud7401012022-12-15 16:08:12 +000014212
14213 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014214 * @return The subscription manager service instance.
14215 */
14216 public SubscriptionManagerService getSubscriptionManagerService() {
14217 return SubscriptionManagerService.getInstance();
14218 }
14219
14220 /**
arunvoddud7401012022-12-15 16:08:12 +000014221 * Class binds the consumer[callback] and carrierId.
14222 */
14223 private static class CallerCallbackInfo {
14224 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014225 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014226
Steve Statia28b7cb32024-03-11 23:58:50 +000014227 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014228 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014229 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014230 }
14231
14232 public Consumer<Integer> getConsumer() {
14233 return mConsumer;
14234 }
14235
Steve Statia28b7cb32024-03-11 23:58:50 +000014236 public Set<Integer> getCarrierIds() {
14237 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014238 }
14239 }
joonhunshin4ac60942023-11-15 15:23:39 +000014240
14241 /*
14242 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14243 * But the context that is passed in is unused if the phone app is already alive.
14244 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14245 */
14246 @VisibleForTesting
14247 public void setPackageManager(PackageManager packageManager) {
14248 mPackageManager = packageManager;
14249 }
14250
14251 /*
Nate Myren453c3472024-03-13 11:28:11 -070014252 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14253 * But the context that is passed in is unused if the phone app is already alive.
14254 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14255 */
14256 @VisibleForTesting
14257 public void setAppOpsManager(AppOpsManager appOps) {
14258 mAppOps = appOps;
14259 }
14260
14261 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014262 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14263 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14264 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14265 */
14266 @VisibleForTesting
14267 public void setFeatureFlags(FeatureFlags featureFlags) {
14268 mFeatureFlags = featureFlags;
14269 }
14270
14271 /**
14272 * Make sure the device has required telephony feature
14273 *
14274 * @throws UnsupportedOperationException if the device does not have required telephony feature
14275 */
14276 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14277 @NonNull String telephonyFeature, @NonNull String methodName) {
14278 if (callingPackage == null || mPackageManager == null) {
14279 return;
14280 }
14281
14282 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14283 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014284 Binder.getCallingUserHandle())
14285 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14286 // Skip to check associated telephony feature,
14287 // if compatibility change is not enabled for the current process or
14288 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014289 return;
14290 }
14291
14292 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14293 throw new UnsupportedOperationException(
14294 methodName + " is unsupported without " + telephonyFeature);
14295 }
14296 }
youngtaecha5d483d52024-04-29 17:05:45 +000014297
14298 /**
14299 * Registers for the satellite communication allowed state changed.
14300 *
14301 * @param subId The subId of the subscription to register for the satellite communication
14302 * allowed state changed.
14303 * @param callback The callback to handle the satellite communication allowed
14304 * state changed event.
14305 *
14306 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14307 *
14308 * @throws SecurityException if the caller doesn't have the required permission.
14309 */
14310 @Override
14311 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14312 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14313 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14314 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14315 subId, callback);
14316 }
14317
14318 /**
14319 * Unregisters for the satellite communication allowed state changed.
14320 * If callback was not registered before, the request will be ignored.
14321 *
14322 * @param subId The subId of the subscription to unregister for the satellite communication
14323 * allowed state changed.
14324 * @param callback The callback that was passed to
14325 * {@link #registerForCommunicationAllowedStateChanged(int,
14326 * ISatelliteCommunicationAllowedStateCallback)}. *
14327 * @throws SecurityException if the caller doesn't have the required permission.
14328 */
14329 @Override
14330 public void unregisterForCommunicationAllowedStateChanged(
14331 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14332 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14333 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14334 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014335
14336 /**
14337 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14338 *
14339 * @param subId The subId of the subscription to the satellite session stats for.
14340 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14341 * if the request is successful or an error code if the request failed.
14342 *
14343 * @throws SecurityException if the caller doesn't have required permission.
14344 */
14345 @Override
14346 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14347 enforceModifyPermission();
14348 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14349 mSatelliteController.requestSatelliteSessionStats(subId, result);
14350 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014351
14352 /**
14353 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14354 *
14355 * @param result The result receiver, which returns the list of prioritized satellite tokens
14356 * to be used for provision if the request is successful or an error code if the request failed.
14357 *
14358 * @throws SecurityException if the caller doesn't have the required permission.
14359 */
14360 @Override
14361 public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) {
14362 enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds");
14363 mSatelliteController.requestProvisionSubscriberIds(result);
14364 }
14365
14366 /**
14367 * Request to get provisioned status for given a satellite subscriber id.
14368 *
14369 * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check.
14370 * @param result The result receiver, which returns the provisioned status of the token if the
14371 * request is successful or an error code if the request failed.
14372 *
14373 * @throws SecurityException if the caller doesn't have the required permission.
14374 */
14375 @Override
Hyosun Kimc7ae4d52024-07-05 02:44:27 +000014376 public void requestIsProvisioned(@NonNull String satelliteSubscriberId,
14377 @NonNull ResultReceiver result) {
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014378 enforceSatelliteCommunicationPermission("requestIsProvisioned");
14379 mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result);
14380 }
14381
14382 /**
14383 * Deliver the list of provisioned satellite subscriber ids.
14384 *
14385 * @param list List of provisioned satellite subscriber ids.
14386 * @param result The result receiver that returns whether deliver success or fail.
14387 *
14388 * @throws SecurityException if the caller doesn't have the required permission.
14389 */
14390 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014391 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014392 @NonNull ResultReceiver result) {
14393 enforceSatelliteCommunicationPermission("provisionSatellite");
14394 mSatelliteController.provisionSatellite(list, result);
14395 }
Jack Yufa8ed012023-02-11 15:42:28 -080014396}