blob: 5ac898f19c57b70d11547a1f671a159c9e867d0d [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();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004357 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4358 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4359 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004360 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004361
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004362 /**
fionaxu0152e512016-11-14 13:36:14 -08004363 * Sets the voice activation state of a given subId.
4364 */
4365 @Override
4366 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4368 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369
joonhunshin4ac60942023-11-15 15:23:39 +00004370 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4371 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 final Phone phone = getPhone(subId);
4376 if (phone != null) {
4377 phone.setVoiceActivationState(activationState);
4378 } else {
4379 loge("setVoiceActivationState fails with invalid subId: " + subId);
4380 }
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004383 }
4384 }
4385
4386 /**
4387 * Sets the data activation state of a given subId.
4388 */
4389 @Override
4390 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4392 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393
joonhunshin4ac60942023-11-15 15:23:39 +00004394 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4395 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 final Phone phone = getPhone(subId);
4400 if (phone != null) {
4401 phone.setDataActivationState(activationState);
4402 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004403 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 }
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004407 }
4408 }
4409
4410 /**
4411 * Returns the voice activation state of a given subId.
4412 */
4413 @Override
4414 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416
joonhunshin4ac60942023-11-15 15:23:39 +00004417 enforceTelephonyFeatureWithException(callingPackage,
4418 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4419
fionaxu0152e512016-11-14 13:36:14 -08004420 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 if (phone != null) {
4424 return phone.getVoiceActivationState();
4425 } else {
4426 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4427 }
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004430 }
4431 }
4432
4433 /**
4434 * Returns the data activation state of a given subId.
4435 */
4436 @Override
4437 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439
joonhunshin4ac60942023-11-15 15:23:39 +00004440 enforceTelephonyFeatureWithException(callingPackage,
4441 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4442
fionaxu0152e512016-11-14 13:36:14 -08004443 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 if (phone != null) {
4447 return phone.getDataActivationState();
4448 } else {
4449 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4450 }
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004453 }
4454 }
4455
4456 /**
Wink Saville36469e72014-06-11 15:17:00 -07004457 * Returns the unread count of voicemails for a subId
4458 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004460 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4461 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004463 mApp, subId, callingPackage, callingFeatureId,
4464 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004465 return 0;
4466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 final Phone phone = getPhone(subId);
4470 if (phone != null) {
4471 return phone.getVoiceMessageCount();
4472 } else {
4473 return 0;
4474 }
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004478 }
4479
4480 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004481 * returns true, if the device is in a state where both voice and data
4482 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004483 */
4484 @Override
4485 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004486 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4487 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 final long identity = Binder.clearCallingIdentity();
4490 try {
Ling Mac28f0212023-03-24 16:07:15 -07004491 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004495 }
4496
4497 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004498 * Send the dialer code if called from the current default dialer or the caller has
4499 * carrier privilege.
4500 * @param inputCode The dialer code to send
4501 */
4502 @Override
4503 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004504 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004505 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004506 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4507 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004508 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004509 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004510 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512
joonhunshin4ac60942023-11-15 15:23:39 +00004513 enforceTelephonyFeatureWithException(callingPackage,
4514 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004518 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
fionaxu235cc5e2017-03-06 22:25:57 -08004522 }
4523
Pengquan Menga1bb6272018-09-06 09:59:22 -07004524 @Override
4525 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004526 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004527 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4528 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004529
4530 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4531 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4532
shilufc958392020-01-20 11:36:01 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 if (!isActiveSubscription(subId)) {
4536 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4537 }
4538 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4539 } finally {
4540 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004542 }
4543
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004545 public boolean isInEmergencySmsMode() {
4546 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004547
4548 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4549 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4550
Brad Ebingerb2b65522019-03-15 13:48:47 -07004551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 for (Phone phone : PhoneFactory.getPhones()) {
4554 if (phone.isInEmergencySmsMode()) {
4555 return true;
4556 }
4557 }
4558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
4561 return false;
4562 }
4563
shilu366312e2019-12-17 09:28:10 -08004564 /**
4565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4566 * @param subId The subscription to use to check the configuration.
4567 * @param c The callback that will be used to send the result.
4568 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004569 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004570 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4571 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004572 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004573 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004574
4575 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4577 "IMS not available on device.");
4578 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 final long token = Binder.clearCallingIdentity();
4580 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004581 int slotId = getSlotIndexOrException(subId);
4582 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004583
4584 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4585 if (controller != null) {
4586 ImsManager imsManager = controller.getImsManager(subId);
4587 if (imsManager != null) {
4588 imsManager.addRegistrationCallbackForSubscription(c, subId);
4589 } else {
4590 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4591 }
4592 } else {
4593 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4594 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004595 } catch (ImsException e) {
4596 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004597 } finally {
4598 Binder.restoreCallingIdentity(token);
4599 }
4600 }
4601
shilu366312e2019-12-17 09:28:10 -08004602 /**
4603 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4604 * @param subId The subscription to use to check the configuration.
4605 * @param c The callback that will be used to send the result.
4606 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004608 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004609 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004610 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4612 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4613 }
Meng Wangafbc5852019-09-19 17:37:13 -07004614 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004615
Meng Wangafbc5852019-09-19 17:37:13 -07004616 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004617 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4618 if (controller != null) {
4619 ImsManager imsManager = controller.getImsManager(subId);
4620 if (imsManager != null) {
4621 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4622 } else {
4623 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4624 + "is inactive, ignoring unregister.");
4625 // If the ImsManager is not valid, just return, since the callback
4626 // will already have been removed internally.
4627 }
4628 }
Meng Wangafbc5852019-09-19 17:37:13 -07004629 } finally {
4630 Binder.restoreCallingIdentity(token);
4631 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 }
4633
Brad Ebingera34a6c22019-10-22 17:36:18 -07004634 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004635 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4636 * @param subId The subscription to use to check the configuration.
4637 * @param c The callback that will be used to send the result.
4638 */
4639 @Override
4640 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4641 throws RemoteException {
4642 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4643 mApp, subId, "registerImsEmergencyRegistrationCallback");
4644
4645 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4647 "IMS not available on device.");
4648 }
4649 final long token = Binder.clearCallingIdentity();
4650 try {
4651 int slotId = getSlotIndexOrException(subId);
4652 verifyImsMmTelConfiguredOrThrow(slotId);
4653
4654 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4655 if (controller != null) {
4656 ImsManager imsManager = controller.getImsManager(subId);
4657 if (imsManager != null) {
4658 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4659 } else {
4660 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4661 }
4662 } else {
4663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4664 }
4665 } catch (ImsException e) {
4666 throw new ServiceSpecificException(e.getCode());
4667 } finally {
4668 Binder.restoreCallingIdentity(token);
4669 }
4670 }
4671
4672 /**
4673 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4674 * @param subId The subscription to use to check the configuration.
4675 * @param c The callback that will be used to send the result.
4676 */
4677 @Override
4678 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4679 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4680 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4681 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4682 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4683 }
4684 final long token = Binder.clearCallingIdentity();
4685
4686 try {
4687 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4688 if (controller != null) {
4689 ImsManager imsManager = controller.getImsManager(subId);
4690 if (imsManager != null) {
4691 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4692 } else {
4693 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4694 + "is inactive, ignoring unregister.");
4695 // If the ImsManager is not valid, just return, since the callback
4696 // will already have been removed internally.
4697 }
4698 }
4699 } finally {
4700 Binder.restoreCallingIdentity(token);
4701 }
4702 }
4703
4704 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004705 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4706 */
4707 @Override
4708 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4709 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4710 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4712 "IMS not available on device.");
4713 }
4714 final long token = Binder.clearCallingIdentity();
4715 try {
4716 Phone phone = getPhone(subId);
4717 if (phone == null) {
4718 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4719 + subId + "'");
4720 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4721 }
4722 phone.getImsRegistrationState(regState -> {
4723 try {
4724 consumer.accept((regState == null)
4725 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4726 } catch (RemoteException e) {
4727 // Ignore if the remote process is no longer available to call back.
4728 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4729 }
4730 });
4731 } finally {
4732 Binder.restoreCallingIdentity(token);
4733 }
4734 }
4735
4736 /**
4737 * Get the transport type for the IMS service registration state.
4738 */
4739 @Override
4740 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004742 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004743 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4744 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4745 "IMS not available on device.");
4746 }
4747 final long token = Binder.clearCallingIdentity();
4748 try {
4749 Phone phone = getPhone(subId);
4750 if (phone == null) {
4751 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4752 + subId + "'");
4753 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4754 }
4755 phone.getImsRegistrationTech(regTech -> {
4756 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4757 int regTechConverted = (regTech == null)
4758 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4759 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4760 regTechConverted);
4761 try {
4762 consumer.accept(regTechConverted);
4763 } catch (RemoteException e) {
4764 // Ignore if the remote process is no longer available to call back.
4765 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4766 }
4767 });
4768 } finally {
4769 Binder.restoreCallingIdentity(token);
4770 }
4771 }
4772
shilu366312e2019-12-17 09:28:10 -08004773 /**
4774 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4775 * @param subId The subscription to use to check the configuration.
4776 * @param c The callback that will be used to send the result.
4777 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004779 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4780 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004782 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004783 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4785 "IMS not available on device.");
4786 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 final long token = Binder.clearCallingIdentity();
4788 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004789 int slotId = getSlotIndexOrException(subId);
4790 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004791
4792 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4793 if (controller != null) {
4794 ImsManager imsManager = controller.getImsManager(subId);
4795 if (imsManager != null) {
4796 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4797 } else {
4798 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4799 }
4800 } else {
4801 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4802 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004803 } catch (ImsException e) {
4804 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 } finally {
4806 Binder.restoreCallingIdentity(token);
4807 }
4808 }
4809
shilu366312e2019-12-17 09:28:10 -08004810 /**
4811 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4812 * @param subId The subscription to use to check the configuration.
4813 * @param c The callback that will be used to send the result.
4814 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004815 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004816 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004817 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004818 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4820 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4821 }
Meng Wangafbc5852019-09-19 17:37:13 -07004822
4823 final long token = Binder.clearCallingIdentity();
4824 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004825 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4826 if (controller != null) {
4827 ImsManager imsManager = controller.getImsManager(subId);
4828 if (imsManager != null) {
4829 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4830 } else {
4831 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4832 + " is inactive, ignoring unregister.");
4833 // If the ImsManager is not valid, just return, since the callback
4834 // will already have been removed internally.
4835 }
4836 }
Meng Wangafbc5852019-09-19 17:37:13 -07004837 } finally {
4838 Binder.restoreCallingIdentity(token);
4839 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 }
4841
4842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004843 public boolean isCapable(int subId, int capability, int regTech) {
4844 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004845
4846 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4847 FEATURE_TELEPHONY_IMS, "isCapable");
4848
Brad Ebinger35c841c2018-10-01 10:40:55 -07004849 final long token = Binder.clearCallingIdentity();
4850 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004851 int slotId = getSlotIndexOrException(subId);
4852 verifyImsMmTelConfiguredOrThrow(slotId);
4853 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4854 } catch (com.android.ims.ImsException e) {
4855 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4856 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004857 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004858 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4859 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 } finally {
4861 Binder.restoreCallingIdentity(token);
4862 }
4863 }
4864
4865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004866 public boolean isAvailable(int subId, int capability, int regTech) {
4867 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004868
4869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4870 FEATURE_TELEPHONY_IMS, "isAvailable");
4871
Brad Ebinger35c841c2018-10-01 10:40:55 -07004872 final long token = Binder.clearCallingIdentity();
4873 try {
4874 Phone phone = getPhone(subId);
4875 if (phone == null) return false;
4876 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004877 } catch (com.android.ims.ImsException e) {
4878 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4879 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 } finally {
4881 Binder.restoreCallingIdentity(token);
4882 }
4883 }
4884
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004885 /**
4886 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4887 * subscription.
4888 * @param subId The subscription to use to check the configuration.
4889 * @param callback The callback that will be used to send the result.
4890 * @param capability The MmTelFeature capability that will be used to send the result.
4891 * @param transportType The transport type of the MmTelFeature capability.
4892 */
4893 @Override
4894 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4895 int transportType) {
4896 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004897 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4898 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4899 "IMS not available on device.");
4900 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004901 final long token = Binder.clearCallingIdentity();
4902 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004903 int slotId = getSlotIndex(subId);
4904 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4905 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4906 + subId + "'");
4907 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4908 }
4909 verifyImsMmTelConfiguredOrThrow(slotId);
4910 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4911 transportType, aBoolean -> {
4912 try {
4913 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4914 } catch (RemoteException e) {
4915 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4916 + "running. Ignore");
4917 }
4918 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 } catch (ImsException e) {
4920 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004921 } finally {
4922 Binder.restoreCallingIdentity(token);
4923 }
4924 }
4925
shilu366312e2019-12-17 09:28:10 -08004926 /**
4927 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4928 * @param subId The subscription to use to check the configuration.
4929 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004930 @Override
4931 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004932 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004933 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004934
joonhunshin4ac60942023-11-15 15:23:39 +00004935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4936 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4937
Brad Ebinger35c841c2018-10-01 10:40:55 -07004938 final long token = Binder.clearCallingIdentity();
4939 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004941 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004942 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (ImsException e) {
4944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004945 } finally {
4946 Binder.restoreCallingIdentity(token);
4947 }
4948 }
4949
4950 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004951 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004953 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004954
4955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4956 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4957
Brad Ebinger35c841c2018-10-01 10:40:55 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004960 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004961 // This setting doesn't require an active ImsService connection, so do not verify. The
4962 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004964 } catch (ImsException e) {
4965 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
shilu366312e2019-12-17 09:28:10 -08004971 /**
4972 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4973 * @param subId The subscription to use to check the configuration.
4974 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004975 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004976 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004978 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004979
4980 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4981 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4982
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004986 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004988 } catch (ImsException e) {
4989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
4993 }
4994
4995 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004996 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004998 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004999
5000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5001 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5002
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 final long identity = Binder.clearCallingIdentity();
5004 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005005 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005006 // This setting doesn't require an active ImsService connection, so do not verify. The
5007 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005008 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005009 } catch (ImsException e) {
5010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
5014 }
5015
shilu366312e2019-12-17 09:28:10 -08005016 /**
5017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5018 * @param subId The subscription to use to check the configuration.
5019 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005020 @Override
5021 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005022 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005023 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005024
5025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5026 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5027
Brad Ebinger35c841c2018-10-01 10:40:55 -07005028 final long identity = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005031 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005033 } catch (ImsException e) {
5034 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
5038 }
5039
5040 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005041 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005043 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005044
5045 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5046 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5047
Brad Ebinger35c841c2018-10-01 10:40:55 -07005048 final long identity = Binder.clearCallingIdentity();
5049 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005050 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005051 // This setting doesn't require an active ImsService connection, so do not verify. The
5052 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005053 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 } catch (ImsException e) {
5055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005056 } finally {
5057 Binder.restoreCallingIdentity(identity);
5058 }
5059 }
5060
shilu366312e2019-12-17 09:28:10 -08005061 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005062 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5064 * @param subId The subscription to use to check the configuration.
5065 */
5066 @Override
5067 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005068 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005069 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005070
5071 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5072 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5073
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005076 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005077 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005078 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005079 } catch (ImsException e) {
5080 throw new ServiceSpecificException(e.getCode());
5081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
5084 }
5085
5086 /**
5087 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5088 * Requires MODIFY_PHONE_STATE permission.
5089 * @param subId The subscription to use to check the configuration.
5090 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5091 * false otherwise
5092 */
5093 @Override
5094 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5096 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005097
5098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5099 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5100
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005103 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005104 // This setting doesn't require an active ImsService connection, so do not verify. The
5105 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005106 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005107 } catch (ImsException e) {
5108 throw new ServiceSpecificException(e.getCode());
5109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
5112 }
5113
5114 /**
shilu366312e2019-12-17 09:28:10 -08005115 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5116 * @param subId The subscription to use to check the configuration.
5117 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005119
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005121 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005122 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005123
5124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5125 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5126
Brad Ebinger35c841c2018-10-01 10:40:55 -07005127 final long identity = Binder.clearCallingIdentity();
5128 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005130 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005132 } catch (ImsException e) {
5133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
5137 }
5138
5139 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005140 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005142 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005143
5144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5145 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5146
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005150 // This setting doesn't require an active ImsService connection, so do not verify. The
5151 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005152 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005153 } catch (ImsException e) {
5154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
5160 @Override
5161 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5163 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005164
5165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5166 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5167
Brad Ebinger35c841c2018-10-01 10:40:55 -07005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005171 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005172 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005173 } catch (ImsException e) {
5174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
5178 }
5179
shilu366312e2019-12-17 09:28:10 -08005180 /**
5181 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5182 * @param subId The subscription to use to check the configuration.
5183 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 @Override
5185 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005186 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005187 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005188
5189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5190 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5191
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005195 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005196 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005197 } catch (ImsException e) {
5198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 @Override
5205 public void setVoWiFiModeSetting(int subId, int mode) {
5206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5207 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005208
5209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5210 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5211
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 final long identity = Binder.clearCallingIdentity();
5213 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005214 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005215 // This setting doesn't require an active ImsService connection, so do not verify. The
5216 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005217 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005218 } catch (ImsException e) {
5219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
5223 }
5224
5225 @Override
5226 public int getVoWiFiRoamingModeSetting(int subId) {
5227 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005228
5229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5230 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5231
Brad Ebinger35c841c2018-10-01 10:40:55 -07005232 final long identity = Binder.clearCallingIdentity();
5233 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005235 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005236 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005237 } catch (ImsException e) {
5238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
5242 }
5243
5244 @Override
5245 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5247 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005248
5249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5250 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5251
Brad Ebinger35c841c2018-10-01 10:40:55 -07005252 final long identity = Binder.clearCallingIdentity();
5253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005255 // This setting doesn't require an active ImsService connection, so do not verify. The
5256 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005257 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005258 } catch (ImsException e) {
5259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
5264
5265 @Override
5266 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5268 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005269
5270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5271 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5272
Brad Ebinger35c841c2018-10-01 10:40:55 -07005273 final long identity = Binder.clearCallingIdentity();
5274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005276 // This setting doesn't require an active ImsService connection, so do not verify. The
5277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005278 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005279 } catch (ImsException e) {
5280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
shilu366312e2019-12-17 09:28:10 -08005286 /**
5287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5288 * @param subId The subscription to use to check the configuration.
5289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005290 @Override
5291 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005293 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005294
5295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5296 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5297
Brad Ebinger35c841c2018-10-01 10:40:55 -07005298 final long identity = Binder.clearCallingIdentity();
5299 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005300 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005301 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005302 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005303 } catch (ImsException e) {
5304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
5308 }
5309
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005310 @Override
5311 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5312 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005313
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005314 final long identity = Binder.clearCallingIdentity();
5315 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005316 if (!isImsAvailableOnDevice()) {
5317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5318 "IMS not available on device.");
5319 }
5320 int slotId = getSlotIndexOrException(subId);
5321 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005322
5323 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5324 if (controller != null) {
5325 ImsManager imsManager = controller.getImsManager(subId);
5326 if (imsManager != null) {
5327 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5328 } else {
5329 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5330 }
5331 } else {
5332 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5333 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005334 } catch (ImsException e) {
5335 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
5339 }
5340
5341 @Override
5342 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5343 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005344
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005345 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5348 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005349 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005350 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5351 if (controller != null) {
5352 ImsManager imsManager = controller.getImsManager(subId);
5353 if (imsManager != null) {
5354 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5355 } else {
5356 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5357 + " is inactive, ignoring unregister.");
5358 // If the ImsManager is not valid, just return, since the callback will already
5359 // have been removed internally.
5360 }
5361 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
5365 }
5366
joonhunshincffb7fc2021-11-28 07:32:01 +00005367 @Override
5368 public void registerFeatureProvisioningChangedCallback(int subId,
5369 IFeatureProvisioningCallback callback) {
5370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5371 mApp, subId, "registerFeatureProvisioningChangedCallback");
5372
5373 final long identity = Binder.clearCallingIdentity();
5374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5375 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5376 }
5377
joonhunshin91bc1952022-04-29 08:47:15 +00005378 try {
5379 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5380 if (controller == null) {
5381 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5382 "Device does not support IMS");
5383 }
5384 controller.addFeatureProvisioningChangedCallback(subId, callback);
5385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005388 }
5389
5390 @Override
5391 public void unregisterFeatureProvisioningChangedCallback(int subId,
5392 IFeatureProvisioningCallback callback) {
5393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5394 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5395
5396 final long identity = Binder.clearCallingIdentity();
5397 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5398 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5399 }
5400
joonhunshin91bc1952022-04-29 08:47:15 +00005401 try {
5402 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5403 if (controller == null) {
5404 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5405 return;
5406 }
5407 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005411 }
allenwtsu99c623b2020-01-03 18:24:23 +08005412
5413 private void checkModifyPhoneStatePermission(int subId, String message) {
5414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5415 message);
5416 }
5417
allenwtsu99c623b2020-01-03 18:24:23 +08005418 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005419 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005420 boolean isProvisioned) {
5421 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5422
joonhunshin4ac60942023-11-15 15:23:39 +00005423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5424 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5425
allenwtsu99c623b2020-01-03 18:24:23 +08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005428 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5429 if (controller == null) {
5430 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5431 return;
5432 }
5433 controller.setRcsProvisioningStatusForCapability(
5434 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
allenwtsu99c623b2020-01-03 18:24:23 +08005438 }
5439
5440
5441 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005442 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5444 mApp, subId, "getRcsProvisioningStatusForCapability");
5445
joonhunshin4ac60942023-11-15 15:23:39 +00005446 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5447 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5448
allenwtsu99c623b2020-01-03 18:24:23 +08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005451 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5452 if (controller == null) {
5453 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5454
5455 // device does not support IMS, this method will return true always.
5456 return true;
5457 }
5458 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
5462 }
5463
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005464 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005465 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5466 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005467 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005468
joonhunshin4ac60942023-11-15 15:23:39 +00005469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5470 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5471
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005472 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005473 final long identity = Binder.clearCallingIdentity();
5474 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005475 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5476 if (controller == null) {
5477 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5478 return;
5479 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005480 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005481 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
5484 }
5485 }
5486
5487 @Override
5488 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5490 mApp, subId, "getProvisioningStatusForCapability");
5491
joonhunshin4ac60942023-11-15 15:23:39 +00005492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5493 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5494
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005495 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496 final long identity = Binder.clearCallingIdentity();
5497 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005498 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5499 if (controller == null) {
5500 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005501
joonhunshin91bc1952022-04-29 08:47:15 +00005502 // device does not support IMS, this method will return true always.
5503 return true;
5504 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005505 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5506 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
5510 }
5511
5512 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005513 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5515 mApp, subId, "isProvisioningRequiredForCapability");
5516
joonhunshin4ac60942023-11-15 15:23:39 +00005517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5518 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5519
joonhunshincffb7fc2021-11-28 07:32:01 +00005520 final long identity = Binder.clearCallingIdentity();
5521 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005522 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5523 if (controller == null) {
5524 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5525
5526 // device does not support IMS, this method will return false
5527 return false;
5528 }
5529 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533 }
5534
5535 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005536 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5537 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5538 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005539
joonhunshin4ac60942023-11-15 15:23:39 +00005540 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5541 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5542
joonhunshincffb7fc2021-11-28 07:32:01 +00005543 final long identity = Binder.clearCallingIdentity();
5544 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005545 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5546 if (controller == null) {
5547 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5548
5549 // device does not support IMS, this method will return false
5550 return false;
5551 }
5552 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005556 }
5557
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005558 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005559 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5561 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5562 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005563 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5564 mApp, subId, "getImsProvisioningInt");
5565
joonhunshin4ac60942023-11-15 15:23:39 +00005566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5567 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5568
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005569 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005573 int slotId = getSlotIndex(subId);
5574 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5575 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5576 + subId + "' for key:" + key);
5577 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5578 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005579
joonhunshin91bc1952022-04-29 08:47:15 +00005580 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5581 if (controller == null) {
5582 loge("getImsProvisioningInt: Device does not support IMS");
5583
5584 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5585 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5586 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005587 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5588 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005589 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5590 return retVal;
5591 }
5592
calvinpanb5a34062021-02-08 19:59:36 +08005593 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005594 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005595 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5596 + subId + "' for key:" + key);
5597 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
5601 }
5602
5603 @Override
5604 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5606 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5607 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5609 mApp, subId, "getImsProvisioningString");
5610
joonhunshin4ac60942023-11-15 15:23:39 +00005611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5612 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5613
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005617 int slotId = getSlotIndex(subId);
5618 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5619 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5620 + subId + "' for key:" + key);
5621 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5622 }
calvinpanb5a34062021-02-08 19:59:36 +08005623 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005624 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005625 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5626 + subId + "' for key:" + key);
5627 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
5631 }
5632
5633 @Override
5634 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5636 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5637 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5639 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005640
joonhunshin4ac60942023-11-15 15:23:39 +00005641 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5642 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5643
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005644 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005648 int slotId = getSlotIndex(subId);
5649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5650 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5651 + subId + "' for key:" + key);
5652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5653 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005654
joonhunshin91bc1952022-04-29 08:47:15 +00005655 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5656 if (controller == null) {
5657 loge("setImsProvisioningInt: Device does not support IMS");
5658
5659 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5660 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5661 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005662 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5663 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005664 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5665 return retVal;
5666 }
5667
calvinpanb5a34062021-02-08 19:59:36 +08005668 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5669 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005670 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005671 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005672 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
5676 }
5677
5678 @Override
5679 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5681 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5682 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5684 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005685
5686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5687 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5688
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005692 int slotId = getSlotIndex(subId);
5693 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5694 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5695 + subId + "' for key:" + key);
5696 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5697 }
calvinpanb5a34062021-02-08 19:59:36 +08005698 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5699 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005700 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005701 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005702 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
5706 }
5707
Brad Ebinger919631e2021-06-02 17:46:35 -07005708 /**
5709 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5710 * for the given slot ID or no ImsResolver instance has been created.
5711 * @param slotId The slot ID that the IMS service is created for.
5712 * @throws ImsException If there is no ImsService configured for this slot.
5713 */
5714 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5715 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5716 ImsFeature.FEATURE_MMTEL)) {
5717 throw new ImsException("This subscription does not support MMTEL over IMS",
5718 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5719 }
5720 }
5721
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005722 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005723 int slotId = SubscriptionManager.getSlotIndex(subId);
5724 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005725 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5726 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005727 }
5728 return slotId;
5729 }
5730
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005731 private int getSlotIndex(int subId) {
5732 int slotId = SubscriptionManager.getSlotIndex(subId);
5733 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5734 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5735 }
5736 return slotId;
5737 }
5738
Wink Saville36469e72014-06-11 15:17:00 -07005739 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005740 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005741 */
5742 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005743 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5744 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005745 try {
5746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5747 } catch (SecurityException se) {
5748 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5749 throw new SecurityException("Package " + callingPackage + " does not belong to "
5750 + Binder.getCallingUid());
5751 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005752 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005753 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005754 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005755 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005756 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005757 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005758 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5760 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005761
joonhunshin4ac60942023-11-15 15:23:39 +00005762 enforceTelephonyFeatureWithException(callingPackage,
5763 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 final Phone phone = getPhone(subId);
5768 if (phone != null) {
5769 return phone.getServiceState().getDataNetworkType();
5770 } else {
5771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5772 }
5773 } finally {
5774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005776 }
5777
5778 /**
5779 * Returns the data network type
5780 */
5781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005783 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005784 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005785 }
5786
5787 /**
5788 * Returns the data network type for a subId
5789 */
5790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005791 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5792 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005793 String functionName = "getDataNetworkTypeForSubscriber";
5794 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5795 mApp, functionName)) {
5796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5797 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5798 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5799 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005800 }
5801
joonhunshin4ac60942023-11-15 15:23:39 +00005802 enforceTelephonyFeatureWithException(callingPackage,
5803 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 final Phone phone = getPhone(subId);
5808 if (phone != null) {
5809 return phone.getServiceState().getDataNetworkType();
5810 } else {
5811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5812 }
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005816 }
5817
5818 /**
Wink Saville36469e72014-06-11 15:17:00 -07005819 * Returns the Voice network type for a subId
5820 */
5821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005822 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5823 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005824 String functionName = "getVoiceNetworkTypeForSubscriber";
5825 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5826 mApp, functionName)) {
5827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5828 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5829 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5830 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005831 }
5832
joonhunshin4ac60942023-11-15 15:23:39 +00005833 enforceTelephonyFeatureWithException(callingPackage,
5834 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 final long identity = Binder.clearCallingIdentity();
5837 try {
5838 final Phone phone = getPhone(subId);
5839 if (phone != null) {
5840 return phone.getServiceState().getVoiceNetworkType();
5841 } else {
5842 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5843 }
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005847 }
5848
5849 /**
5850 * @return true if a ICC card is present
5851 */
5852 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005853 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005854 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005855 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005856 }
5857
5858 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005859 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005860 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005861 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005862 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005863 if (!mApp.getResources().getBoolean(
5864 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5865 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5866 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5867 }
joonhunshin4ac60942023-11-15 15:23:39 +00005868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 final Phone phone = PhoneFactory.getPhone(slotIndex);
5872 if (phone != null) {
5873 return phone.getIccCard().hasIccCard();
5874 } else {
5875 return false;
5876 }
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005880 }
5881
5882 /**
5883 * Return if the current radio is LTE on CDMA. This
5884 * is a tri-state return value as for a period of time
5885 * the mode may be unknown.
5886 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005887 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005888 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005889 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005890 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005892 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5893 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5894 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005895 }
5896
Sanket Padawe356d7632015-06-22 14:03:32 -07005897 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005898 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5899 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005900 try {
5901 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5902 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005903 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5904 }
5905
joonhunshin4ac60942023-11-15 15:23:39 +00005906 enforceTelephonyFeatureWithException(callingPackage,
5907 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 final Phone phone = getPhone(subId);
5912 if (phone == null) {
5913 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5914 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005915 return TelephonyProperties.lte_on_cdma_device()
5916 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 }
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005920 }
Wink Saville36469e72014-06-11 15:17:00 -07005921 }
5922
Wink Saville36469e72014-06-11 15:17:00 -07005923 /**
5924 * {@hide}
5925 * Returns Default subId, 0 in the case of single standby.
5926 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005927 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005928 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005929 }
5930
Shishir Agrawala9f32182016-04-12 12:00:16 -07005931 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005932 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005933 }
5934
Wink Savilleb564aae2014-10-23 10:18:09 -07005935 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005936 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005937 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005938
Pengquan Menge92a50d2018-09-21 15:54:48 -07005939 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005940 return getSubscriptionManagerService().isActiveSubId(subId,
5941 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005942 }
5943
Ihab Awadf2177b72013-11-25 13:33:23 -08005944 /**
5945 * @see android.telephony.TelephonyManager.WifiCallingChoices
5946 */
5947 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005950 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5952 getWhenToMakeWifiCallsDefaultPreference());
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005956 }
5957
5958 /**
5959 * @see android.telephony.TelephonyManager.WifiCallingChoices
5960 */
5961 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005965 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005970 }
5971
Sailesh Nepald1e68152013-12-12 19:08:02 -08005972 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005973 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005974 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005975 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005976
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005977 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5978 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5979 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005980 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005981 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005982 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005983 }
5984 return PhoneFactory.getPhone(phoneId);
5985 }
5986
Shishir Agrawal566b7612013-10-28 14:41:00 -07005987 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005988 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005989 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005990
Rambo Wanga1782702021-11-10 20:15:19 -08005991 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5992 /*message=*/ "iccOpenLogicalChannel");
5993
5994 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5995 // Verify that the callingPackage in the request belongs to the calling UID
5996 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5997
joonhunshin4ac60942023-11-15 15:23:39 +00005998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5999 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6000
Rambo Wanga1782702021-11-10 20:15:19 -08006001 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006002 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006003
Rambo Wanga1782702021-11-10 20:15:19 -08006004 private Phone getPhoneFromValidIccLogicalChannelRequest(
6005 @NonNull IccLogicalChannelRequest request, String message) {
6006 Phone phone;
6007 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, request.subId, message);
6010 phone = getPhoneFromSubId(request.subId);
6011 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6012 enforceModifyPermission();
6013 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6014 } else {
6015 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006016 }
Rambo Wanga1782702021-11-10 20:15:19 -08006017 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006018 }
6019
6020 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006021 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 final long identity = Binder.clearCallingIdentity();
6023 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006024 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6027 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006028 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6029 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 loge("The calling package is not allowed to access ISD-R.");
6031 throw new SecurityException(
6032 "The calling package is not allowed to access ISD-R.");
6033 }
Derek Tan740e1672017-06-27 14:56:27 -07006034 }
Derek Tan740e1672017-06-27 14:56:27 -07006035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006037 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6038 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 return response;
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006043 }
6044
6045 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006046 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6048 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6049
Rambo Wanga1782702021-11-10 20:15:19 -08006050 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6051 /*message=*/"iccCloseLogicalChannel");
6052
6053 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6054
6055 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006056 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006057
Rambo Wanga1782702021-11-10 20:15:19 -08006058 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6059 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006060 // before this feature is enabled, this API should only return false if
6061 // the operation fails instead of throwing runtime exception for
6062 // backward-compatibility.
6063 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6064 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006067 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006068 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 }
Chen Xue9d737e2022-01-01 23:41:31 -08006070 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006071 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006072 Boolean success = false;
6073 if (result instanceof RuntimeException) {
6074 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006075 if (shouldThrowExceptionOnFailure) {
6076 throw (RuntimeException) result;
6077 } else {
6078 return false;
6079 }
Chen Xue9d737e2022-01-01 23:41:31 -08006080 } else if (result instanceof Boolean) {
6081 success = (Boolean) result;
6082 } else {
6083 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6084 }
Rambo Wanga1782702021-11-10 20:15:19 -08006085 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 return success;
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090 }
6091
6092 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006093 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006094 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6096 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006097
6098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6099 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6100
Jordan Liu4c733742019-02-28 12:03:40 -08006101 if (DBG) {
6102 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6103 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6104 + p3 + " data=" + data);
6105 }
6106 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6107 command, p1, p2, p3, data);
6108 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006109
Jordan Liu4c733742019-02-28 12:03:40 -08006110 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006111 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006112 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006113 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006114
6115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6117 "iccTransmitApduLogicalChannelBySlot");
6118
Jordan Liu4c733742019-02-28 12:03:40 -08006119 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006120 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006121 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6122 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006123 }
6124 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006125 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6126 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006127 }
6128
6129 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6130 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 final long identity = Binder.clearCallingIdentity();
6132 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006133 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 return "";
6135 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006138 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6139 null /* workSource */);
6140 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 // Append the returned status code to the end of the response payload.
6143 String s = Integer.toHexString(
6144 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6145 if (response.payload != null) {
6146 s = IccUtils.bytesToHexString(response.payload) + s;
6147 }
6148 return s;
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006151 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006152 }
Jake Hambye994d462014-02-03 13:10:13 -08006153
Evan Charltonc66da362014-05-16 14:06:40 -07006154 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006155 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6156 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006160
6161 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6162 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6163
Jordan Liu4c733742019-02-28 12:03:40 -08006164 if (DBG) {
6165 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6166 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6167 }
6168 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6169 cla, command, p1, p2, p3, data);
6170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006171
Jordan Liu4c733742019-02-28 12:03:40 -08006172 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006173 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006174 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006175 enforceModifyPermission();
6176 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006177
6178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6179 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6180
Jordan Liu4c733742019-02-28 12:03:40 -08006181 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006182 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006183 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6184 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006185 }
6186
6187 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006188 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6189 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006190 }
6191
6192 // open APDU basic channel assuming the caller has sufficient permissions
6193 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6194 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6198 && TextUtils.equals(ISDR_AID, data)) {
6199 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006200 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6201 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 if (bestComponent == null
6203 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6204 loge("The calling package is not allowed to select ISD-R.");
6205 throw new SecurityException(
6206 "The calling package is not allowed to select ISD-R.");
6207 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006208 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006211 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6212 null /* workSource */);
6213 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 // Append the returned status code to the end of the response payload.
6216 String s = Integer.toHexString(
6217 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6218 if (response.payload != null) {
6219 s = IccUtils.bytesToHexString(response.payload) + s;
6220 }
6221 return s;
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006224 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006225 }
6226
6227 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006228 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006229 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6231 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006232
joonhunshin4ac60942023-11-15 15:23:39 +00006233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6234 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 final long identity = Binder.clearCallingIdentity();
6237 try {
6238 if (DBG) {
6239 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6240 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6241 }
6242
6243 IccIoResult response =
6244 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6245 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6246 subId);
6247
6248 if (DBG) {
6249 log("Exchange SIM_IO [R]" + response);
6250 }
6251
6252 byte[] result = null;
6253 int length = 2;
6254 if (response.payload != null) {
6255 length = 2 + response.payload.length;
6256 result = new byte[length];
6257 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6258 } else {
6259 result = new byte[length];
6260 }
6261
6262 result[length - 1] = (byte) response.sw2;
6263 result[length - 2] = (byte) response.sw1;
6264 return result;
6265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006267 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006268 }
6269
Nathan Haroldb3014052017-01-25 15:57:32 -08006270 /**
6271 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6272 * on a particular subscription
6273 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006274 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6275 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006277 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006278 return null;
6279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280
joonhunshin4ac60942023-11-15 15:23:39 +00006281 enforceTelephonyFeatureWithException(callingPackage,
6282 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 if (appType != TelephonyManager.APPTYPE_USIM
6287 && appType != TelephonyManager.APPTYPE_SIM) {
6288 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6289 return null;
6290 }
6291 Object response = sendRequest(
6292 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6293 if (response instanceof String[]) {
6294 return (String[]) response;
6295 }
yincheng zhao2737e882019-09-06 17:06:54 -07006296 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006298 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 } finally {
6300 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006301 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006302 }
6303
yincheng zhao2737e882019-09-06 17:06:54 -07006304 /**
6305 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6306 * subscription.
6307 *
6308 * @param subId the id of the subscription.
6309 * @param appType the uicc app type, must be USIM or SIM.
6310 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6311 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006312 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006313 * @return number of fplmns that is successfully written to the SIM.
6314 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006315 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6316 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6318 mApp, subId, "setForbiddenPlmns");
6319
joonhunshin4ac60942023-11-15 15:23:39 +00006320 enforceTelephonyFeatureWithException(callingPackage,
6321 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6322
yincheng zhao2737e882019-09-06 17:06:54 -07006323 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6324 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6325 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6326 }
6327 if (fplmns == null) {
6328 throw new IllegalArgumentException("Fplmn List provided is null");
6329 }
6330 for (String fplmn : fplmns) {
6331 if (!CellIdentity.isValidPlmn(fplmn)) {
6332 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6333 }
6334 }
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 Object response = sendRequest(
6338 CMD_SET_FORBIDDEN_PLMNS,
6339 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6340 subId);
6341 return (int) response;
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
6345 }
6346
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006347 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006348 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006351
joonhunshin4ac60942023-11-15 15:23:39 +00006352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6353 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6358 if (response.payload == null) {
6359 return "";
6360 }
Evan Charltonc66da362014-05-16 14:06:40 -07006361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 // Append the returned status code to the end of the response payload.
6363 String s = Integer.toHexString(
6364 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6365 s = IccUtils.bytesToHexString(response.payload) + s;
6366 return s;
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Evan Charltonc66da362014-05-16 14:06:40 -07006370 }
6371
Jake Hambye994d462014-02-03 13:10:13 -08006372 /**
6373 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6374 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6375 *
6376 * @param itemID the ID of the item to read
6377 * @return the NV item as a String, or null on error.
6378 */
6379 @Override
6380 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6383 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384
6385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006388 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6390 return value;
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Jake Hambye994d462014-02-03 13:10:13 -08006394 }
6395
6396 /**
6397 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6398 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6399 *
6400 * @param itemID the ID of the item to read
6401 * @param itemValue the value to write, as a String
6402 * @return true on success; false on any failure
6403 */
6404 @Override
6405 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6408 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6413 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006414 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6416 return success;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Jake Hambye994d462014-02-03 13:10:13 -08006420 }
6421
6422 /**
6423 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6424 * Used for device configuration by some CDMA operators.
6425 *
6426 * @param preferredRoamingList byte array containing the new PRL
6427 * @return true on success; false on any failure
6428 */
6429 @Override
6430 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6432 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433
6434 final long identity = Binder.clearCallingIdentity();
6435 try {
6436 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6437 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6438 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6439 return success;
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Jake Hambye994d462014-02-03 13:10:13 -08006443 }
6444
6445 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006446 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006447 * Used for device configuration by some CDMA operators.
6448 *
chen xu6dac5ab2018-10-26 17:39:23 -07006449 * @param slotIndex - device slot.
6450 *
Jake Hambye994d462014-02-03 13:10:13 -08006451 * @return true on success; false on any failure
6452 */
6453 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006454 public boolean resetModemConfig(int slotIndex) {
6455 Phone phone = PhoneFactory.getPhone(slotIndex);
6456 if (phone != null) {
6457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6458 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459
joonhunshin4ac60942023-11-15 15:23:39 +00006460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6461 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6462
chen xu6dac5ab2018-10-26 17:39:23 -07006463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6466 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6467 return success;
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 }
chen xu6dac5ab2018-10-26 17:39:23 -07006472 return false;
6473 }
6474
6475 /**
6476 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6477 *
6478 * @param slotIndex - device slot.
6479 *
6480 * @return true on success; false on any failure
6481 */
6482 @Override
6483 public boolean rebootModem(int slotIndex) {
6484 Phone phone = PhoneFactory.getPhone(slotIndex);
6485 if (phone != null) {
6486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6487 mApp, phone.getSubId(), "rebootModem");
6488
joonhunshin4ac60942023-11-15 15:23:39 +00006489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6490 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6491
chen xu6dac5ab2018-10-26 17:39:23 -07006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6495 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6496 return success;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006502 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006503
Brad Ebinger51f743a2017-01-23 13:50:20 -08006504 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006505 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6506 * {@link #disableIms(int)}.
6507 * @param slotIndex device slot.
6508 */
6509 public void resetIms(int slotIndex) {
6510 enforceModifyPermission();
6511
joonhunshin4ac60942023-11-15 15:23:39 +00006512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6513 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6514
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 if (mImsResolver == null) {
6518 // may happen if the does not support IMS.
6519 return;
6520 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006521 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526
6527 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006528 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6529 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006530 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006531 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533
6534 final long identity = Binder.clearCallingIdentity();
6535 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006536 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006537 // may happen if the device does not support IMS.
6538 return;
6539 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006540 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006544 }
6545
6546 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006547 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6548 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006549 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006550 public void disableIms(int slotId) {
6551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006555 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 // may happen if the device does not support IMS.
6557 return;
6558 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006559 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006563 }
6564
6565 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006566 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6567 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006568 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006569 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006570 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006575 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6577 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006578 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006579 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
6582 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006583 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006584 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006585 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6586 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006587 @Override
6588 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006589 enforceModifyPermission();
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006594 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
6598 }
6599
6600 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006601 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006602 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006603 */
6604 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006609 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006610 // may happen if the device does not support IMS.
6611 return null;
6612 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006613 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006617 }
6618
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006619 /**
6620 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006621 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006622 */
6623 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625
6626 final long identity = Binder.clearCallingIdentity();
6627 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006628 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006629 // may happen if the device does not support IMS.
6630 return null;
6631 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006632 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006636 }
6637
Brad Ebinger884c07b2018-02-15 16:17:40 -08006638 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006639 * Sets the ImsService Package Name that Telephony will bind to.
6640 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006641 * @param slotIndex the slot ID that the ImsService should bind for.
6642 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006643 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 * @param featureTypes An integer array of feature types associated with a packageName.
6645 * @param packageName The name of the package that the current configuration will be replaced
6646 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006647 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006648 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6650 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006653 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 final long identity = Binder.clearCallingIdentity();
6656 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006658 // may happen if the device does not support IMS.
6659 return false;
6660 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006661 Map<Integer, String> featureConfig = new HashMap<>();
6662 for (int featureType : featureTypes) {
6663 featureConfig.put(featureType, packageName);
6664 }
6665 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6666 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006670 }
6671
6672 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006673 * Clears any carrier ImsService overrides for the slot index specified that were previously
6674 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6675 *
6676 * This should only be used for testing.
6677 *
6678 * @param slotIndex the slot ID that the ImsService should bind for.
6679 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6680 */
6681 @Override
6682 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6684 "clearCarrierImsServiceOverride");
6685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006686 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 if (mImsResolver == null) {
6691 // may happen if the device does not support IMS.
6692 return false;
6693 }
6694 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
6698 }
6699
6700 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006701 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006702 *
6703 * @param slotId The slot that the ImsService is associated with.
6704 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6705 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006706 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006707 * @return the package name of the ImsService configuration.
6708 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006709 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6710 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006711 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6713 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006718 // may happen if the device does not support IMS.
6719 return "";
6720 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006721 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006722 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6723 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006727 }
6728
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006729 /**
6730 * Get the MmTelFeature state associated with the requested subscription id.
6731 * @param subId The subscription that the MmTelFeature is associated with.
6732 * @param callback A callback with an integer containing the
6733 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6734 */
6735 @Override
6736 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6737 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6740 "IMS not available on device.");
6741 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006742 final long token = Binder.clearCallingIdentity();
6743 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006744 int slotId = getSlotIndex(subId);
6745 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6746 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6747 + subId + "'");
6748 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6749 }
6750 verifyImsMmTelConfiguredOrThrow(slotId);
6751 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6752 try {
6753 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6754 } catch (RemoteException e) {
6755 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6756 + "Ignore");
6757 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006758 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006759 } catch (ImsException e) {
6760 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006761 } finally {
6762 Binder.restoreCallingIdentity(token);
6763 }
6764 }
6765
Daniel Brightbb5840b2021-01-12 15:48:18 -08006766 /**
6767 * Sets the ims registration state on all valid {@link Phone}s.
6768 */
6769 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006770 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771
6772 final long identity = Binder.clearCallingIdentity();
6773 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006774 // NOTE: Before S, this method only set the default phone.
6775 for (final Phone phone : PhoneFactory.getPhones()) {
6776 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6777 phone.setImsRegistrationState(registered);
6778 }
6779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
Wink Saville36469e72014-06-11 15:17:00 -07006783 }
6784
6785 /**
Stuart Scott54788802015-03-30 13:18:01 -07006786 * Set the network selection mode to automatic.
6787 *
6788 */
6789 @Override
6790 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6792 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
joonhunshin4ac60942023-11-15 15:23:39 +00006794 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6795 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
6798 try {
shilufc958392020-01-20 11:36:01 -08006799 if (!isActiveSubscription(subId)) {
6800 return;
6801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006803 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6804 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
Stuart Scott54788802015-03-30 13:18:01 -07006808 }
6809
Jack Yud10cdd42020-09-28 20:28:01 -07006810 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006811 * Ask the radio to connect to the input network and change selection mode to manual.
6812 *
6813 * @param subId the id of the subscription.
6814 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6815 * the operator to attach to.
6816 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6817 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6818 * normal network selection next time.
6819 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006820 */
6821 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006822 public boolean setNetworkSelectionModeManual(
6823 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6825 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006826
joonhunshin4ac60942023-11-15 15:23:39 +00006827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6828 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6829
Jack Yu285100e2022-12-02 22:48:35 -08006830 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006831 if (!isActiveSubscription(subId)) {
6832 return false;
6833 }
6834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006836 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006838 if (DBG) {
6839 log("setNetworkSelectionModeManual: subId: " + subId
6840 + " operator: " + operatorInfo);
6841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006846 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006847 /**
shilu84f6e8b2019-12-19 13:58:01 -08006848 * Get the manual network selection
6849 *
6850 * @param subId the id of the subscription.
6851 *
6852 * @return the previously saved user selected PLMN
6853 */
6854 @Override
6855 public String getManualNetworkSelectionPlmn(int subId) {
6856 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006857 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6858 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006859
joonhunshin4ac60942023-11-15 15:23:39 +00006860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6862
shilu84f6e8b2019-12-19 13:58:01 -08006863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006866 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006867 }
6868
6869 final Phone phone = getPhone(subId);
6870 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006871 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006872 }
6873 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6874 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006875 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006880
6881 /**
6882 * Scans for available networks.
6883 */
6884 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006885 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6886 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6888 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006889 LocationAccessPolicy.LocationPermissionResult locationResult =
6890 LocationAccessPolicy.checkLocationPermission(mApp,
6891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6892 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006893 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006894 .setCallingPid(Binder.getCallingPid())
6895 .setCallingUid(Binder.getCallingUid())
6896 .setMethod("getCellNetworkScanResults")
6897 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6899 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006900 .build());
6901 switch (locationResult) {
6902 case DENIED_HARD:
6903 throw new SecurityException("Not allowed to access scan results -- location");
6904 case DENIED_SOFT:
6905 return null;
6906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907
Pengquan Menga1bb6272018-09-06 09:59:22 -07006908 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 try {
6910 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006911 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006916 }
6917
6918 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006919 * Get the call forwarding info, given the call forwarding reason.
6920 */
6921 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006922 public void getCallForwarding(int subId, int callForwardingReason,
6923 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006924 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006925
6926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6927 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6928
Shuo Qian4a594052020-01-23 11:59:30 -08006929 long identity = Binder.clearCallingIdentity();
6930 try {
6931 if (DBG) {
6932 log("getCallForwarding: subId " + subId
6933 + " callForwardingReason" + callForwardingReason);
6934 }
Hall Liu27d24262020-09-18 19:04:59 -07006935
6936 Phone phone = getPhone(subId);
6937 if (phone == null) {
6938 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006939 callback.onError(
6940 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006941 } catch (RemoteException e) {
6942 // ignore
6943 }
6944 return;
6945 }
6946
6947 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6948 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6949 @Override
6950 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6951 try {
6952 callback.onCallForwardingInfoAvailable(info);
6953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 }
6957
6958 @Override
6959 public void onError(int error) {
6960 try {
6961 callback.onError(error);
6962 } catch (RemoteException e) {
6963 // ignore
6964 }
6965 }
6966 });
6967 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
6973 /**
6974 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6975 * reason, the number to forward, and the timeout before the forwarding is attempted.
6976 */
6977 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006978 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6979 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006980 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006981
6982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6983 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6984
Shuo Qian4a594052020-01-23 11:59:30 -08006985 long identity = Binder.clearCallingIdentity();
6986 try {
6987 if (DBG) {
6988 log("setCallForwarding: subId " + subId
6989 + " callForwardingInfo" + callForwardingInfo);
6990 }
Hall Liu27d24262020-09-18 19:04:59 -07006991
6992 Phone phone = getPhone(subId);
6993 if (phone == null) {
6994 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006995 callback.accept(
6996 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006997 } catch (RemoteException e) {
6998 // ignore
6999 }
7000 return;
7001 }
7002
7003 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7004 FunctionalUtils.ignoreRemoteException(callback::accept));
7005
7006 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 }
7011
7012 /**
Hall Liu27d24262020-09-18 19:04:59 -07007013 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007014 */
7015 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007016 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007017 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007018
7019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7020 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7021
Shuo Qian4a594052020-01-23 11:59:30 -08007022 long identity = Binder.clearCallingIdentity();
7023 try {
Hall Liu27d24262020-09-18 19:04:59 -07007024 Phone phone = getPhone(subId);
7025 if (phone == null) {
7026 try {
7027 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7028 } catch (RemoteException e) {
7029 // ignore
7030 }
7031 return;
7032 }
SongFerngWang0e767992021-03-31 22:08:45 +08007033 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7034 PersistableBundle c = configManager.getConfigForSubId(subId);
7035 boolean requireUssd = c.getBoolean(
7036 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007037
Shuo Qian4a594052020-01-23 11:59:30 -08007038 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007039 if (requireUssd) {
7040 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7041 getSubscriptionCarrierId(subId));
7042 String newUssdCommand = "";
7043 try {
7044 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007045 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007046 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7047 } catch (NullPointerException e) {
7048 loge("Failed to generate USSD number" + e);
7049 }
7050 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7051 mMainThreadHandler, callback, carrierXmlParser,
7052 CarrierXmlParser.SsEntry.SSAction.QUERY);
7053 final String ussdCommand = newUssdCommand;
7054 Executors.newSingleThreadExecutor().execute(() -> {
7055 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7056 });
7057 } else {
7058 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7059 callback::accept);
7060 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7061 }
Shuo Qian4a594052020-01-23 11:59:30 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
7065 }
7066
7067 /**
Hall Liu27d24262020-09-18 19:04:59 -07007068 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007069 */
7070 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007071 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007072 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007073
7074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7075 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7076
Shuo Qian4a594052020-01-23 11:59:30 -08007077 long identity = Binder.clearCallingIdentity();
7078 try {
Hall Liu27d24262020-09-18 19:04:59 -07007079 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7080
7081 Phone phone = getPhone(subId);
7082 if (phone == null) {
7083 try {
7084 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7085 } catch (RemoteException e) {
7086 // ignore
7087 }
7088 return;
7089 }
7090
SongFerngWang0e767992021-03-31 22:08:45 +08007091 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7092 PersistableBundle c = configManager.getConfigForSubId(subId);
7093 boolean requireUssd = c.getBoolean(
7094 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007095
SongFerngWang0e767992021-03-31 22:08:45 +08007096 if (DBG) log("getCallWaitingStatus: subId " + subId);
7097 if (requireUssd) {
7098 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7099 getSubscriptionCarrierId(subId));
7100 CarrierXmlParser.SsEntry.SSAction ssAction =
7101 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7102 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7103 String newUssdCommand = "";
7104 try {
7105 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007106 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007107 .makeCommand(ssAction, null);
7108 } catch (NullPointerException e) {
7109 loge("Failed to generate USSD number" + e);
7110 }
7111 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7112 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7113 final String ussdCommand = newUssdCommand;
7114 Executors.newSingleThreadExecutor().execute(() -> {
7115 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7116 });
7117 } else {
7118 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7119 FunctionalUtils.ignoreRemoteException(callback::accept));
7120
7121 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7122 }
Shuo Qian4a594052020-01-23 11:59:30 -08007123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
7126 }
7127
7128 /**
yinxub1bed742017-04-17 11:45:04 -07007129 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007130 *
yinxub1bed742017-04-17 11:45:04 -07007131 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007132 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7133 * location related information which will be sent if the caller already possess
7134 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007135 * @param request contains the radio access networks with bands/channels to scan
7136 * @param messenger callback messenger for scan results or errors
7137 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007138 * @return the id of the requested scan which can be used to stop the scan.
7139 */
7140 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007141 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7142 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007143 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7145 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007146 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007147 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7148 if (!renounceFineLocationAccess) {
7149 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007150 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7151 .setCallingPackage(callingPackage)
7152 .setCallingFeatureId(callingFeatureId)
7153 .setCallingPid(Binder.getCallingPid())
7154 .setCallingUid(Binder.getCallingUid())
7155 .setMethod("requestNetworkScan")
7156 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7158 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7159 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007160 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007162 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7163 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007164 if (e != null) {
7165 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7166 throw e;
7167 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007168 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007169 return TelephonyScanManager.INVALID_SCAN_ID;
7170 }
7171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 }
joonhunshin4ac60942023-11-15 15:23:39 +00007173
7174 enforceTelephonyFeatureWithException(callingPackage,
7175 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7176
Hall Liu912dfd32019-04-25 14:02:26 -07007177 int callingUid = Binder.getCallingUid();
7178 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007182 renounceFineLocationAccess, request, messenger, binder,
7183 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007184 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
yinxu504e1392017-04-12 16:03:22 -07007188 }
7189
Hall Liub2ac8ef2019-02-28 15:56:23 -08007190 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007191 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007192 boolean hasCarrierPriv;
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7196 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Hall Liu558027f2019-05-15 19:14:05 -07007200 boolean hasNetworkScanPermission =
7201 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007202 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007203
7204 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7205 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7206 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007207 }
7208
7209 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7210 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007211 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7212 return new SecurityException("Specific channels must not be"
7213 + " scanned without location access.");
7214 }
7215 }
7216 }
7217
Hall Liub2ac8ef2019-02-28 15:56:23 -08007218 return null;
7219 }
7220
yinxu504e1392017-04-12 16:03:22 -07007221 /**
7222 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007223 *
7224 * @param subId id of the subscription
7225 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007226 */
7227 @Override
7228 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7230 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231
Hall Liu912dfd32019-04-25 14:02:26 -07007232 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007235 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
yinxu504e1392017-04-12 16:03:22 -07007239 }
7240
7241 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007242 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007243 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007244 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007245 */
7246 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007247 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007248 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007249 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007250 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
joonhunshin4ac60942023-11-15 15:23:39 +00007252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7253 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 final long identity = Binder.clearCallingIdentity();
7256 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007257 if (DBG) log("getAllowedNetworkTypesBitmask");
7258 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7259 int networkTypesBitmask = (result != null ? result[0] : -1);
7260 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7261 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007265 }
7266
7267 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007268 * Get the allowed network types for certain reason.
7269 *
7270 * @param subId the id of the subscription.
7271 * @param reason the reason the allowed network type change is taking place
7272 * @return the allowed network types.
7273 */
7274 @Override
7275 public long getAllowedNetworkTypesForReason(int subId,
7276 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007278 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007279
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007280 if (!mApp.getResources().getBoolean(
7281 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7283 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7284 "getAllowedNetworkTypesForReason");
7285 }
joonhunshin4ac60942023-11-15 15:23:39 +00007286
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007287 final long identity = Binder.clearCallingIdentity();
7288 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007289 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007296 * Enable/Disable E-UTRA-NR Dual Connectivity
7297 * @param subId subscription id of the sim card
7298 * @param nrDualConnectivityState expected NR dual connectivity state
7299 * This can be passed following states
7300 * <ol>
7301 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7302 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7303 * <li>Disable NR dual connectivity and force secondary cell to be released
7304 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7305 * </ol>
7306 * @return operation result.
7307 */
7308 @Override
7309 public int setNrDualConnectivityState(int subId,
7310 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7312 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007313 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007314 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7315 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7316 }
7317
Sooraj Sasindran37444802020-08-11 10:40:43 -07007318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7322 nrDualConnectivityState, subId,
7323 workSource);
7324 if (DBG) log("enableNRDualConnectivity result: " + result);
7325 return result;
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
7329 }
7330
7331 /**
7332 * Is E-UTRA-NR Dual Connectivity enabled
7333 * @return true if dual connectivity is enabled else false
7334 */
7335 @Override
7336 public boolean isNrDualConnectivityEnabled(int subId) {
7337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007339 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007340 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007341 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7342 return false;
7343 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7348 null, subId, workSource);
7349 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7350 return isEnabled;
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
7354 }
7355
7356 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007357 * Set the allowed network types of the device and
7358 * provide the reason triggering the allowed network change.
7359 *
7360 * @param subId the id of the subscription.
7361 * @param reason the reason the allowed network type change is taking place
7362 * @param allowedNetworkTypes the allowed network types.
7363 * @return true on success; false on any failure.
7364 */
7365 @Override
7366 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007367 @TelephonyManager.AllowedNetworkTypesReason int reason,
7368 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7370 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007371 // If the caller only has carrier privileges, then they should not be able to override
7372 // any network types which were set for security reasons.
7373 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7374 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007375 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007376 throw new SecurityException(
7377 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007378 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007379 }
joonhunshin4ac60942023-11-15 15:23:39 +00007380
7381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7382 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7383
SongFerngWang3ef3e072020-12-21 16:41:52 +08007384 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007385 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007386 return false;
7387 }
7388 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7389 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007390 return false;
7391 }
7392
Jack Yu5b494332023-01-23 18:18:04 +00007393 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7394 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007395
Jack Yue37dd262022-12-16 11:53:37 -08007396 Phone phone = getPhone(subId);
7397 if (phone == null) {
7398 return false;
7399 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007400
Jack Yue37dd262022-12-16 11:53:37 -08007401 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007402 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007403 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007404 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007405
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007406 final long identity = Binder.clearCallingIdentity();
7407 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007408 Boolean success = (Boolean) sendRequest(
7409 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7410 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7411
7412 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7413 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
7417 }
7418
7419 /**
Miaoa84611c2019-03-15 09:21:10 +08007420 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007421 *
Miaoa84611c2019-03-15 09:21:10 +08007422 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007423 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007424 * @hide
7425 */
7426 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007427 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007428 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007429
7430 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7431 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007434 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 try {
Miaoa84611c2019-03-15 09:21:10 +08007436 if (phone != null) {
7437 return phone.hasMatchedTetherApnSetting();
7438 } else {
7439 return false;
7440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 } finally {
7442 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007443 }
Junda Liu475951f2014-11-07 16:45:03 -08007444 }
7445
7446 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007447 * Get the user enabled state of Mobile Data.
7448 *
7449 * TODO: remove and use isUserDataEnabled.
7450 * This can't be removed now because some vendor codes
7451 * calls through ITelephony directly while they should
7452 * use TelephonyManager.
7453 *
7454 * @return true on enabled
7455 */
7456 @Override
7457 public boolean getDataEnabled(int subId) {
7458 return isUserDataEnabled(subId);
7459 }
7460
7461 /**
7462 * Get whether mobile data is enabled per user setting.
7463 *
7464 * There are other factors deciding whether mobile data is actually enabled, but they are
7465 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007466 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7468 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007469 *
7470 * @return {@code true} if data is enabled else {@code false}
7471 */
7472 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007473 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007474 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007475 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007476 try {
7477 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7478 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007479 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007480 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7481 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007482 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007484 mApp, subId, functionName);
7485
Robert Greenwalt646120a2014-05-23 11:54:03 -07007486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
Jack Yu285100e2022-12-02 22:48:35 -08007490 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7492 Phone phone = PhoneFactory.getPhone(phoneId);
7493 if (phone != null) {
7494 boolean retVal = phone.isUserDataEnabled();
7495 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7496 return retVal;
7497 } else {
7498 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7499 return false;
7500 }
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007503 }
7504 }
7505
7506 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007507 * Checks if the device is capable of mobile data by considering whether whether the
7508 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7509 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007510 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007511 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007512 */
7513 @Override
7514 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007515 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007516 try {
7517 try {
7518 mApp.enforceCallingOrSelfPermission(
7519 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007520 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007521 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 try {
7523 mApp.enforceCallingOrSelfPermission(
7524 android.Manifest.permission.READ_PHONE_STATE,
7525 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007526 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007527 mApp.enforceCallingOrSelfPermission(
7528 permission.READ_BASIC_PHONE_STATE, functionName);
7529 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007530 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007531 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007532 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534
joonhunshin4ac60942023-11-15 15:23:39 +00007535 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7536 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
Jack Yu285100e2022-12-02 22:48:35 -08007540 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007542 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007543 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007544 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 return retVal;
7546 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007547 if (DBG) {
7548 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7549 + subId + " retVal=false");
7550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 return false;
7552 }
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007555 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007556 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007557
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007558 /**
7559 * Check if data is enabled for a specific reason
7560 * @param subId Subscription index
7561 * @param reason the reason the data enable change is taking place
7562 * @return {@code true} if the overall data is enabled; {@code false} if not.
7563 */
7564 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007565 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007566 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007567 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007568 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007569 try {
7570 mApp.enforceCallingOrSelfPermission(
7571 android.Manifest.permission.ACCESS_NETWORK_STATE,
7572 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007573 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007574 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7575 functionName);
7576 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007577 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007578 try {
7579 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007580 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007581 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007583 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007584 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007585 }
7586
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007587 if (!mApp.getResources().getBoolean(
7588 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7589 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7590 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7591 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007592
7593 final long identity = Binder.clearCallingIdentity();
7594 try {
Jack Yu285100e2022-12-02 22:48:35 -08007595 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007596 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007597 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007598 + " reason=" + reason);
7599 }
7600 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007601 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007603 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007604 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007605 return retVal;
7606 } else {
7607 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007608 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007609 + subId + " retVal=false");
7610 }
7611 return false;
7612 }
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
7616 }
7617
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007618 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007619 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007620 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7621 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7622
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007623 // No permission needed; this only lets the caller inspect their own status.
7624 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007625 }
Junda Liu29340342014-07-10 15:23:27 -07007626
7627 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007628 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007629 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007630
7631 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7632 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7633
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007634 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7635 }
7636
7637 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7638 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007639 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007640 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7642 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007643 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7644 if (cpt == null) {
7645 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007646 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7647 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007648 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007649 }
7650
7651 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007652 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007653 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007654
7655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7657
chen xuf7e9fe82019-05-09 19:31:02 -07007658 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007659 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007660 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007661 Phone phone = getPhone(subId);
7662 if (phone == null) {
7663 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7664 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7665 }
7666 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7667 if (cpt == null) {
7668 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007669 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7670 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007671 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007672 }
7673
7674 @Override
7675 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007676 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007677
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007678 if (!mApp.getResources().getBoolean(
7679 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7681 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7682 "checkCarrierPrivilegesForPackageAnyPhone");
7683 }
joonhunshin4ac60942023-11-15 15:23:39 +00007684
Rambo Wange7209ce2022-02-23 13:41:02 -08007685 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7686 }
7687
7688 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007689 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007690 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007691 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007692 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007693 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7694 Phone phone = PhoneFactory.getPhone(phoneId);
7695 if (phone == null) {
7696 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007697 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007698 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7699 if (cpt == null) {
7700 continue;
7701 }
7702 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007703 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7704 break;
7705 }
7706 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007707 return result;
Junda Liu29340342014-07-10 15:23:27 -07007708 }
Derek Tan89e89d42014-07-08 17:00:10 -07007709
7710 @Override
Junda Liue64de782015-04-16 17:19:16 -07007711 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007712 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007713
7714 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7715 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7716 "getCarrierPackageNamesForIntentAndPhone");
7717
Rambo Wang8a247eb2022-02-08 21:11:18 +00007718 Phone phone = PhoneFactory.getPhone(phoneId);
7719 if (phone == null) {
7720 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007721 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007722 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7723 if (cpt == null) {
7724 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007725 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007726 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007727 }
7728
Amith Yamasani6e118872016-02-19 12:53:51 -08007729 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007730 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007731 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007732 Phone phone = PhoneFactory.getPhone(phoneId);
7733 if (phone == null) {
7734 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007735 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007736 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7737 if (cpt == null) {
7738 return Collections.emptyList();
7739 }
7740 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007741 }
7742
chen xuf7e9fe82019-05-09 19:31:02 -07007743 @Override
7744 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007745 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007746
7747 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7748 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7749 "getPackagesWithCarrierPrivilegesForAllPhones");
7750
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007751 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007752 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007753 try {
7754 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7755 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7756 }
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007759 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007760 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007761 }
7762
Rambo Wang6812ffb2022-03-15 16:54:17 -07007763 @Override
7764 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7765 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7766
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007767 if (!mApp.getResources().getBoolean(
7768 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7769 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7770 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7771 "getCarrierServicePackageNameForLogicalSlot");
7772 }
joonhunshin4ac60942023-11-15 15:23:39 +00007773
Rambo Wang6812ffb2022-03-15 16:54:17 -07007774 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7775 if (phone == null) {
7776 return null;
7777 }
7778 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7779 if (cpt == null) {
7780 return null;
7781 }
7782 return cpt.getCarrierServicePackageName();
7783 }
7784
Wink Savilleb564aae2014-10-23 10:18:09 -07007785 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007786 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007787 UiccPort port = phone == null ? null : phone.getUiccPort();
7788 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007789 return null;
7790 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007791 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007792 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007793 return null;
7794 }
7795 return iccId;
7796 }
7797
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007798 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007799 public void setCallComposerStatus(int subId, int status) {
7800 enforceModifyPermission();
7801
joonhunshin4ac60942023-11-15 15:23:39 +00007802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7803 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7804
Shuo Qiane4e11672020-12-15 22:15:33 -08007805 final long identity = Binder.clearCallingIdentity();
7806 try {
7807 Phone phone = getPhone(subId);
7808 if (phone != null) {
7809 Phone defaultPhone = phone.getImsPhone();
7810 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7811 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7812 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007813 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7814 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007815 }
7816 }
Shuo Qian284ae752020-12-22 19:10:14 -08007817 } catch (ImsException e) {
7818 throw new ServiceSpecificException(e.getCode());
7819 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007820 Binder.restoreCallingIdentity(identity);
7821 }
7822 }
7823
7824 @Override
7825 public int getCallComposerStatus(int subId) {
7826 enforceReadPrivilegedPermission("getCallComposerStatus");
7827
joonhunshin4ac60942023-11-15 15:23:39 +00007828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7829 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7830
Shuo Qiane4e11672020-12-15 22:15:33 -08007831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 Phone phone = getPhone(subId);
7834 if (phone != null) {
7835 Phone defaultPhone = phone.getImsPhone();
7836 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7837 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7838 return imsPhone.getCallComposerStatus();
7839 }
7840 }
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7845 }
7846
7847 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007848 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7849 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007850 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007851 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007852
joonhunshin4ac60942023-11-15 15:23:39 +00007853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7855 "setLine1NumberForDisplayForSubscriber");
7856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 final String iccId = getIccId(subId);
7860 final Phone phone = getPhone(subId);
7861 if (phone == null) {
7862 return false;
7863 }
arunvoddub1365e62024-07-31 09:42:31 +00007864 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7865 Rlog.e(LOG_TAG, "Number is too long");
7866 return false;
7867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final String subscriberId = phone.getSubscriberId();
7869
7870 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007871 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872 + subscriberId + " to " + number);
7873 }
7874
7875 if (TextUtils.isEmpty(iccId)) {
7876 return false;
7877 }
7878
7879 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7880
7881 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7882 if (alphaTag == null) {
7883 editor.remove(alphaTagPrefKey);
7884 } else {
7885 editor.putString(alphaTagPrefKey, alphaTag);
7886 }
7887
7888 // Record both the line number and IMSI for this ICCID, since we need to
7889 // track all merged IMSIs based on line number
7890 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7891 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7892 if (number == null) {
7893 editor.remove(numberPrefKey);
7894 editor.remove(subscriberPrefKey);
7895 } else {
7896 editor.putString(numberPrefKey, number);
7897 editor.putString(subscriberPrefKey, subscriberId);
7898 }
7899
7900 editor.commit();
7901 return true;
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007904 }
Derek Tan7226c842014-07-02 17:42:23 -07007905 }
7906
7907 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007908 public String getLine1NumberForDisplay(int subId, String callingPackage,
7909 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007910 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007911 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007912 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007913 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007914 return null;
7915 }
Derek Tan97ebb422014-09-05 16:55:38 -07007916
joonhunshin4ac60942023-11-15 15:23:39 +00007917 enforceTelephonyFeatureWithException(callingPackage,
7918 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 final long identity = Binder.clearCallingIdentity();
7921 try {
7922 String iccId = getIccId(subId);
7923 if (iccId != null) {
7924 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7925 if (DBG_MERGE) {
7926 log("getLine1NumberForDisplay returning "
7927 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7928 }
7929 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7932 return null;
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007935 }
Derek Tan7226c842014-07-02 17:42:23 -07007936 }
7937
7938 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007939 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7940 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007942 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007943 return null;
7944 }
Derek Tan97ebb422014-09-05 16:55:38 -07007945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 final long identity = Binder.clearCallingIdentity();
7947 try {
7948 String iccId = getIccId(subId);
7949 if (iccId != null) {
7950 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7951 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7952 }
7953 return null;
7954 } finally {
7955 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007956 }
Derek Tan7226c842014-07-02 17:42:23 -07007957 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007958
7959 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007960 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7961 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007962 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7963 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007965 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007966 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007967 return null;
7968 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007969
Jordan Liub49b04b2019-05-06 14:45:15 -07007970 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7971 // the process, where TelephonyManager was instantiated.
7972 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007973 final long identity = Binder.clearCallingIdentity();
7974 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007975 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 final TelephonyManager tele = TelephonyManager.from(context);
7977 final SubscriptionManager sub = SubscriptionManager.from(context);
7978
7979 // Figure out what subscribers are currently active
7980 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981
Jordan Liub49b04b2019-05-06 14:45:15 -07007982 // Only consider subs which match the current subId
7983 // This logic can be simplified. See b/131189269 for progress.
7984 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007985 activeSubscriberIds.add(tele.getSubscriberId(subId));
7986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987
7988 // First pass, find a number override for an active subscriber
7989 String mergeNumber = null;
7990 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7991 for (String key : prefs.keySet()) {
7992 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7993 final String subscriberId = (String) prefs.get(key);
7994 if (activeSubscriberIds.contains(subscriberId)) {
7995 final String iccId = key.substring(
7996 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7997 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7998 mergeNumber = (String) prefs.get(numberKey);
7999 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008000 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 + " for active subscriber " + subscriberId);
8002 }
8003 if (!TextUtils.isEmpty(mergeNumber)) {
8004 break;
8005 }
8006 }
8007 }
8008 }
8009
8010 // Shortcut when no active merged subscribers
8011 if (TextUtils.isEmpty(mergeNumber)) {
8012 return null;
8013 }
8014
8015 // Second pass, find all subscribers under that line override
8016 final ArraySet<String> result = new ArraySet<>();
8017 for (String key : prefs.keySet()) {
8018 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8019 final String number = (String) prefs.get(key);
8020 if (mergeNumber.equals(number)) {
8021 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8022 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8023 final String subscriberId = (String) prefs.get(subscriberKey);
8024 if (!TextUtils.isEmpty(subscriberId)) {
8025 result.add(subscriberId);
8026 }
8027 }
8028 }
8029 }
8030
8031 final String[] resultArray = result.toArray(new String[result.size()]);
8032 Arrays.sort(resultArray);
8033 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008034 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8036 }
8037 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008038 } finally {
8039 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008040 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008041 }
8042
8043 @Override
zoey chen38003472019-12-13 17:16:31 +08008044 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8045 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008046
joonhunshin4ac60942023-11-15 15:23:39 +00008047 enforceTelephonyFeatureWithException(callingPackage,
8048 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8049
Malcolm Chen6ca97372019-07-01 16:28:21 -07008050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 final TelephonyManager telephonyManager = mApp.getSystemService(
8053 TelephonyManager.class);
8054 String subscriberId = telephonyManager.getSubscriberId(subId);
8055 if (subscriberId == null) {
8056 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008057 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008058 + subId);
8059 }
8060 return null;
8061 }
8062
Jack Yu3beaf9d2023-04-14 09:17:27 -07008063 final SubscriptionInfo info = getSubscriptionManagerService()
8064 .getSubscriptionInfo(subId);
8065 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008066 // If it doesn't belong to any group, return just subscriberId of itself.
8067 if (groupUuid == null) {
8068 return new String[]{subscriberId};
8069 }
8070
8071 // Get all subscriberIds from the group.
8072 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008073 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8074 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8075 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008076 for (SubscriptionInfo subInfo : groupInfos) {
8077 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8078 if (subscriberId != null) {
8079 mergedSubscriberIds.add(subscriberId);
8080 }
8081 }
8082
8083 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
8086
8087 }
8088 }
8089
8090 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008091 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008092 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008093 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094
joonhunshin4ac60942023-11-15 15:23:39 +00008095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8096 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 final Phone phone = getPhone(subId);
8101 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008105 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008106
8107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008108 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008109 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8110 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008111 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8112 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
8116 final Phone phone = getPhone(subId);
8117 if (phone == null) {
8118 return false;
8119 }
8120 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8121 cdmaNonRoamingList);
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008124 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008125 }
8126
8127 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008128 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008129 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008130 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008131 if (phone == null) {
8132 return raf;
8133 }
8134
Shuo Qiandee53402020-05-29 14:08:15 -07008135 try {
8136 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008137 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008138 mApp, phone.getSubId(), "getRadioAccessFamily");
8139 } catch (SecurityException e) {
8140 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8141 throw e;
8142 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008143
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008144 if (!mApp.getResources().getBoolean(
8145 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8146 enforceTelephonyFeatureWithException(callingPackage,
8147 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8148 }
joonhunshin4ac60942023-11-15 15:23:39 +00008149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 final long identity = Binder.clearCallingIdentity();
8151 try {
chen xub97461a2018-10-26 14:17:57 -07008152 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 } finally {
8154 Binder.restoreCallingIdentity(identity);
8155 }
chen xub97461a2018-10-26 14:17:57 -07008156 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008157 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008158
8159 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008160 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008161 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008162 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8163 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008164 enforceTelephonyFeatureWithException(callingPackage,
8165 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8166
Hall Liu82694d52020-12-11 18:22:04 -08008167 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008168 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008169 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8170 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008171 if (!dialerRoleHolders.contains(callingPackage)) {
8172 throw new SecurityException("App must be the dialer role holder to"
8173 + " upload a call composer pic");
8174 }
8175
8176 Executors.newSingleThreadExecutor().execute(() -> {
8177 ByteArrayOutputStream output = new ByteArrayOutputStream(
8178 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8179 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8180 boolean readUntilEnd = false;
8181 int totalBytesRead = 0;
8182 byte[] buffer = new byte[16 * 1024];
8183 while (true) {
8184 int numRead;
8185 try {
8186 numRead = input.read(buffer);
8187 } catch (IOException e) {
8188 try {
8189 fd.checkError();
8190 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8191 null);
8192 } catch (IOException e1) {
8193 // This means that the other side closed explicitly with an error. If this
8194 // happens, log and ignore.
8195 loge("Remote end of call composer picture pipe closed: " + e1);
8196 }
8197 break;
8198 }
8199 if (numRead == -1) {
8200 readUntilEnd = true;
8201 break;
8202 }
8203 totalBytesRead += numRead;
8204 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8205 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8206 try {
8207 input.close();
8208 } catch (IOException e) {
8209 // ignore
8210 }
8211 break;
8212 }
8213 output.write(buffer, 0, numRead);
8214 }
8215 // Generally, the remote end will close the file descriptors. The only case where we
8216 // close is above, where the picture size is too big.
8217
8218 try {
8219 fd.checkError();
8220 } catch (IOException e) {
8221 loge("Remote end for call composer closed with an error: " + e);
8222 return;
8223 }
8224
Hall Liuaa4211e2021-01-20 15:43:39 -08008225 if (!readUntilEnd) {
8226 loge("Did not finish reading entire image; aborting");
8227 return;
8228 }
Hall Liu82694d52020-12-11 18:22:04 -08008229
Hall Liuaa4211e2021-01-20 15:43:39 -08008230 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8231 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8232 new CallComposerPictureTransfer.Factory() {},
8233 imageData,
8234 (result) -> {
8235 if (result.first != null) {
8236 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8237 Bundle outputResult = new Bundle();
8238 outputResult.putParcelable(
8239 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8240 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8241 outputResult);
8242 } else {
8243 callback.send(result.second, null);
8244 }
8245 }
8246 );
Hall Liu82694d52020-12-11 18:22:04 -08008247 });
8248 }
8249
8250 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008251 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008252 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008253 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254
joonhunshin4ac60942023-11-15 15:23:39 +00008255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8256 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 final long identity = Binder.clearCallingIdentity();
8259 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008260 ImsManager.getInstance(defaultPhone.getContext(),
8261 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008265 }
8266
8267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008268 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8271 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008272 return false;
8273 }
Svet Ganovb320e182015-04-16 12:30:10 -07008274
joonhunshin4ac60942023-11-15 15:23:39 +00008275 enforceTelephonyFeatureWithException(callingPackage,
8276 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 final long identity = Binder.clearCallingIdentity();
8279 try {
8280 // Check the user preference and the system-level IMS setting. Even if the user has
8281 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8282 // In the long run, we may instead need to check if there exists a connection service
8283 // which can support video calling.
8284 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008285 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 return imsManager.isVtEnabledByPlatform()
8287 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8288 && imsManager.isVtEnabledByUser();
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008292 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008293
Andrew Leea1239f22015-03-02 17:44:07 -08008294 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008295 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8296 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008298 mApp, subId, callingPackage, callingFeatureId,
8299 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 return false;
8301 }
8302
joonhunshin4ac60942023-11-15 15:23:39 +00008303 enforceTelephonyFeatureWithException(callingPackage,
8304 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 final long identity = Binder.clearCallingIdentity();
8307 try {
8308 CarrierConfigManager configManager =
8309 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008310 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
Andrew Leea1239f22015-03-02 17:44:07 -08008315 }
8316
8317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008318 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008320 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 return false;
8322 }
8323
joonhunshin4ac60942023-11-15 15:23:39 +00008324 enforceTelephonyFeatureWithException(callingPackage,
8325 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 CarrierConfigManager configManager =
8330 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008331 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
Andrew Leea1239f22015-03-02 17:44:07 -08008336 }
8337
Andrew Lee9431b832015-03-09 18:46:45 -07008338 @Override
8339 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008340 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008341 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008342 }
8343
8344 @Override
8345 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8347 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 final long identity = Binder.clearCallingIdentity();
8350 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008351 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
Andrew Lee9431b832015-03-09 18:46:45 -07008355 }
8356
Hall Liuf6668912018-10-31 17:05:23 -07008357 /**
8358 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8359 * support for the feature and device firmware support.
8360 *
8361 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8362 */
8363 @Override
8364 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008365 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8366 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008369 final Phone phone = getPhone(subscriptionId);
8370 if (phone == null) {
8371 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8372 return false;
8373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008375 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008377 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8378 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8379 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 return isCarrierSupported && isDeviceSupported;
8381 } finally {
8382 Binder.restoreCallingIdentity(identity);
8383 }
Hall Liu98187582018-01-22 19:15:32 -08008384 }
8385
Hall Liuf6668912018-10-31 17:05:23 -07008386 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008387 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8388 * RTT setting, will return true if the device and carrier both support RTT.
8389 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008390 */
8391 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 final long identity = Binder.clearCallingIdentity();
8393 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008394 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8395 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8396 return false;
8397 }
8398 }
8399
Hall Liu5bab75c2019-12-11 23:58:20 +00008400 boolean isRttSupported = isRttSupported(subscriptionId);
8401 boolean isUserRttSettingOn = Settings.Secure.getInt(
8402 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8403 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8404 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8405 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 } finally {
8407 Binder.restoreCallingIdentity(identity);
8408 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008409 }
8410
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008411 @Deprecated
8412 @Override
8413 public String getDeviceId(String callingPackage) {
8414 return getDeviceIdWithFeature(callingPackage, null);
8415 }
8416
Sanket Padawe7310cc72015-01-14 09:53:20 -08008417 /**
8418 * Returns the unique device ID of phone, for example, the IMEI for
8419 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8420 *
8421 * <p>Requires Permission:
8422 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8423 */
8424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008425 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008426 try {
8427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8428 } catch (SecurityException se) {
8429 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8430 throw new SecurityException("Package " + callingPackage + " does not belong to "
8431 + Binder.getCallingUid());
8432 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008433 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008434 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008435 return null;
8436 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008437 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008438 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008439 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008440 return null;
8441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442
8443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 return phone.getDeviceId();
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008449 }
8450
Ping Sunc67b7c22016-03-02 19:16:45 +08008451 /**
8452 * {@hide}
8453 * Returns the IMS Registration Status on a particular subid
8454 *
8455 * @param subId
8456 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008457 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008458 Phone phone = getPhone(subId);
8459 if (phone != null) {
8460 return phone.isImsRegistered();
8461 } else {
8462 return false;
8463 }
8464 }
8465
Santos Cordon7a1885b2015-02-03 11:15:19 -08008466 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008467 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008468 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008471 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8472 }
8473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
8478 }
8479 }
8480
8481 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008482 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008483 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008484 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008485 mApp,
8486 subscriptionId,
8487 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8488 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008489
8490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8491 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8492
Tyler Gunnf70ed162019-04-03 15:28:53 -07008493 final long identity = Binder.clearCallingIdentity();
8494 try {
8495 Phone phone = getPhone(subscriptionId);
8496 if (phone == null) {
8497 return null;
8498 }
8499 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8500 } finally {
8501 Binder.restoreCallingIdentity(identity);
8502 }
8503 }
8504
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008505 /**
8506 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008507 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008508 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 Phone phone = getPhone(subId);
8512 if (phone != null) {
8513 return phone.isWifiCallingEnabled();
8514 } else {
8515 return false;
8516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008519 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008520 }
8521
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008522 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008523 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008524 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008525 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 Phone phone = getPhone(subId);
8529 if (phone != null) {
8530 return phone.isVideoEnabled();
8531 } else {
8532 return false;
8533 }
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008536 }
8537 }
8538
8539 /**
8540 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8541 * defined in {@link ImsRegistrationImplBase}.
8542 */
8543 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 Phone phone = getPhone(subId);
8547 if (phone != null) {
8548 return phone.getImsRegistrationTech();
8549 } else {
8550 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8551 }
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008554 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008555 }
8556
Stuart Scott8eef64f2015-04-08 15:13:54 -07008557 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008558 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008559 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008560
8561 enforceTelephonyFeatureWithException(callingPackage,
8562 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8563
Stuart Scott981d8582015-04-21 14:09:50 -07008564 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8565 return;
8566 }
Kai Shif70f46f2021-03-03 13:59:46 -08008567 Phone defaultPhone = getDefaultPhone();
8568 if (defaultPhone != null) {
8569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8570 mApp, getDefaultPhone().getSubId(), "factoryReset");
8571 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008572 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008573
Svet Ganovcc087f82015-05-12 20:35:54 -07008574 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008575 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8576 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008577 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008578 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008579 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008580 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008581 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008582 setDataRoamingEnabled(subId, phone == null ? false
8583 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008584 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008585 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008586 // There has been issues when Sms raw table somehow stores orphan
8587 // fragments. They lead to garbled message when new fragments come
8588 // in and combined with those stale ones. In case this happens again,
8589 // user can reset all network settings which will clean up this table.
8590 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008591 // Clean up IMS settings as well here.
8592 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008593 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008594 ImsManager.getInstance(mApp, slotId).factoryReset();
8595 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008596
Kai Shif70f46f2021-03-03 13:59:46 -08008597 if (defaultPhone == null) {
8598 return;
8599 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008600 // Erase modem config if erase modem on network setting is enabled.
8601 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8602 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8603 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008604 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008605 }
Kai Shif70f46f2021-03-03 13:59:46 -08008606
8607 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008608 } finally {
8609 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008610 }
8611 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008612
SongFerngWangfd89b102021-05-27 22:44:54 +08008613 @VisibleForTesting
8614 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8615 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8616 return;
8617 }
8618 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8619 RILConstants.PREFERRED_NETWORK_MODE);
8620 SubscriptionManager.setSubscriptionProperty(subId,
8621 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8622 "user=" + defaultNetworkType);
8623 phone.loadAllowedNetworksFromSubscriptionDatabase();
8624 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8625 defaultNetworkType, null);
8626 }
8627
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008628 private void cleanUpSmsRawTable(Context context) {
8629 ContentResolver resolver = context.getContentResolver();
8630 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8631 resolver.delete(uri, null, null);
8632 }
8633
Narayan Kamath1c496c22015-04-16 14:40:19 +01008634 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008635 public String getSimLocaleForSubscriber(int subId) {
8636 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008637
8638 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8639 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8640
chen xu5d3637b2019-01-21 23:31:38 -08008641 final Phone phone = getPhone(subId);
8642 if (phone == null) {
8643 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008644 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646 final long identity = Binder.clearCallingIdentity();
8647 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008648 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8649 phone.getContext().getOpPackageName(),
8650 phone.getContext().getAttributionTag());
8651 if (info == null) {
8652 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8653 return null;
chen xu6291c472019-02-04 12:55:53 -08008654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655 // Try and fetch the locale from the carrier properties or from the SIM language
8656 // preferences (EF-PL and EF-LI)...
8657 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008659 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8660 if (localeFromDefaultSim != null) {
8661 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8662 if (DBG) log("Using locale from subId: " + subId + " locale: "
8663 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008664 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008665 } else {
8666 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 }
8668 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 // The SIM language preferences only store a language (e.g. fr = French), not an
8671 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8672 // the SIM and carrier preferences does not include a country we add the country
8673 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008674 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008676 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008677 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008678 }
8679
8680 if (DBG) log("No locale found - returning null");
8681 return null;
8682 } finally {
8683 Binder.restoreCallingIdentity(identity);
8684 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008685 }
8686
tom hsu0b59d292022-09-29 23:49:21 +08008687 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008688 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008689 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008690 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008691 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008692 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8693 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008694 Locale.forLanguageTag(localeTag).getCountry())) {
8695 return localeTag;
8696 }
8697 }
8698 return inputLocale.toLanguageTag();
8699 }
8700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008701 /**
8702 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8703 */
8704 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008705 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008706 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008707 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008708
Gary Jian3aa9a762022-01-24 16:41:19 +08008709 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8710 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008711
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008712 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008713 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8714 * representing the state of the modem.
8715 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008716 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8717 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008718 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008719 */
8720 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008721 public void requestModemActivityInfo(ResultReceiver result) {
8722 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008723
8724 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8725 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8726
vagdeviaf9a5b92018-08-15 16:01:53 -07008727 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008728
8729 final long identity = Binder.clearCallingIdentity();
8730 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008731 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008732 } finally {
8733 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008734 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008735 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008736
Gary Jian76280a42022-12-07 16:18:33 +08008737 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008738 // less than total activity duration.
8739 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8740 if (info == null) {
8741 return false;
8742 }
8743 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008744 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008745 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8746
Hall Liu49656c02020-10-09 19:00:11 -07008747 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8748
Siddharth Rayb8114062018-06-17 15:02:38 -07008749 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008750 && (info.getSleepTimeMillis() <= activityDurationMs)
8751 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008752 }
8753
Gary Jian3aa9a762022-01-24 16:41:19 +08008754 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8755 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8756 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8757 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8758
8759 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8760 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8761 }
8762
8763 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8764 mLastModemActivityInfo.setReceiveTimeMillis(
8765 rat,
8766 freq,
8767 info.getReceiveTimeMillis(rat, freq)
8768 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8769 }
8770
8771 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8772 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8773 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8774 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8775
8776 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8777 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8778 }
8779 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8780 mLastModemActivityInfo.setReceiveTimeMillis(
8781 rat,
8782 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8783 }
8784
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008785 /**
8786 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8787 * @param info recent ModemActivityInfo
8788 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008789 private void mergeModemActivityInfo(ModemActivityInfo info) {
8790 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008791 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008792 boolean matched;
8793 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8794 matched = false;
8795 int rat = info.getSpecificInfoRat(i);
8796 int freq = info.getSpecificInfoFrequencyRange(i);
8797 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8798 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8799 //if it already exists
8800 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8801 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8802 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8803 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8804 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8805 updateLastModemActivityInfo(info, rat, freq);
8806 matched = true;
8807 }
8808 } else {
8809 updateLastModemActivityInfo(info, rat);
8810 matched = true;
8811 }
8812 }
8813 }
8814
8815 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008816 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008817 new ActivityStatsTechSpecificInfo(
8818 rat,
8819 freq,
8820 info.getTransmitTimeMillis(rat, freq),
8821 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008822 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008823 }
8824 }
8825 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8826 mLastModemActivitySpecificInfo =
8827 new ActivityStatsTechSpecificInfo[merged.size()];
8828 merged.toArray(mLastModemActivitySpecificInfo);
8829
8830 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8831 mLastModemActivityInfo.setSleepTimeMillis(
8832 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008833 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008834 mLastModemActivityInfo.setIdleTimeMillis(
8835 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008836 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008837
8838 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008839 new ModemActivityInfo(
8840 mLastModemActivityInfo.getTimestampMillis(),
8841 mLastModemActivityInfo.getSleepTimeMillis(),
8842 mLastModemActivityInfo.getIdleTimeMillis(),
8843 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008844 }
8845
8846 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8847 ActivityStatsTechSpecificInfo[] info) {
8848 int infoSize = info.length;
8849 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8850 for (int i = 0; i < infoSize; i++) {
8851 ret[i] = new ActivityStatsTechSpecificInfo(
8852 info[i].getRat(), info[i].getFrequencyRange(),
8853 info[i].getTransmitTimeMillis(),
8854 (int) info[i].getReceiveTimeMillis());
8855 }
8856 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008857 }
8858
Jack Yu85bd38a2015-11-09 11:34:32 -08008859 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008860 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008861 */
8862 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008863 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8864 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8865 Phone phone = PhoneFactory.getPhone(slotIndex);
8866 if (phone == null) {
8867 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8868 return null;
8869 }
8870
8871 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008873 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008874 return null;
8875 }
8876
joonhunshin4ac60942023-11-15 15:23:39 +00008877 enforceTelephonyFeatureWithException(callingPackage,
8878 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8879
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008880 boolean hasFinePermission = false;
8881 boolean hasCoarsePermission = false;
8882 if (!renounceFineLocationAccess) {
8883 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8884 LocationAccessPolicy.checkLocationPermission(mApp,
8885 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8886 .setCallingPackage(callingPackage)
8887 .setCallingFeatureId(callingFeatureId)
8888 .setCallingPid(Binder.getCallingPid())
8889 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008890 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008891 .setLogAsInfo(true)
8892 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8893 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8894 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8895 .build());
8896 hasFinePermission =
8897 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8898 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008899
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008900 if (!renounceCoarseLocationAccess) {
8901 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8902 LocationAccessPolicy.checkLocationPermission(mApp,
8903 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8904 .setCallingPackage(callingPackage)
8905 .setCallingFeatureId(callingFeatureId)
8906 .setCallingPid(Binder.getCallingPid())
8907 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008908 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008909 .setLogAsInfo(true)
8910 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8911 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8912 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8913 .build());
8914 hasCoarsePermission =
8915 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8916 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008917
Jordan Liu0f2bc442020-11-18 16:47:37 -08008918 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008920 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8921 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008922 if (subInfo != null && !subInfo.isActive()) {
8923 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008924 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008925 }
8926
Hall Liuf19c44f2018-11-27 14:38:17 -08008927 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008928 boolean isCallingPackageDataService = phone.getDataServicePackages()
8929 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008930
8931 // Scrub out the location info in ServiceState depending on what level of access
8932 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008933 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008934 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8935 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 } finally {
8937 Binder.restoreCallingIdentity(identity);
8938 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008939 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008940
8941 /**
8942 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8943 *
8944 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8945 * voicemail ringtone.
8946 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8947 * PhoneAccount.
8948 */
8949 @Override
8950 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008951 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8952 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 final long identity = Binder.clearCallingIdentity();
8955 try {
8956 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8957 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008958 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8962 } finally {
8963 Binder.restoreCallingIdentity(identity);
8964 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008965 }
8966
8967 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008968 * Sets the per-account voicemail ringtone.
8969 *
8970 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8971 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8972 *
8973 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8974 * voicemail ringtone.
8975 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8976 * PhoneAccount.
8977 */
8978 @Override
8979 public void setVoicemailRingtoneUri(String callingPackage,
8980 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008981 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008983 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8984 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8986 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8987 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989
joonhunshin4ac60942023-11-15 15:23:39 +00008990 enforceTelephonyFeatureWithException(callingPackage,
8991 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8996 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008997 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008998 }
8999 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 }
9004
9005 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009006 * Returns whether vibration is set for voicemail notification in Phone settings.
9007 *
9008 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9009 * voicemail vibration setting.
9010 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9011 */
9012 @Override
9013 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9015 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009017 final long identity = Binder.clearCallingIdentity();
9018 try {
9019 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9020 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009021 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009022 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009024 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9025 } finally {
9026 Binder.restoreCallingIdentity(identity);
9027 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009028 }
9029
Youhan Wange64578a2016-05-02 15:32:42 -07009030 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009031 * Sets the per-account voicemail vibration.
9032 *
9033 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9034 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9035 *
9036 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9037 * voicemail vibration setting.
9038 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9039 * specific PhoneAccount.
9040 */
9041 @Override
9042 public void setVoicemailVibrationEnabled(String callingPackage,
9043 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009044 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009046 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9047 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9049 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9050 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009051 }
9052
joonhunshin4ac60942023-11-15 15:23:39 +00009053 enforceTelephonyFeatureWithException(callingPackage,
9054 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9059 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009060 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009061 }
9062 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009065 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009066 }
9067
9068 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009069 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9070 *
9071 * @throws SecurityException if the caller does not have the required permission
9072 */
arunvoddud7401012022-12-15 16:08:12 +00009073 @VisibleForTesting
9074 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009075 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009076 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009077 }
9078
9079 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009080 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9081 * permission.
9082 *
9083 * @throws SecurityException if the caller does not have the required permission
9084 */
9085 private void enforceSendSmsPermission() {
9086 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9087 }
9088
9089 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009090 * Make sure either called from same process as self (phone) or IPC caller has interact across
9091 * users permission.
9092 *
9093 * @throws SecurityException if the caller does not have the required permission
9094 */
9095 private void enforceInteractAcrossUsersPermission(String message) {
9096 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9097 }
9098
9099 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009100 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009101 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009102 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009103 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009104 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009108 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009109 if (componentName == null) {
9110 throw new SecurityException(
9111 "Caller not current active visual voicemail package[null]");
9112 }
9113 String vvmPackage = componentName.getPackageName();
9114 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009115 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009116 }
9117 } finally {
9118 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009119 }
9120 }
9121
9122 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009123 * Return the application ID for the app type.
9124 *
9125 * @param subId the subscription ID that this request applies to.
9126 * @param appType the uicc app type.
9127 * @return Application ID for specificied app type, or null if no uicc.
9128 */
9129 @Override
9130 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009131 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009132
9133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9134 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9135
Youhan Wange64578a2016-05-02 15:32:42 -07009136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009137
9138 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009139 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009140 if (phone == null) {
9141 return null;
9142 }
9143 String aid = null;
9144 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009145 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146 .getApplicationByType(appType).getAid();
9147 } catch (Exception e) {
9148 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9149 }
9150 return aid;
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009153 }
Youhan Wange64578a2016-05-02 15:32:42 -07009154 }
9155
Youhan Wang4001d252016-05-11 10:29:41 -07009156 /**
9157 * Return the Electronic Serial Number.
9158 *
9159 * @param subId the subscription ID that this request applies to.
9160 * @return ESN or null if error.
9161 */
9162 @Override
9163 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009164 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009165 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166
9167 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009168 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009169 if (phone == null) {
9170 return null;
9171 }
9172 String esn = null;
9173 try {
9174 esn = phone.getEsn();
9175 } catch (Exception e) {
9176 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9177 }
9178 return esn;
9179 } finally {
9180 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009181 }
Youhan Wang4001d252016-05-11 10:29:41 -07009182 }
9183
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009184 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009185 * Return the Preferred Roaming List Version.
9186 *
9187 * @param subId the subscription ID that this request applies to.
9188 * @return PRLVersion or null if error.
9189 */
9190 @Override
9191 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009192 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009193
9194 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9195 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9196
Youhan Wang66ad5d72016-07-18 17:56:58 -07009197 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009198
9199 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009200 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009201 if (phone == null) {
9202 return null;
9203 }
9204 String cdmaPrlVersion = null;
9205 try {
9206 cdmaPrlVersion = phone.getCdmaPrlVersion();
9207 } catch (Exception e) {
9208 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9209 }
9210 return cdmaPrlVersion;
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009213 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009214 }
9215
9216 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009217 * Get snapshot of Telephony histograms
9218 * @return List of Telephony histograms
9219 * @hide
9220 */
9221 @Override
9222 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9224 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009225
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
9228 return RIL.getTelephonyRILTimingHistograms();
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009232 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009233
9234 /**
9235 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009236 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9237 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009238 * Require system privileges. In the future we may add this to carrier APIs.
9239 *
Michele Berionne482f8202018-11-27 18:57:59 -08009240 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009241 */
9242 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009243 @TelephonyManager.SetCarrierRestrictionResult
9244 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009245 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009246
9247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9248 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9249
vagdeviaf9a5b92018-08-15 16:01:53 -07009250 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009251
Michele Berionne482f8202018-11-27 18:57:59 -08009252 if (carrierRestrictionRules == null) {
9253 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009254 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009256 final long identity = Binder.clearCallingIdentity();
9257 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009258 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009259 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009263 }
9264
9265 /**
9266 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009267 * Get the allowed carrier list and the excluded carrier list, including the priority between
9268 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009269 * Require system privileges. In the future we may add this to carrier APIs.
9270 *
Michele Berionne482f8202018-11-27 18:57:59 -08009271 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009272 */
9273 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009274 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009275 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009276
9277 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9278 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9279
vagdeviaf9a5b92018-08-15 16:01:53 -07009280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009281
9282 final long identity = Binder.clearCallingIdentity();
9283 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009284 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9285 if (response instanceof CarrierRestrictionRules) {
9286 return (CarrierRestrictionRules) response;
9287 }
9288 // Response is an Exception of some kind,
9289 // which is signalled to the user as a NULL retval
9290 return null;
9291 } catch (Exception e) {
9292 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9293 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009294 } finally {
9295 Binder.restoreCallingIdentity(identity);
9296 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009297 }
9298
fionaxu59545b42016-05-25 15:53:37 -07009299 /**
arunvoddud7401012022-12-15 16:08:12 +00009300 * Fetches the carrier restriction status of the device and sends the status to the caller
9301 * through the callback.
9302 *
9303 * @param callback The callback that will be used to send the result.
9304 * @throws SecurityException if the caller does not have the required permission/privileges or
9305 * the caller is not allowlisted.
9306 */
9307 @Override
9308 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009309 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009310 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009311 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9312 try {
9313 mApp.enforceCallingOrSelfPermission(
9314 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9315 functionName);
9316 } catch (SecurityException e) {
9317 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9318 functionName);
9319 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009320 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9321 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009322 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9323 throw new SecurityException("Not an authorized caller");
9324 }
9325 final long identity = Binder.clearCallingIdentity();
9326 try {
9327 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009328 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009329 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
arunvoddu567f2b42023-04-25 17:22:00 +00009335 @Override
9336 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9337 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9338 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9339 return allowListInfo.getShaIdList(pkgName, carrierId);
9340 }
9341
arunvoddud7401012022-12-15 16:08:12 +00009342 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009343 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009344 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009345 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009346 }
9347
9348 /**
fionaxu59545b42016-05-25 15:53:37 -07009349 * Action set from carrier signalling broadcast receivers to enable/disable radio
9350 * @param subId the subscription ID that this action applies to.
9351 * @param enabled control enable or disable radio.
9352 * {@hide}
9353 */
9354 @Override
9355 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9356 enforceModifyPermission();
9357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009358
9359 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009360 if (phone == null) {
9361 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9362 return;
9363 }
9364 try {
9365 phone.carrierActionSetRadioEnabled(enabled);
9366 } catch (Exception e) {
9367 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009368 } finally {
9369 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009370 }
9371 }
9372
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009373 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009374 * Enable or disable Voice over NR (VoNR)
9375 * @param subId the subscription ID that this action applies to.
9376 * @param enabled enable or disable VoNR.
9377 * @return operation result.
9378 */
9379 @Override
9380 public int setVoNrEnabled(int subId, boolean enabled) {
9381 enforceModifyPermission();
9382 final Phone phone = getPhone(subId);
9383
9384 final long identity = Binder.clearCallingIdentity();
9385 if (phone == null) {
9386 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9387 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9388 }
9389
9390 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9391 try {
9392 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9393 workSource);
9394 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009395
9396 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9397 if (DBG) {
9398 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9399 }
9400 SubscriptionManager.setSubscriptionProperty(
9401 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9402 (enabled ? "1" : "0"));
9403 }
9404
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009405 return result;
9406 } finally {
9407 Binder.restoreCallingIdentity(identity);
9408 }
9409 }
9410
9411 /**
9412 * Is voice over NR enabled
9413 * @return true if VoNR is enabled else false
9414 */
9415 @Override
9416 public boolean isVoNrEnabled(int subId) {
9417 enforceReadPrivilegedPermission("isVoNrEnabled");
9418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9419 final long identity = Binder.clearCallingIdentity();
9420 try {
9421 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9422 null, subId, workSource);
9423 if (DBG) log("isVoNrEnabled: " + isEnabled);
9424 return isEnabled;
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
9430 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009431 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9432 * network status based on which carrier apps could apply actions accordingly,
9433 * enable/disable default url handler for example.
9434 *
9435 * @param subId the subscription ID that this action applies to.
9436 * @param report control start/stop reporting the default network status.
9437 * {@hide}
9438 */
9439 @Override
9440 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9441 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009442
9443 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9444 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9445 "carrierActionReportDefaultNetworkStatus");
9446
fionaxu8da9cb12017-05-23 15:02:46 -07009447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009448
9449 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009450 if (phone == null) {
9451 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9452 return;
9453 }
9454 try {
9455 phone.carrierActionReportDefaultNetworkStatus(report);
9456 } catch (Exception e) {
9457 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009458 } finally {
9459 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009460 }
9461 }
9462
9463 /**
fionaxud9622282017-07-17 17:51:30 -07009464 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9465 * @param subId the subscription ID that this action applies to.
9466 * {@hide}
9467 */
9468 @Override
9469 public void carrierActionResetAll(int subId) {
9470 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009471
9472 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9473 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9474
fionaxud9622282017-07-17 17:51:30 -07009475 final Phone phone = getPhone(subId);
9476 if (phone == null) {
9477 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9478 return;
9479 }
9480 try {
9481 phone.carrierActionResetAll();
9482 } catch (Exception e) {
9483 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9484 }
9485 }
9486
9487 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009488 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9489 * bug report is being generated.
9490 */
9491 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009492 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009493 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9494 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009495 writer.println("Permission Denial: can't dump Phone from pid="
9496 + Binder.getCallingPid()
9497 + ", uid=" + Binder.getCallingUid()
9498 + "without permission "
9499 + android.Manifest.permission.DUMP);
9500 return;
9501 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009502 try {
9503 DumpsysHandler.dump(mApp, fd, writer, args);
9504 } catch (Exception e) {
9505 writer.println("Failed to dump phone information: " + e);
9506 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009507 }
Jack Yueb89b242016-06-22 13:27:47 -07009508
Brad Ebingerdac2f002018-04-03 15:17:52 -07009509 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009510 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9511 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9512 @NonNull String[] args) {
9513 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9514 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009515 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009516 }
9517
Jack Yueb89b242016-06-22 13:27:47 -07009518 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009519 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009520 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009521 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009522 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009523 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009524 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009525 */
9526 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009527 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009528 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009529 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9530 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9531 try {
9532 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009533 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009534 } catch (SecurityException se) {
9535 enforceModifyPermission();
9536 }
9537 } else {
9538 enforceModifyPermission();
9539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009540
joonhunshin4ac60942023-11-15 15:23:39 +00009541 enforceTelephonyFeatureWithException(callingPackage,
9542 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9543
Nate Myren116695d2024-02-09 09:36:01 -08009544 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009545 final long identity = Binder.clearCallingIdentity();
9546 try {
Nate Myren116695d2024-02-09 09:36:01 -08009547 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9548 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009549 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009550 callingUid, callingPackage, null, null);
9551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009552 Phone phone = getPhone(subId);
9553 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009554 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9555 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009556 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009557 phone.getDataSettingsManager().setDataEnabled(
9558 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009563 }
9564 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009565
9566 /**
9567 * Get Client request stats
9568 * @return List of Client Request Stats
9569 * @hide
9570 */
9571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009572 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9573 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009575 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009576 return null;
9577 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009578 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 if (phone != null) {
9583 return phone.getClientRequestStats();
9584 }
9585
9586 return null;
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
9589 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009590 }
9591
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009592 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009593 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009594 if (uid == Process.ROOT_UID && packageName == null) {
9595 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9596 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9597 // exception. ROOT_UID seems not to have a valid package name returned by
9598 // PackageManager, so just fake it here to avoid issues when running telephony shell
9599 // commands that plumb through the RIL as root, like so:
9600 // $ adb root
9601 // $ adb shell cmd phone ...
9602 packageName = "root";
9603 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009604 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009605 }
Jack Yueb4124c2017-02-16 15:32:43 -08009606
9607 /**
Grace Chen70990072017-03-24 17:21:30 -07009608 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009609 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009610 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009611 * @param state State of SIM (power down, power up, pass through)
9612 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9613 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9614 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009615 *
9616 **/
9617 @Override
Grace Chen70990072017-03-24 17:21:30 -07009618 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009619 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009620
9621 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9622 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9623
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009624 Phone phone = PhoneFactory.getPhone(slotIndex);
9625
vagdeviaf9a5b92018-08-15 16:01:53 -07009626 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009628 final long identity = Binder.clearCallingIdentity();
9629 try {
9630 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009631 phone.setSimPowerState(state, null, workSource);
9632 }
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
9637
9638 /**
9639 * Set SIM card power state.
9640 *
9641 * @param slotIndex SIM slot id.
9642 * @param state State of SIM (power down, power up, pass through)
9643 * @param callback callback to trigger after success or failure
9644 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9645 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9646 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9647 *
9648 **/
9649 @Override
9650 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9651 IIntegerConsumer callback) {
9652 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009653
9654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9655 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9656 "setSimPowerStateForSlotWithCallback");
9657
Jordan Liu109698e2020-11-24 14:50:34 -08009658 Phone phone = PhoneFactory.getPhone(slotIndex);
9659
9660 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9661
9662 final long identity = Binder.clearCallingIdentity();
9663 try {
9664 if (phone != null) {
9665 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9666 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009667 }
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009670 }
9671 }
Shuo Qiandd210312017-04-12 22:11:33 +00009672
Tyler Gunn65d45c22017-06-05 11:22:26 -07009673 private boolean isUssdApiAllowed(int subId) {
9674 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009675 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009676 if (configManager == null) {
9677 return false;
9678 }
9679 PersistableBundle pb = configManager.getConfigForSubId(subId);
9680 if (pb == null) {
9681 return false;
9682 }
9683 return pb.getBoolean(
9684 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9685 }
9686
Shuo Qiandd210312017-04-12 22:11:33 +00009687 /**
Ling Mac28f0212023-03-24 16:07:15 -07009688 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009689 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009690 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009691 */
goneil9c5f4872017-12-05 14:07:56 -08009692 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009693 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009694 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009695
9696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9697 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009699 final long identity = Binder.clearCallingIdentity();
9700 try {
Ling Mac28f0212023-03-24 16:07:15 -07009701 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009702 } finally {
9703 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009704 }
9705 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009706
9707 /**
9708 * Get the current signal strength information for the given subscription.
9709 * Because this information is not updated when the device is in a low power state
9710 * it should not be relied-upon to be current.
9711 * @param subId Subscription index
9712 * @return the most recent cached signal strength info from the modem
9713 */
9714 @Override
9715 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009716 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9717 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009719 final long identity = Binder.clearCallingIdentity();
9720 try {
9721 Phone p = getPhone(subId);
9722 if (p == null) {
9723 return null;
9724 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009726 return p.getSignalStrength();
9727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009730 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009731
Pengquan Meng77b7f132018-08-22 14:49:57 -07009732 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009733 * Get the current modem radio state for the given slot.
9734 * @param slotIndex slot index.
9735 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009736 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009737 * @return the current radio power state from the modem
9738 */
9739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009740 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009741 Phone phone = PhoneFactory.getPhone(slotIndex);
9742 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9744 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009745 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9746 }
9747
joonhunshin4ac60942023-11-15 15:23:39 +00009748 enforceTelephonyFeatureWithException(callingPackage,
9749 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9750
Chen Xuf792fd62018-10-17 17:54:36 +00009751 final long identity = Binder.clearCallingIdentity();
9752 try {
9753 return phone.getRadioPowerState();
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
9757 }
9758 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9759 }
9760
9761 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009762 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9763 *
9764 * <p>Requires one of the following permissions:
9765 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009766 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009767 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9768 * privileges.
9769 *
9770 * @param subId subscription id
9771 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9772 * {@code false}.
9773 */
9774 @Override
9775 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009776 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009777 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009778 try {
9779 mApp.enforceCallingOrSelfPermission(
9780 android.Manifest.permission.ACCESS_NETWORK_STATE,
9781 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009782 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009783 mApp.enforceCallingOrSelfPermission(
9784 permission.READ_BASIC_PHONE_STATE, functionName);
9785 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009786 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009787 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009788 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009789 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009790
joonhunshin4ac60942023-11-15 15:23:39 +00009791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9792 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9793
Pengquan Menga1bb6272018-09-06 09:59:22 -07009794 boolean isEnabled = false;
9795 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009796 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009797 Phone phone = getPhone(subId);
9798 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009799 } finally {
9800 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009801 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009802 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009803 }
9804
9805
9806 /**
9807 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9808 *
9809 * <p> Requires permission:
9810 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9811 * privileges.
9812 *
9813 * @param subId subscription id
9814 * @param isEnabled {@code true} means enable, {@code false} means disable.
9815 */
9816 @Override
9817 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9819 mApp, subId, "setDataRoamingEnabled");
9820
joonhunshin4ac60942023-11-15 15:23:39 +00009821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9822 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9823
Pengquan Menga1bb6272018-09-06 09:59:22 -07009824 final long identity = Binder.clearCallingIdentity();
9825 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009826 Phone phone = getPhone(subId);
9827 if (phone != null) {
9828 phone.setDataRoamingEnabled(isEnabled);
9829 }
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009832 }
9833 }
9834
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009835 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009836 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009837 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009838 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009839 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009840
joonhunshin4ac60942023-11-15 15:23:39 +00009841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9842 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9843
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009844 boolean isAllowed = true;
9845 final long identity = Binder.clearCallingIdentity();
9846 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009847 Phone phone = getPhone(subId);
9848 if (phone != null) {
9849 isAllowed = phone.isCspPlmnEnabled();
9850 }
9851 } finally {
9852 Binder.restoreCallingIdentity(identity);
9853 }
9854 return isAllowed;
9855 }
9856
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009857 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9858 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009859 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009860 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009861 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009862 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9863 if (phone == null) {
9864 return false;
9865 }
9866 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9867 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9868 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009869 }
9870
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009871 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009872 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009873 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009874 mApp.getSystemService(AppOpsManager.class)
9875 .checkPackage(Binder.getCallingUid(), callingPackage);
9876
Jordan Liu1e142fc2019-04-22 15:10:43 -07009877 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009878 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009879 try {
9880 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009881 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009882 } catch (SecurityException e) {
9883 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9884 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009885 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009886 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009887 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009888 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009889 }
joonhunshin4ac60942023-11-15 15:23:39 +00009890
9891 enforceTelephonyFeatureWithException(callingPackage,
9892 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9893
sandeepjsb6c87872021-09-27 15:34:44 +00009894 // checking compatibility, if calling app's target SDK is T and beyond.
9895 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9896 Binder.getCallingUid())) {
9897 isIccIdAccessRestricted = true;
9898 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009899 final long identity = Binder.clearCallingIdentity();
9900 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009901 UiccController uiccController = UiccController.getInstance();
9902 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009903 if (hasReadPermission) {
9904 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009905 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009906
9907 // Remove private info if the caller doesn't have access
9908 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9909 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009910 //setting the value after compatibility check
9911 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009912 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9913 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009914 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009915 if (card == null) {
9916 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009917 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009918 continue;
9919 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009920 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9921 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009922 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009923 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009924 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009925 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9926 for (UiccPortInfo portInfo : portInfos) {
9927 UiccPort port = uiccController.getUiccPortForSlot(
9928 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9929 if (port == null) {
9930 // assume no access if port is null
9931 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9932 continue;
9933 }
9934 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9935 uiccPortInfos.add(portInfo);
9936 } else {
9937 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9938 }
9939 }
9940 filteredInfos.add(new UiccCardInfo(
9941 cardInfo.isEuicc(),
9942 cardInfo.getCardId(),
9943 null,
9944 cardInfo.getPhysicalSlotIndex(),
9945 cardInfo.isRemovable(),
9946 cardInfo.isMultipleEnabledProfilesSupported(),
9947 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009948 }
9949 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
sandeepjsb6c87872021-09-27 15:34:44 +00009955 /**
9956 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9957 * generally private and require carrier privileges to view.
9958 *
9959 * @hide
9960 */
9961 @NonNull
9962 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9963 List<UiccPortInfo> portinfo = new ArrayList<>();
9964 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9965 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9966 }
9967 return new UiccCardInfo(
9968 cardInfo.isEuicc(),
9969 cardInfo.getCardId(),
9970 null,
9971 cardInfo.getPhysicalSlotIndex(),
9972 cardInfo.isRemovable(),
9973 cardInfo.isMultipleEnabledProfilesSupported(),
9974 portinfo
9975 );
9976 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009977
sandeepjsb6c87872021-09-27 15:34:44 +00009978 /**
9979 * @hide
9980 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9981 * These values are generally private and require carrier privileges to view.
9982 */
9983 @NonNull
9984 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9985 return new UiccPortInfo(
9986 UiccPortInfo.ICCID_REDACTED,
9987 portInfo.getPortIndex(),
9988 portInfo.getLogicalSlotIndex(),
9989 portInfo.isActive()
9990 );
9991 }
9992 @Override
9993 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009994 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009995 mApp.getSystemService(AppOpsManager.class)
9996 .checkPackage(Binder.getCallingUid(), callingPackage);
9997
sandeepjsb6c87872021-09-27 15:34:44 +00009998 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009999
Aman Guptaf3c90b32022-03-17 04:54:16 +000010000 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10001 // we are reading iccId which is PII data.
10002 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010003
joonhunshin4ac60942023-11-15 15:23:39 +000010004 enforceTelephonyFeatureWithException(callingPackage,
10005 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10006
sandeepjsb6c87872021-09-27 15:34:44 +000010007 // checking compatibility, if calling app's target SDK is T and beyond.
10008 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10009 Binder.getCallingUid())) {
10010 isLogicalSlotAccessRestricted = true;
10011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010012 final long identity = Binder.clearCallingIdentity();
10013 try {
10014 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010015 if (slots == null || slots.length == 0) {
10016 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010017 return null;
10018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010019 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10020 for (int i = 0; i < slots.length; i++) {
10021 UiccSlot slot = slots[i];
10022 if (slot == null) {
10023 continue;
10024 }
10025
Jordan Liu7be7e652019-05-06 18:55:02 +000010026 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010027 UiccCard card = slot.getUiccCard();
10028 if (card != null) {
10029 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010030 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010031 cardId = slot.getEid();
10032 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010033 // If cardId is null, use iccId of default port as cardId.
10034 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036 }
10037
Jordan Liu857451f2019-05-09 16:35:35 -070010038 if (cardId != null) {
10039 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10040 // if cardId is an EID, it's all digits so this is fine
10041 cardId = IccUtils.stripTrailingFs(cardId);
10042 }
10043
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010044 int cardState = 0;
10045 switch (slot.getCardState()) {
10046 case CARDSTATE_ABSENT:
10047 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10048 break;
10049 case CARDSTATE_PRESENT:
10050 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10051 break;
10052 case CARDSTATE_ERROR:
10053 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10054 break;
10055 case CARDSTATE_RESTRICTED:
10056 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10057 break;
10058 default:
10059 break;
10060
10061 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010062 List<UiccPortInfo> portInfos = new ArrayList<>();
10063 int[] portIndexes = slot.getPortList();
10064 for (int portIdx : portIndexes) {
10065 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010066 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010067 portInfos.add(new UiccPortInfo(iccId, portIdx,
10068 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010070 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010071 slot.isEuicc(),
10072 cardId,
10073 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010074 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010075 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010076 //setting the value after compatibility check
10077 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010078 }
10079 return infos;
10080 } finally {
10081 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010082 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010083 }
10084
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010085 /* Returns null if doesn't have read permission or carrier privilege access. */
10086 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10087 boolean hasReadPermission) {
10088 String iccId = slot.getIccId(portIndex);
10089 if (hasReadPermission) { // if has read permission
10090 return iccId;
10091 } else {
10092 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10093 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10094 // if no read permission, checking carrier privilege access
10095 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10096 return iccId;
10097 }
10098 }
10099 }
10100 // No read permission or carrier privilege access.
10101 return UiccPortInfo.ICCID_REDACTED;
10102 }
10103
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010104 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010105 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010106 public boolean switchSlots(int[] physicalSlots) {
10107 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010108
joonhunshin4ac60942023-11-15 15:23:39 +000010109 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10110 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10111
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010112 final long identity = Binder.clearCallingIdentity();
10113 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010114 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10115 for (int i = 0; i < physicalSlots.length; i++) {
10116 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10117 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10118 physicalSlots[i], i));
10119 }
10120 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010121 } finally {
10122 Binder.restoreCallingIdentity(identity);
10123 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010124 }
Jack Yu4c988042018-02-27 15:30:01 -080010125
10126 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010127 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10128 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10129 enforceModifyPermission();
10130
joonhunshin4ac60942023-11-15 15:23:39 +000010131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10132 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10133
sandeepjsb6c87872021-09-27 15:34:44 +000010134 final long identity = Binder.clearCallingIdentity();
10135 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010136 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010137 } finally {
10138 Binder.restoreCallingIdentity(identity);
10139 }
10140 }
10141
10142 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010143 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010144 enforceTelephonyFeatureWithException(callingPackage,
10145 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10146
Jordan Liu7de49fa2018-12-06 14:48:49 -080010147 final long identity = Binder.clearCallingIdentity();
10148 try {
10149 return UiccController.getInstance().getCardIdForDefaultEuicc();
10150 } finally {
10151 Binder.restoreCallingIdentity(identity);
10152 }
10153 }
10154
Pengquan Meng85728fb2018-03-12 16:31:21 -070010155 /**
goneil47ffb6e2018-04-06 15:40:58 -070010156 * A test API to reload the UICC profile.
10157 *
10158 * <p>Requires that the calling app has permission
10159 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10160 * @hide
10161 */
10162 @Override
10163 public void refreshUiccProfile(int subId) {
10164 enforceModifyPermission();
10165
10166 final long identity = Binder.clearCallingIdentity();
10167 try {
10168 Phone phone = getPhone(subId);
10169 if (phone == null) {
10170 return;
10171 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010172 UiccPort uiccPort = phone.getUiccPort();
10173 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010174 return;
10175 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010176 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010177 if (uiccProfile == null) {
10178 return;
10179 }
10180 uiccProfile.refresh();
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010187 * Returns false if the mobile data is disabled by default, otherwise return true.
10188 */
10189 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010190 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010191 }
10192
10193 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010194 * Returns the default network type for the given {@code subId}, if the default network type is
10195 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10196 */
10197 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010198 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010199 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010200 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10201 return list.get(phoneId);
10202 }
10203 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010204 }
fionaxua13278b2018-03-21 00:08:13 -070010205
10206 @Override
10207 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010208 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010210
10211 final long identity = Binder.clearCallingIdentity();
10212 try {
10213 final Phone phone = getPhone(subId);
10214 if (phone == null) {
10215 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10216 return;
10217 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010218 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10219 if (cpt != null) {
10220 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10221 }
10222 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010223 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10224 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010225 if (carrierPrivilegeRules == null) {
10226 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10227 } else {
10228 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010230 } finally {
10231 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010232 }
fionaxua13278b2018-03-21 00:08:13 -070010233 }
10234
10235 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010236 public void setCarrierServicePackageOverride(
10237 int subId, String carrierServicePackage, String callingPackage) {
10238 TelephonyPermissions.enforceShellOnly(
10239 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10240
Benedict Wong66477622023-02-03 23:30:57 +000010241 final long identity = Binder.clearCallingIdentity();
10242 try {
10243 final Phone phone = getPhone(subId);
10244 if (phone == null || phone.getSubId() != subId) {
10245 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10246 throw new IllegalArgumentException("No phone for subid");
10247 }
10248 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10249 if (cpt == null) {
10250 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10251 throw new IllegalStateException("No CPT for phone");
10252 }
10253 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10254 } finally {
10255 Binder.restoreCallingIdentity(identity);
10256 }
10257 }
10258
10259 @Override
fionaxua13278b2018-03-21 00:08:13 -070010260 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010261 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010262
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 final Phone phone = getPhone(subId);
10266 if (phone == null) {
10267 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10268 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10269 }
10270 return phone.getCarrierIdListVersion();
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010273 }
fionaxua13278b2018-03-21 00:08:13 -070010274 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010275
10276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010277 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10278 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010280 mApp, subId, callingPackage, callingFeatureId,
10281 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010282 return -1;
10283 }
10284
10285 final long identity = Binder.clearCallingIdentity();
10286 try {
10287 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10288 } finally {
10289 Binder.restoreCallingIdentity(identity);
10290 }
10291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010292
10293 @Override
10294 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010295 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010296 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010297 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010298
joonhunshin4ac60942023-11-15 15:23:39 +000010299 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10300 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10301
Pengquan Menga1bb6272018-09-06 09:59:22 -070010302 final long identity = Binder.clearCallingIdentity();
10303 try {
10304 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
10308 }
10309
10310 @Override
10311 public boolean setCdmaRoamingMode(int subId, int mode) {
10312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10313 mApp, subId, "setCdmaRoamingMode");
10314
joonhunshin4ac60942023-11-15 15:23:39 +000010315 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10316 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10317
Pengquan Menga1bb6272018-09-06 09:59:22 -070010318 final long identity = Binder.clearCallingIdentity();
10319 try {
10320 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
10326 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010327 public int getCdmaSubscriptionMode(int subId) {
10328 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010329 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010330 mApp, subId, "getCdmaSubscriptionMode");
10331
joonhunshin4ac60942023-11-15 15:23:39 +000010332 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10333 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10334
Sarah Chinbaab1432020-10-28 13:46:24 -070010335 final long identity = Binder.clearCallingIdentity();
10336 try {
10337 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10338 } finally {
10339 Binder.restoreCallingIdentity(identity);
10340 }
10341 }
10342
10343 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010344 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10346 mApp, subId, "setCdmaSubscriptionMode");
10347
joonhunshin4ac60942023-11-15 15:23:39 +000010348 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10349 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10350
Pengquan Menga1bb6272018-09-06 09:59:22 -070010351 final long identity = Binder.clearCallingIdentity();
10352 try {
10353 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010358
sqianc5eccab2018-10-19 18:46:41 -070010359 @Override
sqian8c685422019-02-22 15:55:18 -080010360 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010361 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010363 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10364 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010365 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10366 }
joonhunshin4ac60942023-11-15 15:23:39 +000010367
10368 enforceTelephonyFeatureWithException(callingPackage,
10369 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10370
sqian11b7a0e2018-12-05 18:48:28 -080010371 final long identity = Binder.clearCallingIdentity();
10372 try {
sqian854d44b2018-12-12 16:48:18 -080010373 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10374 for (Phone phone: PhoneFactory.getPhones()) {
10375 if (phone.getEmergencyNumberTracker() != null
10376 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10377 emergencyNumberListInternal.put(
10378 phone.getSubId(),
10379 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10380 }
sqian11b7a0e2018-12-05 18:48:28 -080010381 }
sqian854d44b2018-12-12 16:48:18 -080010382 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
sqianc5eccab2018-10-19 18:46:41 -070010386 }
10387
10388 @Override
sqian8c685422019-02-22 15:55:18 -080010389 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010390 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010391 if (!exactMatch) {
10392 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010393 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010394 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010395 }
joonhunshin4ac60942023-11-15 15:23:39 +000010396
10397 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10398 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10399
sqian11b7a0e2018-12-05 18:48:28 -080010400 final long identity = Binder.clearCallingIdentity();
10401 try {
sqian854d44b2018-12-12 16:48:18 -080010402 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010403 //Note: we ignore passed in param exactMatch. We can remove it once
10404 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010405 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010406 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010407 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010408 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010409 }
sqian11b7a0e2018-12-05 18:48:28 -080010410 }
10411 return false;
10412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
sqianf4ca7ed2019-01-15 18:32:07 -080010417 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010418 * Start emergency callback mode for GsmCdmaPhone for testing.
10419 */
10420 @Override
10421 public void startEmergencyCallbackMode() {
10422 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10423 "startEmergencyCallbackMode");
10424 enforceModifyPermission();
10425 final long identity = Binder.clearCallingIdentity();
10426 try {
10427 for (Phone phone : PhoneFactory.getPhones()) {
10428 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10429 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10430 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10431 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10432 gsmCdmaPhone.obtainMessage(
10433 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10434 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10435 }
10436 }
10437 } finally {
10438 Binder.restoreCallingIdentity(identity);
10439 }
10440 }
10441
10442 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010443 * Update emergency number list for test mode.
10444 */
10445 @Override
10446 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10447 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10448 "updateEmergencyNumberListTestMode");
10449
10450 final long identity = Binder.clearCallingIdentity();
10451 try {
10452 for (Phone phone: PhoneFactory.getPhones()) {
10453 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10454 if (tracker != null) {
10455 tracker.executeEmergencyNumberTestModeCommand(action, num);
10456 }
10457 }
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
10463 /**
10464 * Get the full emergency number list for test mode.
10465 */
10466 @Override
10467 public List<String> getEmergencyNumberListTestMode() {
10468 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10469 "getEmergencyNumberListTestMode");
10470
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 Set<String> emergencyNumbers = new HashSet<>();
10474 for (Phone phone: PhoneFactory.getPhones()) {
10475 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10476 if (tracker != null) {
10477 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10478 emergencyNumbers.add(num.getNumber());
10479 }
10480 }
10481 }
10482 return new ArrayList<>(emergencyNumbers);
10483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
10487
chen xud6b45bd2018-10-30 22:27:10 -070010488 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010489 public int getEmergencyNumberDbVersion(int subId) {
10490 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10491
joonhunshin4ac60942023-11-15 15:23:39 +000010492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10493 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10494
Shuo Qian3b6ee772019-11-13 17:43:31 -080010495 final long identity = Binder.clearCallingIdentity();
10496 try {
10497 final Phone phone = getPhone(subId);
10498 if (phone == null) {
10499 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10500 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10501 }
10502 return phone.getEmergencyNumberDbVersion();
10503 } finally {
10504 Binder.restoreCallingIdentity(identity);
10505 }
10506 }
10507
10508 @Override
10509 public void notifyOtaEmergencyNumberDbInstalled() {
10510 enforceModifyPermission();
10511
joonhunshin4ac60942023-11-15 15:23:39 +000010512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10513 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10514
Shuo Qian3b6ee772019-11-13 17:43:31 -080010515 final long identity = Binder.clearCallingIdentity();
10516 try {
10517 for (Phone phone: PhoneFactory.getPhones()) {
10518 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10519 if (tracker != null) {
10520 tracker.updateOtaEmergencyNumberDatabase();
10521 }
10522 }
10523 } finally {
10524 Binder.restoreCallingIdentity(identity);
10525 }
10526 }
10527
10528 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010529 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010530 enforceActiveEmergencySessionPermission();
10531
joonhunshin4ac60942023-11-15 15:23:39 +000010532 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10533 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10534
Shuo Qian3b6ee772019-11-13 17:43:31 -080010535 final long identity = Binder.clearCallingIdentity();
10536 try {
10537 for (Phone phone: PhoneFactory.getPhones()) {
10538 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10539 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010540 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10541 }
10542 }
10543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 }
10547
10548 @Override
10549 public void resetOtaEmergencyNumberDbFilePath() {
10550 enforceActiveEmergencySessionPermission();
10551
joonhunshin4ac60942023-11-15 15:23:39 +000010552 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10553 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10554
Shuo Qianc373f112020-03-05 17:55:34 -080010555 final long identity = Binder.clearCallingIdentity();
10556 try {
10557 for (Phone phone: PhoneFactory.getPhones()) {
10558 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10559 if (tracker != null) {
10560 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010561 }
10562 }
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010569 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10570 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10571 Phone phone = getPhone(subId);
10572 if (phone == null) {
10573 return null;
10574 }
10575 final long identity = Binder.clearCallingIdentity();
10576 try {
10577 UiccProfile profile = UiccController.getInstance()
10578 .getUiccProfileForPhone(phone.getPhoneId());
10579 if (profile != null) {
10580 return profile.getCertsFromCarrierPrivilegeAccessRules();
10581 }
10582 } finally {
10583 Binder.restoreCallingIdentity(identity);
10584 }
10585 return null;
10586 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010587
10588 /**
10589 * Enable or disable a modem stack.
10590 */
10591 @Override
10592 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10593 enforceModifyPermission();
10594
joonhunshin4ac60942023-11-15 15:23:39 +000010595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10596 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10597
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010598 final long identity = Binder.clearCallingIdentity();
10599 try {
10600 Phone phone = PhoneFactory.getPhone(slotIndex);
10601 if (phone == null) {
10602 return false;
10603 } else {
10604 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10605 }
10606 } finally {
10607 Binder.restoreCallingIdentity(identity);
10608 }
10609 }
Michelecea4cf22018-12-21 15:00:11 -080010610
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010611 /**
10612 * Whether a modem stack is enabled or not.
10613 */
10614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010615 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10616 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010617 Phone phone = PhoneFactory.getPhone(slotIndex);
10618 if (phone == null) return false;
10619
10620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010621 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10622 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010623 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10624 }
10625
joonhunshin4ac60942023-11-15 15:23:39 +000010626 enforceTelephonyFeatureWithException(callingPackage,
10627 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10628
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010629 final long identity = Binder.clearCallingIdentity();
10630 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010631 try {
10632 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10633 } catch (NoSuchElementException ex) {
10634 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10635 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
Michelecea4cf22018-12-21 15:00:11 -080010641 @Override
Michele0ea7d782019-03-19 14:58:42 -070010642 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010643 enforceModifyPermission();
10644
joonhunshin4ac60942023-11-15 15:23:39 +000010645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10646 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10647
Michelecea4cf22018-12-21 15:00:11 -080010648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010651 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010652 .commit();
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
10658 @Override
Michele0ea7d782019-03-19 14:58:42 -070010659 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010660 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010661 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010662 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10663 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010664 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010665 }
Michelecea4cf22018-12-21 15:00:11 -080010666
joonhunshin4ac60942023-11-15 15:23:39 +000010667 enforceTelephonyFeatureWithException(callingPackage,
10668 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10669
Michelecea4cf22018-12-21 15:00:11 -080010670 final long identity = Binder.clearCallingIdentity();
10671 try {
Michele0ea7d782019-03-19 14:58:42 -070010672 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010673 } finally {
10674 Binder.restoreCallingIdentity(identity);
10675 }
10676 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010677
Michele0ea7d782019-03-19 14:58:42 -070010678 @TelephonyManager.IsMultiSimSupportedResult
10679 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010680 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10681 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10682 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010683 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10684 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010685 }
10686 // Check if the hardware supports multisim functionality. If usage of multisim is not
10687 // supported by the modem, indicate that it is restricted.
10688 PhoneCapability staticCapability =
10689 mPhoneConfigurationManager.getStaticPhoneCapability();
10690 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010691 loge("isMultiSimSupportedInternal: no static configuration available");
10692 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010693 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010694 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010695 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10696 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010697 }
10698 // Check if support of multiple SIMs is restricted by carrier
10699 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010700 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010701 }
10702
Michele0ea7d782019-03-19 14:58:42 -070010703 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010704 }
10705
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010706 /**
10707 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010708 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10709 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10710 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010711 * @param numOfSims number of active sims we want to switch to
10712 */
10713 @Override
10714 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010715 if (numOfSims == 1) {
10716 enforceModifyPermission();
10717 } else {
10718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10719 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10720 }
joonhunshin4ac60942023-11-15 15:23:39 +000010721
10722 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10723 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10724
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010725 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010726
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010727 try {
Michele30b57b22019-03-01 12:01:14 -080010728 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010729 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010730 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10731 return;
10732 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010733 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10734 } finally {
10735 Binder.restoreCallingIdentity(identity);
10736 }
10737 }
10738
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010739 @Override
10740 public boolean isApplicationOnUicc(int subId, int appType) {
10741 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010742
10743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10744 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10745
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010746 Phone phone = getPhone(subId);
10747 if (phone == null) {
10748 return false;
10749 }
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010752 UiccPort uiccPort = phone.getUiccPort();
10753 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010754 return false;
10755 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010756 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010757 if (uiccProfile == null) {
10758 return false;
10759 }
10760 if (TelephonyManager.APPTYPE_SIM <= appType
10761 && appType <= TelephonyManager.APPTYPE_ISIM) {
10762 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10763 }
10764 return false;
10765 } finally {
10766 Binder.restoreCallingIdentity(identity);
10767 }
10768 }
10769
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010770 /**
chen xub4baa772019-04-03 10:23:41 -070010771 * Get whether making changes to modem configurations will trigger reboot.
10772 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010773 */
10774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010775 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10776 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010778 mApp, subId, callingPackage, callingFeatureId,
10779 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010780 return false;
10781 }
joonhunshin4ac60942023-11-15 15:23:39 +000010782
10783 enforceTelephonyFeatureWithException(callingPackage,
10784 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10785 "doesSwitchMultiSimConfigTriggerReboot");
10786
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010787 final long identity = Binder.clearCallingIdentity();
10788 try {
10789 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
Nathan Harold29f5f052019-02-15 13:41:57 -080010795 private void updateModemStateMetrics() {
10796 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10797 // TODO: check the state for each modem if the api is ready.
10798 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10799 }
10800
Pengquan Meng3889a572019-01-23 11:16:29 -080010801 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010802 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010803 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010804 // Verify that the callingPackage belongs to the calling UID
10805 mApp.getSystemService(AppOpsManager.class)
10806 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010807
10808 enforceTelephonyFeatureWithException(callingPackage,
10809 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10810
Pengquan Meng3889a572019-01-23 11:16:29 -080010811 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010812 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010813 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010814 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10815 if (slotInfos != null) {
10816 for (int i = 0; i < slotInfos.length; i++) {
10817 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10818 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10819 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10820 portInfo.getLogicalSlotIndex()));
10821 }
10822 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010823 }
10824 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010825 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010826 } finally {
10827 Binder.restoreCallingIdentity(identity);
10828 }
10829 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010830
10831 /**
10832 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010833 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010834 */
jimsunf9ec1622022-09-13 21:18:43 +080010835 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010836 @Override
10837 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010838 return getHalVersion(HAL_SERVICE_RADIO);
10839 }
10840
10841 /**
10842 * Get the HAL Version of a specific service
10843 */
10844 @Override
10845 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010846 Phone phone = getDefaultPhone();
10847 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010848 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010849 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10850 return hv.major * 100 + hv.minor;
10851 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010852
10853 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010854 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010855 *
10856 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010857 */
10858 @Override
sangyun097dcf72024-01-04 10:35:49 +090010859 public @Nullable String getCurrentPackageName() {
10860 PackageManager pm = mApp.getPackageManager();
10861 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10862 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010863 }
10864
10865 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010866 * @return The calling package name or "phone" if the caller is the phone process. This is done
10867 * because multiple Phone has multiple packages in it and the first element in the array is not
10868 * actually always the caller.
10869 * Note: This is for logging purposes only and should not be used for security checks.
10870 */
10871 private String getCurrentPackageNameOrPhone() {
10872 PackageManager pm = mApp.getPackageManager();
10873 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10874 if (uidName != null && !uidName.isEmpty()) return uidName;
10875 return getCurrentPackageName();
10876 }
10877
10878 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010879 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10880 * corresponding network requests on a subId.
10881 *
10882 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010883 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010884 * 2) APN is un-metered for this subscription, or
10885 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010886 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010887 *
10888 * @return whether data is allowed for a apn type.
10889 *
10890 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010891 */
10892 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010893 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010894 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10895 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010896
joonhunshin4ac60942023-11-15 15:23:39 +000010897 enforceTelephonyFeatureWithException(callingPackage,
10898 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10899
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010900 // Now that all security checks passes, perform the operation as ourselves.
10901 final long identity = Binder.clearCallingIdentity();
10902 try {
10903 Phone phone = getPhone(subId);
10904 if (phone == null) return false;
10905
Jack Yu27422a52022-03-21 10:38:05 -070010906 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010907 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010908 isMetered = phone.getDataNetworkController().getDataConfigManager()
10909 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10910 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010911 isDataEnabled = (phone.getDataSettingsManager() != null)
10912 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010913 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
10918
10919 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010920 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010921 enforceReadPrivilegedPermission("isApnMetered");
10922
joonhunshin4ac60942023-11-15 15:23:39 +000010923 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10924 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10925
Malcolm Chene5ad5792019-04-18 13:51:02 -070010926 // Now that all security checks passes, perform the operation as ourselves.
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 Phone phone = getPhone(subId);
10930 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010931 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10932 DataUtils.apnTypeToNetworkCapability(apnType),
10933 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010934 } finally {
10935 Binder.restoreCallingIdentity(identity);
10936 }
10937 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010938
10939 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010940 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10941 int subscriptionId, IBooleanConsumer resultCallback) {
10942 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010943
10944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10945 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10946
Hall Liu73f5d362020-01-20 13:42:00 -080010947 long token = Binder.clearCallingIdentity();
10948 try {
10949 Phone phone = getPhone(subscriptionId);
10950 if (phone == null) {
10951 try {
10952 if (resultCallback != null) {
10953 resultCallback.accept(false);
10954 }
10955 } catch (RemoteException e) {
10956 // ignore
10957 }
10958 return;
10959 }
10960 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10961 Pair.create(specifiers, (x) -> {
10962 try {
10963 if (resultCallback != null) {
10964 resultCallback.accept(x);
10965 }
10966 } catch (RemoteException e) {
10967 // ignore
10968 }
10969 });
10970 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10971 } finally {
10972 Binder.restoreCallingIdentity(token);
10973 }
10974 }
10975
10976 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010977 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10978 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010979 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010980 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010981
10982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10983 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10984
Sarah Chin679c08a2020-11-18 13:39:35 -080010985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10986 final long identity = Binder.clearCallingIdentity();
10987 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010988 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10989 if (result instanceof IllegalStateException) {
10990 throw (IllegalStateException) result;
10991 }
10992 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010993 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10994 return specifiers;
10995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
10999
11000 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011001 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011002 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011003
11004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11005 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11006
Jack Yu8b766fc2022-03-21 09:42:33 -070011007 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011008 }
11009
11010 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011011 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11012 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011013 if (callingPackage == null) {
11014 callingPackage = getCurrentPackageName();
11015 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011016 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11017 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011018 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11019 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011020 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11021 }
11022 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11023 Intent intent = new Intent();
11024 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11025 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11026 // Bring up choose default SMS subscription dialog right now
11027 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11028 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11029 mApp.startActivity(intent);
11030 }
chen xud5ca2d52019-05-28 15:20:57 -070011031
11032 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011033 public void showSwitchToManagedProfileDialog() {
11034 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011035 try {
11036 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11037 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11038 // for work telephony.
11039 Intent intent = new Intent(Intent.ACTION_SENDTO);
11040 intent.setData(Uri.parse("smsto:"));
11041 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11042 mApp.startActivity(intent);
11043 } catch (ActivityNotFoundException e) {
11044 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11045 Intent intent = new Intent();
11046 intent.setClass(mApp, ErrorDialogActivity.class);
11047 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11048 mApp.startActivity(intent);
11049 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011050 }
11051
11052 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011053 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011054 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11055 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11056
chen xud5ca2d52019-05-28 15:20:57 -070011057 //TODO investigate if this API should require proper permission check in R b/133791609
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011060 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11061 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11062 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11063 return carrierUAProfUrl;
11064 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011065 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11066 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011067 } finally {
11068 Binder.restoreCallingIdentity(identity);
11069 }
11070 }
11071
11072 @Override
11073 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11075 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11076
chen xud5ca2d52019-05-28 15:20:57 -070011077 //TODO investigate if this API should require proper permission check in R b/133791609
11078 final long identity = Binder.clearCallingIdentity();
11079 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011080 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11081 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11082 if (!TextUtils.isEmpty(carrierUserAgent)) {
11083 return carrierUserAgent;
11084 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011085 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11086 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
Jack Yub07d4972019-05-28 16:12:25 -070011091
11092 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011093 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11094 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011095
joonhunshin4ac60942023-11-15 15:23:39 +000011096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11097 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11098
Jack Yub07d4972019-05-28 16:12:25 -070011099 final long identity = Binder.clearCallingIdentity();
11100 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011101 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011102 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011103
Ling Maf188d502022-09-16 15:22:36 -070011104 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011105 } finally {
11106 Binder.restoreCallingIdentity(identity);
11107 }
11108 }
11109
11110 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011111 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011112 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011113 enforceModifyPermission();
11114
joonhunshin4ac60942023-11-15 15:23:39 +000011115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11116 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11117
changbettyd5c246e2019-12-24 15:40:37 +080011118 final long identity = Binder.clearCallingIdentity();
11119 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011120 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011121 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011122
Ling Maf188d502022-09-16 15:22:36 -070011123 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011129 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011130 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011131 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11132 * otherwise.
11133 */
11134 @Override
11135 public void setCepEnabled(boolean isCepEnabled) {
11136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11137
11138 final long identity = Binder.clearCallingIdentity();
11139 try {
11140 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11141 for (Phone phone : PhoneFactory.getPhones()) {
11142 Phone defaultPhone = phone.getImsPhone();
11143 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11144 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11145 ImsPhoneCallTracker imsPhoneCallTracker =
11146 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11147 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11148 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11149 + imsPhone.getMsisdn());
11150 }
11151 }
11152 } finally {
11153 Binder.restoreCallingIdentity(identity);
11154 }
11155 }
allenwtsu46dcc572020-01-08 18:24:03 +080011156
11157 /**
11158 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11159 *
11160 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11161 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11162 * before being read.
11163 */
11164 @Override
11165 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11166 isCompressed) {
11167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11168 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011169 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11170 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11171 }
joonhunshin4ac60942023-11-15 15:23:39 +000011172
11173 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11174 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11175 Binder.getCallingUserHandle())) {
11176 if (!isImsAvailableOnDevice()) {
11177 // ProvisioningManager can not handle ServiceSpecificException.
11178 // Throw the IllegalStateException and annotate ProvisioningManager.
11179 throw new IllegalStateException("IMS not available on device.");
11180 }
11181 } else {
11182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11183 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11184 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011185 }
11186
11187 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011188 try {
Hui Wang761a6682020-10-31 05:12:53 +000011189 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11190 } finally {
11191 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011192 }
11193 }
zoey chene02881a2019-12-30 16:11:23 +080011194
11195 @Override
11196 public boolean isIccLockEnabled(int subId) {
11197 enforceReadPrivilegedPermission("isIccLockEnabled");
11198
joonhunshin4ac60942023-11-15 15:23:39 +000011199 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11200 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11201
zoey chene02881a2019-12-30 16:11:23 +080011202 // Now that all security checks passes, perform the operation as ourselves.
11203 final long identity = Binder.clearCallingIdentity();
11204 try {
11205 Phone phone = getPhone(subId);
11206 if (phone != null && phone.getIccCard() != null) {
11207 return phone.getIccCard().getIccLockEnabled();
11208 } else {
11209 return false;
11210 }
11211 } finally {
11212 Binder.restoreCallingIdentity(identity);
11213 }
11214 }
11215
11216 /**
11217 * Set the ICC pin lock enabled or disabled.
11218 *
11219 * @return an integer representing the status of IccLock enabled or disabled in the following
11220 * three cases:
11221 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11222 * successfully.
11223 * - Positive number and zero for remaining password attempts.
11224 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11225 *
11226 */
11227 @Override
11228 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11229 enforceModifyPermission();
11230
joonhunshin4ac60942023-11-15 15:23:39 +000011231 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11232 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11233
zoey chene02881a2019-12-30 16:11:23 +080011234 Phone phone = getPhone(subId);
11235 if (phone == null) {
11236 return 0;
11237 }
11238 // Now that all security checks passes, perform the operation as ourselves.
11239 final long identity = Binder.clearCallingIdentity();
11240 try {
11241 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11242 new Pair<Boolean, String>(enabled, password), phone, null);
11243 return attemptsRemaining;
11244
11245 } catch (Exception e) {
11246 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11247 } finally {
11248 Binder.restoreCallingIdentity(identity);
11249 }
11250 return 0;
11251 }
11252
11253 /**
11254 * Change the ICC password used in ICC pin lock.
11255 *
11256 * @return an integer representing the status of IccLock changed in the following three cases:
11257 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11258 * - Positive number and zero for remaining password attempts.
11259 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11260 *
11261 */
11262 @Override
11263 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11264 enforceModifyPermission();
11265
joonhunshin4ac60942023-11-15 15:23:39 +000011266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11267 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11268
zoey chene02881a2019-12-30 16:11:23 +080011269 Phone phone = getPhone(subId);
11270 if (phone == null) {
11271 return 0;
11272 }
11273 // Now that all security checks passes, perform the operation as ourselves.
11274 final long identity = Binder.clearCallingIdentity();
11275 try {
11276 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11277 new Pair<String, String>(oldPassword, newPassword), phone, null);
11278 return attemptsRemaining;
11279
11280 } catch (Exception e) {
11281 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11282 } finally {
11283 Binder.restoreCallingIdentity(identity);
11284 }
11285 return 0;
11286 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011287
11288 /**
11289 * Request for receiving user activity notification
11290 */
11291 @Override
11292 public void requestUserActivityNotification() {
11293 if (!mNotifyUserActivity.get()
11294 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11295 mNotifyUserActivity.set(true);
11296 }
11297 }
11298
11299 /**
11300 * Called when userActivity is signalled in the power manager.
11301 * This is safe to call from any thread, with any window manager locks held or not.
11302 */
11303 @Override
11304 public void userActivity() {
11305 // ***************************************
11306 // * Inherited from PhoneWindowManager *
11307 // ***************************************
11308 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11309 // WITH ITS LOCKS HELD.
11310 //
11311 // This code must be VERY careful about the locks
11312 // it acquires.
11313 // In fact, the current code acquires way too many,
11314 // and probably has lurking deadlocks.
11315
11316 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11317 throw new SecurityException("Only the OS may call notifyUserActivity()");
11318 }
11319
11320 if (mNotifyUserActivity.getAndSet(false)) {
11321 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11322 USER_ACTIVITY_NOTIFICATION_DELAY);
11323 }
11324 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011325
11326 @Override
11327 public boolean canConnectTo5GInDsdsMode() {
11328 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11329 }
Jack Yud10cdd42020-09-28 20:28:01 -070011330
11331 @Override
11332 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11333 String callingFeatureId) {
11334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11335 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11336 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11337 }
11338
joonhunshin4ac60942023-11-15 15:23:39 +000011339 enforceTelephonyFeatureWithException(callingPackage,
11340 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11341
Jack Yud10cdd42020-09-28 20:28:01 -070011342 Phone phone = getPhone(subId);
11343 if (phone == null) {
11344 throw new RuntimeException("phone is not available");
11345 }
11346 // Now that all security checks passes, perform the operation as ourselves.
11347 final long identity = Binder.clearCallingIdentity();
11348 try {
11349 return phone.getEquivalentHomePlmns();
11350 } finally {
11351 Binder.restoreCallingIdentity(identity);
11352 }
11353 }
Daniel Bright59e67312020-11-13 11:49:37 -080011354
11355 @Override
11356 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011357 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011358 if (!mApp.getResources().getBoolean(
11359 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11361 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11362 "isRadioInterfaceCapabilitySupported");
11363 }
joonhunshin4ac60942023-11-15 15:23:39 +000011364
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011365 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011366 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011367 if (radioInterfaceCapabilities == null) {
11368 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011369 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011370 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011371 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011372
Hui Wang641e81c2020-10-12 12:14:23 -070011373 @Override
11374 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11375 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011376 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11377 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11378 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11379 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11380 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011381
11382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11383 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11384
Hui Wang641e81c2020-10-12 12:14:23 -070011385 if (DBG) {
11386 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11387 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11388 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11389 }
11390
11391 if (!SubscriptionManager.isValidSubscriptionId(subId)
11392 || appType < TelephonyManager.APPTYPE_UNKNOWN
11393 || appType > TelephonyManager.APPTYPE_ISIM
11394 || nafUrl == null || securityProtocol == null || callback == null) {
11395 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11396 if (callback != null) {
11397 try {
11398 callback.onAuthenticationFailure(
11399 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11400 } catch (RemoteException exception) {
11401 log("Fail to notify onAuthenticationFailure due to " + exception);
11402 }
11403 return;
11404 }
11405 }
11406
11407 final long token = Binder.clearCallingIdentity();
11408 try {
11409 getGbaManager(subId).bootstrapAuthenticationRequest(
11410 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011411 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011412 } finally {
11413 Binder.restoreCallingIdentity(token);
11414 }
11415 }
11416
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011417 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011418 * Attempts to set the radio power state for all phones for thermal reason.
11419 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011420 * requested radio power state will actually be set. See {@link
11421 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11422 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011423 * @param enable {@code true} if trying to turn radio on.
11424 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11425 * false}.
11426 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011427 private boolean setRadioPowerForThermal(boolean enable) {
11428 boolean isPhoneAvailable = false;
11429 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11430 Phone phone = PhoneFactory.getPhone(i);
11431 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011432 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011433 isPhoneAvailable = true;
11434 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011435 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011436
11437 // return true if successfully informed the phone object about the thermal radio power
11438 // request.
11439 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011440 }
11441
11442 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011443 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011444 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11445 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11446 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11447 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11448 throw new IllegalArgumentException("modem does not support data throttling");
11449 }
11450
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011451 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11452 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011453 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011454 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11455 }
11456
Sarah Chinecc78c42022-03-31 21:16:48 -070011457 setDataEnabledForReason(
11458 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011459
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011460 if (isDataThrottlingSupported) {
11461 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011462 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011463 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11464 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11465 } else if (thermalMitigationResult
11466 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011467 log("Modem likely does not support data throttling on secondary carrier. Data " +
11468 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11469 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011470 }
11471 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011472 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011473
11474 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011475 }
11476
Jack Nudelman644b91a2021-03-12 14:09:48 -080011477 private static List<String> getThermalMitigationAllowlist(Context context) {
11478 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11479 for (String pckg : context.getResources()
11480 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11481 sThermalMitigationAllowlistedPackages.add(pckg);
11482 }
11483 }
11484
11485 return sThermalMitigationAllowlistedPackages;
11486 }
11487
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011488 private boolean isAnyPhoneInEmergencyState() {
11489 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11490 if (tm.isInEmergencyCall()) {
11491 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11492 return true;
11493 }
11494 for (Phone phone : PhoneFactory.getPhones()) {
11495 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11496 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011497 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11498 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011499 return true;
11500 }
11501 }
11502
11503 return false;
11504 }
11505
Jack Nudelman644b91a2021-03-12 14:09:48 -080011506 /**
11507 * Used by shell commands to add an authorized package name for thermal mitigation.
11508 * @param packageName name of package to be allowlisted
11509 * @param context
11510 */
11511 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11512 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11513 sThermalMitigationAllowlistedPackages.add(packageName);
11514 }
11515
11516 /**
11517 * Used by shell commands to remove an authorized package name for thermal mitigation.
11518 * @param packageName name of package to remove from allowlist
11519 * @param context
11520 */
11521 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11522 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11523 sThermalMitigationAllowlistedPackages.remove(packageName);
11524 }
11525
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011526 /**
11527 * Thermal mitigation request to control functionalities at modem.
11528 *
11529 * @param subId the id of the subscription.
11530 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011531 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 *
11533 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11534 */
11535 @Override
11536 @ThermalMitigationResult
11537 public int sendThermalMitigationRequest(
11538 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011539 ThermalMitigationRequest thermalMitigationRequest,
11540 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011541 enforceModifyPermission();
11542
Jack Nudelman644b91a2021-03-12 14:09:48 -080011543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011544
11545 enforceTelephonyFeatureWithException(callingPackage,
11546 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11547
Jack Nudelman644b91a2021-03-12 14:09:48 -080011548 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11549 .contains(callingPackage)) {
11550 throw new SecurityException("Calling package must be configured in the device config. "
11551 + "calling package: " + callingPackage);
11552 }
11553
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11555 final long identity = Binder.clearCallingIdentity();
11556
11557 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11558 try {
11559 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11560 switch (thermalMitigationAction) {
11561 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11562 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011563 handleDataThrottlingRequest(subId,
11564 thermalMitigationRequest.getDataThrottlingRequest(),
11565 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011566 break;
11567 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11568 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11569 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11570 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11571 }
11572
11573 // Ensure that radio is on. If not able to power on due to phone being
11574 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011575 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011576 thermalMitigationResult =
11577 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11578 break;
11579 }
11580
11581 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011582 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011583 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11584 break;
11585 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11586 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11587 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11588 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11589 }
11590
11591 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11592 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011593 Phone phone = getPhone(subId);
11594 if (phone == null) {
11595 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011596 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011597 break;
11598 }
11599
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011600 TelephonyConnectionService service =
11601 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011602 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011603 Log.e(LOG_TAG, "An emergency call is pending");
11604 thermalMitigationResult =
11605 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11606 break;
11607 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011608 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011609 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011610 break;
11611 }
11612 } else {
11613 thermalMitigationResult =
11614 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11615 break;
11616 }
11617
11618 // Turn radio off. If not able to power off due to phone being unavailable,
11619 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011620 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011621 thermalMitigationResult =
11622 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11623 break;
11624 }
11625 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011626 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011627 break;
11628 default:
11629 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11630 + "not exist. Requested action: " + thermalMitigationAction);
11631 }
11632 } catch (IllegalArgumentException e) {
11633 throw e;
11634 } catch (Exception e) {
11635 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11636 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11637 } finally {
11638 Binder.restoreCallingIdentity(identity);
11639 }
11640
11641 if (DBG) {
11642 log("thermalMitigationRequest returning with thermalMitigationResult: "
11643 + thermalMitigationResult);
11644 }
11645
11646 return thermalMitigationResult;
11647 }
Hui Wang641e81c2020-10-12 12:14:23 -070011648
11649 /**
11650 * Set the GbaService Package Name that Telephony will bind to.
11651 *
11652 * @param subId The sim that the GbaService is associated with.
11653 * @param packageName The name of the package to be replaced with.
11654 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11655 */
11656 @Override
11657 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11658 enforceModifyPermission();
11659
11660 final long identity = Binder.clearCallingIdentity();
11661 try {
11662 return getGbaManager(subId).overrideServicePackage(packageName);
11663 } finally {
11664 Binder.restoreCallingIdentity(identity);
11665 }
11666 }
11667
11668 /**
11669 * Return the package name of the currently bound GbaService.
11670 *
11671 * @param subId The sim that the GbaService is associated with.
11672 * @return the package name of the GbaService configuration, null if GBA is not supported.
11673 */
11674 @Override
11675 public String getBoundGbaService(int subId) {
11676 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11677
11678 final long identity = Binder.clearCallingIdentity();
11679 try {
11680 return getGbaManager(subId).getServicePackage();
11681 } finally {
11682 Binder.restoreCallingIdentity(identity);
11683 }
11684 }
11685
11686 /**
11687 * Set the release time for telephony to unbind GbaService.
11688 *
11689 * @param subId The sim that the GbaService is associated with.
11690 * @param interval The release time to unbind GbaService by millisecond.
11691 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11692 */
11693 @Override
11694 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11695 enforceModifyPermission();
11696
11697 final long identity = Binder.clearCallingIdentity();
11698 try {
11699 return getGbaManager(subId).overrideReleaseTime(interval);
11700 } finally {
11701 Binder.restoreCallingIdentity(identity);
11702 }
11703 }
11704
11705 /**
11706 * Return the release time for telephony to unbind GbaService.
11707 *
11708 * @param subId The sim that the GbaService is associated with.
11709 * @return The release time to unbind GbaService by millisecond.
11710 */
11711 @Override
11712 public int getGbaReleaseTime(int subId) {
11713 enforceReadPrivilegedPermission("getGbaReleaseTime");
11714
11715 final long identity = Binder.clearCallingIdentity();
11716 try {
11717 return getGbaManager(subId).getReleaseTime();
11718 } finally {
11719 Binder.restoreCallingIdentity(identity);
11720 }
11721 }
11722
11723 private GbaManager getGbaManager(int subId) {
11724 GbaManager instance = GbaManager.getInstance(subId);
11725 if (instance == null) {
11726 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11727 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11728 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11729 }
11730 return instance;
11731 }
Hui Wang761a6682020-10-31 05:12:53 +000011732
11733 /**
11734 * indicate whether the device and the carrier can support
11735 * RCS VoLTE single registration.
11736 */
11737 @Override
11738 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011739 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11740 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11741 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11742 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011743
11744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11745 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11746 }
11747
11748 final long identity = Binder.clearCallingIdentity();
11749 try {
11750 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11751 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011752 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11753 if (isCapable != null) {
11754 return isCapable;
11755 }
Hui Wang761a6682020-10-31 05:12:53 +000011756 }
Hui Wang67af90e2021-06-04 16:57:15 -070011757 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11758 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011759 } finally {
11760 Binder.restoreCallingIdentity(identity);
11761 }
11762 }
11763
11764 /**
11765 * Register RCS provisioning callback.
11766 */
11767 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011768 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011769 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011770 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011771 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011772 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11773 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011774
11775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11777 }
joonhunshin4ac60942023-11-15 15:23:39 +000011778 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11779 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11780 Binder.getCallingUserHandle())) {
11781 if (!isImsAvailableOnDevice()) {
11782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11783 "IMS not available on device.");
11784 }
11785 } else {
11786 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11787 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011788 }
11789
11790 final long identity = Binder.clearCallingIdentity();
11791 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011792 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011793 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011794 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11795 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011796 }
Hui Wang761a6682020-10-31 05:12:53 +000011797 } finally {
11798 Binder.restoreCallingIdentity(identity);
11799 }
11800 }
11801
11802 /**
11803 * Unregister RCS provisioning callback.
11804 */
11805 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011806 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011807 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011808 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011809 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011810 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11811 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011812
11813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11814 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11815 }
joonhunshin4ac60942023-11-15 15:23:39 +000011816
11817 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11818 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11819 Binder.getCallingUserHandle())) {
11820 if (!isImsAvailableOnDevice()) {
11821 // operation failed silently
11822 Rlog.w(LOG_TAG, "IMS not available on device.");
11823 return;
11824 }
11825 } else {
11826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11827 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11828 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011829 }
11830
11831 final long identity = Binder.clearCallingIdentity();
11832 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011833 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011834 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011835 } finally {
11836 Binder.restoreCallingIdentity(identity);
11837 }
11838 }
11839
11840 /**
11841 * trigger RCS reconfiguration.
11842 */
11843 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011844 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11845 "triggerRcsReconfiguration",
11846 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011847
11848 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11849 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11850 }
joonhunshin4ac60942023-11-15 15:23:39 +000011851 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11852 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11853 Binder.getCallingUserHandle())) {
11854 if (!isImsAvailableOnDevice()) {
11855 // ProvisioningManager can not handle ServiceSpecificException.
11856 // Throw the IllegalStateException and annotate ProvisioningManager.
11857 throw new IllegalStateException("IMS not available on device.");
11858 }
11859 } else {
11860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11861 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011862 }
11863
11864 final long identity = Binder.clearCallingIdentity();
11865 try {
11866 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11867 } finally {
11868 Binder.restoreCallingIdentity(identity);
11869 }
11870 }
11871
11872 /**
11873 * Provide the client configuration parameters of the RCS application.
11874 */
11875 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011876 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11877 "setRcsClientConfiguration",
11878 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011879
11880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11881 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11882 }
joonhunshin4ac60942023-11-15 15:23:39 +000011883 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11884 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11885 Binder.getCallingUserHandle())) {
11886 if (!isImsAvailableOnDevice()) {
11887 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11888 "IMS not available on device.");
11889 }
11890 } else {
11891 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11892 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011893 }
11894
11895 final long identity = Binder.clearCallingIdentity();
11896
11897 try {
11898 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11899 if (configBinder == null) {
11900 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011901 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11902 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011903 } else {
11904 configBinder.setRcsClientConfiguration(rcc);
11905 }
joonhunshin3e154242021-09-17 06:33:39 +000011906
11907 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11908 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011909 } catch (RemoteException e) {
11910 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011911 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11912 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011913 } finally {
11914 Binder.restoreCallingIdentity(identity);
11915 }
11916 }
11917
11918 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011919 * Enables or disables the test mode for RCS VoLTE single registration.
11920 */
11921 @Override
11922 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11923 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11924 "setRcsSingleRegistrationTestModeEnabled");
11925
11926 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11927 }
11928
11929 /**
11930 * Gets the test mode for RCS VoLTE single registration.
11931 */
11932 @Override
11933 public boolean getRcsSingleRegistrationTestModeEnabled() {
11934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11935 "getRcsSingleRegistrationTestModeEnabled");
11936
11937 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11938 }
11939
11940 /**
Hui Wang761a6682020-10-31 05:12:53 +000011941 * Overrides the config of RCS VoLTE single registration enabled for the device.
11942 */
11943 @Override
11944 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11946 "setDeviceSingleRegistrationEnabledOverride");
11947 enforceModifyPermission();
11948
11949 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11950 : Boolean.parseBoolean(enabledStr);
11951 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011952 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011953 }
11954
11955 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011956 * Sends a device to device communication message. Only usable via shell.
11957 * @param message message to send.
11958 * @param value message value.
11959 */
11960 @Override
11961 public void sendDeviceToDeviceMessage(int message, int value) {
11962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011963 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011964 enforceModifyPermission();
11965
11966 final long identity = Binder.clearCallingIdentity();
11967 try {
11968 TelephonyConnectionService service =
11969 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11970 if (service == null) {
11971 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11972 return;
11973 }
11974 service.sendTestDeviceToDeviceMessage(message, value);
11975 } finally {
11976 Binder.restoreCallingIdentity(identity);
11977 }
11978 }
11979
Tyler Gunnbabbda02021-02-10 11:05:02 -080011980 /**
11981 * Sets the specified device to device transport active.
11982 * @param transport The transport to set active.
11983 */
11984 @Override
11985 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11987 "setActiveDeviceToDeviceTransport");
11988 enforceModifyPermission();
11989
11990 final long identity = Binder.clearCallingIdentity();
11991 try {
11992 TelephonyConnectionService service =
11993 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11994 if (service == null) {
11995 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11996 return;
11997 }
11998 service.setActiveDeviceToDeviceTransport(transport);
11999 } finally {
12000 Binder.restoreCallingIdentity(identity);
12001 }
12002 }
Tyler Gunn92479152021-01-20 16:30:10 -080012003
Tyler Gunnd4339262021-05-03 14:46:49 -070012004 @Override
12005 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12007 "setDeviceToDeviceForceEnabled");
12008
12009 final long identity = Binder.clearCallingIdentity();
12010 try {
12011 Arrays.stream(PhoneFactory.getPhones()).forEach(
12012 p -> {
12013 Phone thePhone = p.getImsPhone();
12014 if (thePhone != null && thePhone instanceof ImsPhone) {
12015 ImsPhone imsPhone = (ImsPhone) thePhone;
12016 CallTracker tracker = imsPhone.getCallTracker();
12017 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12018 ImsPhoneCallTracker imsPhoneCallTracker =
12019 (ImsPhoneCallTracker) tracker;
12020 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12021 }
12022 }
12023 }
12024 );
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
12029
Tyler Gunn92479152021-01-20 16:30:10 -080012030 /**
Hui Wang761a6682020-10-31 05:12:53 +000012031 * Gets the config of RCS VoLTE single registration enabled for the device.
12032 */
12033 @Override
12034 public boolean getDeviceSingleRegistrationEnabled() {
12035 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12036 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12037 }
12038
12039 /**
12040 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12041 */
12042 @Override
12043 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12045 "setCarrierSingleRegistrationEnabledOverride");
12046 enforceModifyPermission();
12047
12048 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12049 : Boolean.parseBoolean(enabledStr);
12050 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12051 subId, enabled);
12052 }
12053
12054 /**
12055 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12056 */
12057 @Override
12058 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12059 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12060 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12061 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012062
12063 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012064 * Overrides the ims feature validation result
12065 */
12066 @Override
12067 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12069 "setImsFeatureValidationOverride");
12070
12071 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12072 : Boolean.parseBoolean(enabledStr);
12073 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12074 subId, enabled);
12075 }
12076
12077 /**
12078 * Gets the ims feature validation override value
12079 */
12080 @Override
12081 public boolean getImsFeatureValidationOverride(int subId) {
12082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12083 "getImsFeatureValidationOverride");
12084 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12085 }
12086
12087 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012088 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12089 * their mobile plan.
12090 */
12091 @Override
12092 public String getMobileProvisioningUrl() {
12093 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12094 final long identity = Binder.clearCallingIdentity();
12095 try {
12096 return getDefaultPhone().getMobileProvisioningUrl();
12097 } finally {
12098 Binder.restoreCallingIdentity(identity);
12099 }
12100 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012101
James.cf Linbcdf8b32021-01-14 16:44:13 +080012102 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012103 * Get the EAB contact from the EAB database.
12104 */
12105 @Override
12106 public String getContactFromEab(String contact) {
12107 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12108 enforceModifyPermission();
12109 final long identity = Binder.clearCallingIdentity();
12110 try {
12111 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12112 } finally {
12113 Binder.restoreCallingIdentity(identity);
12114 }
12115 }
12116
12117 /**
Calvin Pana1434322021-07-01 19:27:01 +080012118 * Get the EAB capability from the EAB database.
12119 */
12120 @Override
12121 public String getCapabilityFromEab(String contact) {
12122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12123 enforceModifyPermission();
12124 final long identity = Binder.clearCallingIdentity();
12125 try {
12126 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12127 } finally {
12128 Binder.restoreCallingIdentity(identity);
12129 }
12130 }
12131
12132 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012133 * Remove the EAB contacts from the EAB database.
12134 */
12135 @Override
12136 public int removeContactFromEab(int subId, String contacts) {
12137 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12138 enforceModifyPermission();
12139 final long identity = Binder.clearCallingIdentity();
12140 try {
12141 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12142 } finally {
12143 Binder.restoreCallingIdentity(identity);
12144 }
12145 }
12146
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012147 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012148 public boolean getDeviceUceEnabled() {
12149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12150 final long identity = Binder.clearCallingIdentity();
12151 try {
12152 return mApp.getDeviceUceEnabled();
12153 } finally {
12154 Binder.restoreCallingIdentity(identity);
12155 }
12156 }
12157
12158 @Override
12159 public void setDeviceUceEnabled(boolean isEnabled) {
12160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12161 final long identity = Binder.clearCallingIdentity();
12162 try {
12163 mApp.setDeviceUceEnabled(isEnabled);
12164 } finally {
12165 Binder.restoreCallingIdentity(identity);
12166 }
12167 }
12168
Brad Ebinger14d467f2021-02-12 06:18:28 +000012169 /**
12170 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12171 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12172 */
12173 // Used for SHELL command only right now.
12174 @Override
12175 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12176 List<String> featureTags) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12178 "addUceRegistrationOverrideShell");
12179 final long identity = Binder.clearCallingIdentity();
12180 try {
12181 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12182 new ArraySet<>(featureTags));
12183 } catch (ImsException e) {
12184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12185 } finally {
12186 Binder.restoreCallingIdentity(identity);
12187 }
12188 }
12189
12190 /**
12191 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12192 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12193 */
12194 // Used for SHELL command only right now.
12195 @Override
12196 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12197 List<String> featureTags) {
12198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12199 "removeUceRegistrationOverrideShell");
12200 final long identity = Binder.clearCallingIdentity();
12201 try {
12202 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12203 new ArraySet<>(featureTags));
12204 } catch (ImsException e) {
12205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12206 } finally {
12207 Binder.restoreCallingIdentity(identity);
12208 }
12209 }
12210
12211 /**
12212 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12213 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12214 */
12215 // Used for SHELL command only right now.
12216 @Override
12217 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12218 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12219 "clearUceRegistrationOverrideShell");
12220 final long identity = Binder.clearCallingIdentity();
12221 try {
12222 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12223 } catch (ImsException e) {
12224 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12225 } finally {
12226 Binder.restoreCallingIdentity(identity);
12227 }
12228 }
12229
12230 /**
12231 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12232 */
12233 // Used for SHELL command only right now.
12234 @Override
12235 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12237 "getLatestRcsContactUceCapabilityShell");
12238 final long identity = Binder.clearCallingIdentity();
12239 try {
12240 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12241 } catch (ImsException e) {
12242 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12243 } finally {
12244 Binder.restoreCallingIdentity(identity);
12245 }
12246 }
12247
12248 /**
12249 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12250 * device does not have an active PUBLISH.
12251 */
12252 // Used for SHELL command only right now.
12253 @Override
12254 public String getLastUcePidfXmlShell(int subId) {
12255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12256 final long identity = Binder.clearCallingIdentity();
12257 try {
12258 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12259 } catch (ImsException e) {
12260 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12261 } finally {
12262 Binder.restoreCallingIdentity(identity);
12263 }
12264 }
12265
James.cf Line8713a42021-04-29 16:04:26 +080012266 /**
12267 * Remove UCE requests cannot be sent to the network status.
12268 */
12269 // Used for SHELL command only right now.
12270 @Override
12271 public boolean removeUceRequestDisallowedStatus(int subId) {
12272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12273 final long identity = Binder.clearCallingIdentity();
12274 try {
12275 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12276 } catch (ImsException e) {
12277 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12278 } finally {
12279 Binder.restoreCallingIdentity(identity);
12280 }
12281 }
12282
James.cf Lin18bb9002021-05-25 01:37:38 +080012283 /**
12284 * Remove UCE requests cannot be sent to the network status.
12285 */
12286 // Used for SHELL command only.
12287 @Override
12288 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12290 final long identity = Binder.clearCallingIdentity();
12291 try {
12292 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12293 } catch (ImsException e) {
12294 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12295 } finally {
12296 Binder.restoreCallingIdentity(identity);
12297 }
12298 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012299
James.cf Lin4b784aa2021-01-31 03:25:15 +080012300 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012301 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12302 String callingPackage) {
12303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12304 mApp, subId, "setSignalStrengthUpdateRequest");
12305
joonhunshin4ac60942023-11-15 15:23:39 +000012306 enforceTelephonyFeatureWithException(callingPackage,
12307 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12308
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012309 final int callingUid = Binder.getCallingUid();
12310 // Verify that tha callingPackage belongs to the calling UID
12311 mApp.getSystemService(AppOpsManager.class)
12312 .checkPackage(callingUid, callingPackage);
12313
Rambo Wang3607f502021-02-01 21:51:40 -080012314 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012315
12316 final long identity = Binder.clearCallingIdentity();
12317 try {
12318 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12319 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12320
12321 if (result instanceof IllegalStateException) {
12322 throw (IllegalStateException) result;
12323 }
12324 } finally {
12325 Binder.restoreCallingIdentity(identity);
12326 }
12327 }
12328
12329 @Override
12330 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12331 String callingPackage) {
12332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12333 mApp, subId, "clearSignalStrengthUpdateRequest");
12334
joonhunshin4ac60942023-11-15 15:23:39 +000012335 enforceTelephonyFeatureWithException(callingPackage,
12336 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12337
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012338 final int callingUid = Binder.getCallingUid();
12339 // Verify that tha callingPackage belongs to the calling UID
12340 mApp.getSystemService(AppOpsManager.class)
12341 .checkPackage(callingUid, callingPackage);
12342
12343 final long identity = Binder.clearCallingIdentity();
12344 try {
12345 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12346 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12347
12348 if (result instanceof IllegalStateException) {
12349 throw (IllegalStateException) result;
12350 }
12351 } finally {
12352 Binder.restoreCallingIdentity(identity);
12353 }
12354 }
12355
Rambo Wang3607f502021-02-01 21:51:40 -080012356 private static void validateSignalStrengthUpdateRequest(Context context,
12357 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012358 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012359 // phone/system process do not have further restriction on request
12360 return;
12361 }
12362
12363 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012364 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012365 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012366 context.enforceCallingOrSelfPermission(
12367 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12368 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012369 }
12370
12371 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012372 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012373 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012374 || info.isEnabled()) {
12375 throw new IllegalArgumentException(
12376 "Only system can set hide fields in SignalThresholdInfo");
12377 }
12378
12379 // Thresholds length for each RAN need in range. This has been validated in
12380 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12381 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12382 final int[] thresholds = info.getThresholds();
12383 Objects.requireNonNull(thresholds);
12384 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12385 || thresholds.length
12386 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12387 throw new IllegalArgumentException(
12388 "thresholds length is out of range: " + thresholds.length);
12389 }
12390 }
12391 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012392
12393 /**
12394 * Gets the current phone capability.
12395 *
12396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12397 * @return the PhoneCapability which describes the data connection capability of modem.
12398 * It's used to evaluate possible phone config change, for example from single
12399 * SIM device to multi-SIM device.
12400 */
12401 @Override
12402 public PhoneCapability getPhoneCapability() {
12403 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012404
12405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12406 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12407
SongFerngWang8236caa2021-01-17 21:51:44 +080012408 final long identity = Binder.clearCallingIdentity();
12409 try {
12410 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12411 } finally {
12412 Binder.restoreCallingIdentity(identity);
12413 }
12414 }
Michele Berionne5e411512020-11-13 02:36:59 +000012415
12416 /**
12417 * Prepare TelephonyManager for an unattended reboot. The reboot is
12418 * required to be done shortly after the API is invoked.
12419 */
12420 @Override
12421 @TelephonyManager.PrepareUnattendedRebootResult
12422 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012423 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012424 enforceRebootPermission();
12425
joonhunshin4ac60942023-11-15 15:23:39 +000012426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12427 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12428
Michele Berionne5e411512020-11-13 02:36:59 +000012429 final long identity = Binder.clearCallingIdentity();
12430 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012431 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012432 } finally {
12433 Binder.restoreCallingIdentity(identity);
12434 }
12435 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012436
12437 /**
12438 * Request to get the current slicing configuration including URSP rules and
12439 * NSSAIs (configured, allowed and rejected).
12440 *
12441 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12442 */
12443 @Override
12444 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012445 TelephonyPermissions
12446 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12447 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012448
joonhunshin4ac60942023-11-15 15:23:39 +000012449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12450 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12451 "getSlicingConfig");
12452
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012453 final long identity = Binder.clearCallingIdentity();
12454 try {
12455 Phone phone = getDefaultPhone();
12456 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12457 } finally {
12458 Binder.restoreCallingIdentity(identity);
12459 }
12460 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012461
12462 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012463 * Check whether the given premium capability is available for purchase from the carrier.
12464 *
12465 * @param capability The premium capability to check.
12466 * @param subId The subId to check the premium capability for.
12467 *
12468 * @return Whether the given premium capability is available to purchase.
12469 */
12470 @Override
12471 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12472 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12473 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12474 log("Premium capability "
12475 + TelephonyManager.convertPremiumCapabilityToString(capability)
12476 + " is not available for purchase due to missing permissions.");
12477 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12478 + "permission READ_BASIC_PHONE_STATE.");
12479 }
12480
joonhunshin4ac60942023-11-15 15:23:39 +000012481 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12482 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12483
Sarah Chin2ec39f62022-08-31 17:03:26 -070012484 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012485 if (phone == null) {
12486 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12487 return false;
12488 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012489 final long identity = Binder.clearCallingIdentity();
12490 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012491 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012492 .isPremiumCapabilityAvailableForPurchase(capability);
12493 } finally {
12494 Binder.restoreCallingIdentity(identity);
12495 }
12496 }
12497
12498 /**
12499 * Purchase the given premium capability from the carrier.
12500 *
12501 * @param capability The premium capability to purchase.
12502 * @param callback The result of the purchase request.
12503 * @param subId The subId to purchase the premium capability for.
12504 */
12505 @Override
12506 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12507 log("purchasePremiumCapability: capability="
12508 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12509 + getCurrentPackageName());
12510
12511 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12512 mApp, "purchasePremiumCapability")) {
12513 log("purchasePremiumCapability "
12514 + TelephonyManager.convertPremiumCapabilityToString(capability)
12515 + " failed due to missing permissions.");
12516 throw new SecurityException("purchasePremiumCapability requires permission "
12517 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012518 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12519 mApp, "purchasePremiumCapability")) {
12520 log("purchasePremiumCapability "
12521 + TelephonyManager.convertPremiumCapabilityToString(capability)
12522 + " failed due to missing permissions.");
12523 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012524 }
12525
joonhunshin4ac60942023-11-15 15:23:39 +000012526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12527 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12528
Sarah Chin2ec39f62022-08-31 17:03:26 -070012529 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012530 if (phone == null) {
12531 try {
12532 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12533 callback.accept(result);
12534 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12535 } catch (RemoteException e) {
12536 String logStr = "Purchase premium capability "
12537 + TelephonyManager.convertPremiumCapabilityToString(capability)
12538 + " failed due to RemoteException handling null phone: " + e;
12539 if (DBG) log(logStr);
12540 AnomalyReporter.reportAnomaly(
12541 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12542 }
12543 return;
12544 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012545
12546 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012547 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012548 callingProcess = mApp.getPackageManager().getApplicationInfo(
12549 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012550 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012551 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012552 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012553
12554 boolean isVisible = false;
12555 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12556 if (am != null) {
12557 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12558 if (processes != null) {
12559 for (ActivityManager.RunningAppProcessInfo process : processes) {
12560 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012561 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012562 if (process.processName.equals(callingProcess) && process.importance
12563 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12564 isVisible = true;
12565 break;
12566 }
12567 }
12568 }
12569 }
12570
12571 if (!isVisible) {
12572 try {
12573 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12574 callback.accept(result);
12575 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12576 } catch (RemoteException e) {
12577 String logStr = "Purchase premium capability "
12578 + TelephonyManager.convertPremiumCapabilityToString(capability)
12579 + " failed due to RemoteException handling background application: " + e;
12580 if (DBG) log(logStr);
12581 AnomalyReporter.reportAnomaly(
12582 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12583 }
12584 return;
12585 }
12586
Sarah Chin71b3a852022-09-28 15:54:19 -070012587 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012588 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012589 }
12590
12591 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012592 * Register an IMS connection state callback
12593 */
12594 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012595 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12596 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012597 if (feature == ImsFeature.FEATURE_MMTEL) {
12598 // ImsMmTelManager
12599 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12600 TelephonyPermissions
12601 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12602 mApp, subId, "registerImsStateCallback");
12603 } else if (feature == ImsFeature.FEATURE_RCS) {
12604 // ImsRcsManager or SipDelegateManager
12605 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12606 Binder.getCallingUid(), "registerImsStateCallback",
12607 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12608 Manifest.permission.READ_PRECISE_PHONE_STATE,
12609 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12610 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12611 }
12612
12613 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12614 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12615 "IMS not available on device.");
12616 }
12617
12618 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12619 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12620 }
12621
12622 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12623 if (controller == null) {
12624 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12625 "IMS not available on device.");
12626 }
12627
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012628 if (callingPackage == null) {
12629 callingPackage = getCurrentPackageName();
12630 }
12631
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012632 final long token = Binder.clearCallingIdentity();
12633 try {
12634 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012635 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012636 } catch (ImsException e) {
12637 throw new ServiceSpecificException(e.getCode());
12638 } finally {
12639 Binder.restoreCallingIdentity(token);
12640 }
12641 }
12642
12643 /**
12644 * Unregister an IMS connection state callback
12645 */
12646 @Override
12647 public void unregisterImsStateCallback(IImsStateCallback cb) {
12648 final long token = Binder.clearCallingIdentity();
12649 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12650 if (controller == null) {
12651 return;
12652 }
12653 try {
12654 controller.unregisterImsStateCallback(cb);
12655 } finally {
12656 Binder.restoreCallingIdentity(token);
12657 }
12658 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012659
12660 /**
12661 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12662 *
12663 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012664 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012665 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012666 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012667 * If there is current registered network this value will be same as the registered cell
12668 * identity. If the device goes out of service the previous cell identity is cached and
12669 * will be returned. If the cache age of the Cell identity is more than 24 hours
12670 * it will be cleared and null will be returned.
12671 *
12672 */
12673 @Override
12674 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12675 String callingFeatureId) {
12676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12677 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12678 LocationAccessPolicy.checkLocationPermission(mApp,
12679 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12680 .setCallingPackage(callingPackage)
12681 .setCallingFeatureId(callingFeatureId)
12682 .setCallingPid(Binder.getCallingPid())
12683 .setCallingUid(Binder.getCallingUid())
12684 .setMethod("getLastKnownCellIdentity")
12685 .setLogAsInfo(true)
12686 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12687 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12688 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12689 .build());
12690
12691 boolean hasFinePermission =
12692 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12693 if (!hasFinePermission
12694 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12695 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012696 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012697 }
12698
12699 final long identity = Binder.clearCallingIdentity();
12700 try {
Ling Mac28f0212023-03-24 16:07:15 -070012701 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012702 if (sst == null) return null;
12703 return sst.getLastKnownCellIdentity();
12704 } finally {
12705 Binder.restoreCallingIdentity(identity);
12706 }
12707 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012708
jimsun3b9ccac2021-10-26 15:01:23 +080012709 /**
12710 * Sets the modem service class Name that Telephony will bind to.
12711 *
12712 * @param serviceName The class name of the modem service.
12713 * @return true if the operation is succeed, otherwise false.
12714 */
12715 public boolean setModemService(String serviceName) {
12716 Log.d(LOG_TAG, "setModemService - " + serviceName);
12717 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012719 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12720 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012721 return mPhoneConfigurationManager.setModemService(serviceName);
12722 }
12723
12724 /**
12725 * Return the class name of the currently bounded modem service.
12726 *
12727 * @return the class name of the modem service.
12728 */
12729 public String getModemService() {
12730 String result;
12731 Log.d(LOG_TAG, "getModemService");
12732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12733 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012734 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012735 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12736 "getModemService");
12737 result = mPhoneConfigurationManager.getModemService();
12738 Log.d(LOG_TAG, "result = " + result);
12739 return result;
12740 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012741
Hakjun Choi3ee81112023-12-19 15:40:58 +000012742 /**
12743 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12744 * including carrier config, entitlement server, and config update.
12745 *
12746 * @param subId subId The subscription ID of the carrier.
12747 *
12748 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12749 * be returned.
12750 *
12751 * @throws SecurityException if the caller doesn't have the required permission.
12752 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012753 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12754 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012755 final long identity = Binder.clearCallingIdentity();
12756 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012757 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012758 } finally {
12759 Binder.restoreCallingIdentity(identity);
12760 }
12761 }
12762
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012763 @Override
12764 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12765 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12766 mApp.enforceCallingOrSelfPermission(
12767 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12768 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12769
12770 final long identity = Binder.clearCallingIdentity();
12771 try {
12772 Phone phone = getPhone(subId);
12773 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012774 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12775 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012776 phone.setVoiceServiceStateOverride(hasService);
12777 } finally {
12778 Binder.restoreCallingIdentity(identity);
12779 }
12780 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012781
12782 /**
12783 * set removable eSIM as default eUICC.
12784 *
12785 * @hide
12786 */
12787 @Override
12788 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12789 enforceModifyPermission();
12790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12791
12792 final long identity = Binder.clearCallingIdentity();
12793 try {
12794 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12795 } finally {
12796 Binder.restoreCallingIdentity(identity);
12797 }
12798 }
12799
12800 /**
12801 * Returns whether the removable eSIM is default eUICC or not.
12802 *
12803 * @hide
12804 */
12805 @Override
12806 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12807 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12809
12810 final long identity = Binder.clearCallingIdentity();
12811 try {
12812 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12813 } finally {
12814 Binder.restoreCallingIdentity(identity);
12815 }
12816 }
12817
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012818 /**
12819 * Get the component name of the default app to direct respond-via-message intent for the
12820 * user associated with this subscription, update the cache if there is no respond-via-message
12821 * application currently configured for this user.
12822 * @return component name of the app and class to direct Respond Via Message intent to, or
12823 * {@code null} if the functionality is not supported.
12824 * @hide
12825 */
12826 @Override
12827 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12828 boolean updateIfNeeded) {
12829 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012830
joonhunshin4ac60942023-11-15 15:23:39 +000012831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12832 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12833 "getDefaultRespondViaMessageApplication");
12834
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012835 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12836
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012837 UserHandle userHandle = null;
12838 final long identity = Binder.clearCallingIdentity();
12839 try {
12840 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12841 } finally {
12842 Binder.restoreCallingIdentity(identity);
12843 }
12844 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12845 updateIfNeeded, userHandle);
12846 }
Jack Yuf5badd92022-12-08 00:50:53 -080012847
12848 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012849 * Set whether the device is able to connect with null ciphering or integrity
12850 * algorithms. This is a global setting and will apply to all active subscriptions
12851 * and all new subscriptions after this.
12852 *
12853 * @param enabled when true, null cipher and integrity algorithms are allowed.
12854 * @hide
12855 */
12856 @Override
12857 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12858 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12859 enforceModifyPermission();
12860 checkForNullCipherAndIntegritySupport();
12861
12862 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12863 // for listening to these preference changes and applying them immediately.
12864 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12865 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12866 editor.apply();
12867
12868 for (Phone phone: PhoneFactory.getPhones()) {
12869 phone.handleNullCipherEnabledChange();
12870 }
12871 }
12872
12873
12874 /**
12875 * Get whether the device is able to connect with null ciphering or integrity
12876 * algorithms. Note that this retrieves the phone-global preference and not
12877 * the state of the radio.
12878 *
12879 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12880 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12881 * version for this feature.
12882 * @hide
12883 */
12884 @Override
12885 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12886 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12887 enforceReadPermission();
12888 checkForNullCipherAndIntegritySupport();
12889 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12890 }
12891
12892 private void checkForNullCipherAndIntegritySupport() {
12893 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12894 throw new UnsupportedOperationException(
12895 "Null cipher and integrity operations require HAL 2.1 or above");
12896 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012897 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12898 throw new UnsupportedOperationException(
12899 "Null cipher and integrity operations unsupported by modem");
12900 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012901 }
12902
Gil Cukierman06403e12023-11-29 16:33:03 +000012903 private void checkForIdentifierDisclosureNotificationSupport() {
12904 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12905 throw new UnsupportedOperationException(
12906 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12907 + "above");
12908 }
12909 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12910 throw new UnsupportedOperationException(
12911 "Cellular identifier disclosure transparency operations unsupported by modem");
12912 }
12913 }
12914
Michael Groover826b71d2023-12-21 22:08:06 -060012915 private void checkForNullCipherNotificationSupport() {
12916 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12917 throw new UnsupportedOperationException(
12918 "Null cipher notification operations require HAL 2.2 or above");
12919 }
12920 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12921 throw new UnsupportedOperationException(
12922 "Null cipher notification operations unsupported by modem");
12923 }
12924 }
12925
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012926 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012927 * Get the SIM state for the slot index.
12928 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12929 *
12930 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12931 */
12932 @Override
12933 @SimState
12934 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012935 if (!mApp.getResources().getBoolean(
12936 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12938 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12939 }
joonhunshin4ac60942023-11-15 15:23:39 +000012940
Jack Yuf5badd92022-12-08 00:50:53 -080012941 IccCardConstants.State simState;
12942 if (slotIndex < 0) {
12943 simState = IccCardConstants.State.UNKNOWN;
12944 } else {
12945 Phone phone = null;
12946 try {
12947 phone = PhoneFactory.getPhone(slotIndex);
12948 } catch (IllegalStateException e) {
12949 // ignore
12950 }
12951 if (phone == null) {
12952 simState = IccCardConstants.State.UNKNOWN;
12953 } else {
12954 IccCard icc = phone.getIccCard();
12955 if (icc == null) {
12956 simState = IccCardConstants.State.UNKNOWN;
12957 } else {
12958 simState = icc.getState();
12959 }
12960 }
12961 }
12962 return simState.ordinal();
12963 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012964
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012965 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12966 boolean enableLogcat,
12967 long logcatStartTimestampMillis, boolean enableTelecomDump,
12968 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012969 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012970 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12971 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12972 ecdDataBuilder
12973 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12974 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012975 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012976 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012977 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012978 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12979 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012980 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12981 Executors.newCachedThreadPool(), db,
12982 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012983 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012984 }
12985
12986 /**
12987 * Request telephony to persist state for debugging emergency call failures.
12988 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012989 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012990 * @param enableLogcat whether to collect logcat output
12991 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12992 * @param enableTelecomDump whether to collect telecom dumpsys
12993 * @param enableTelephonyDump whether to collect telephony dumpsys
12994 */
12995 @Override
12996 @RequiresPermission(android.Manifest.permission.DUMP)
12997 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12998 long logcatStartTimestampMillis, boolean enableTelecomDump,
12999 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013000 // Verify that the caller has READ_DROPBOX_DATA permission.
13001 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13002 && Flags.enableReadDropboxPermission()) {
13003 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13004 "persistEmergencyCallDiagnosticData");
13005 } else {
13006 // Otherwise, enforce legacy permission.
13007 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13008 "persistEmergencyCallDiagnosticData");
13009 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013010 final long identity = Binder.clearCallingIdentity();
13011 try {
13012 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13013 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13014
13015 } finally {
13016 Binder.restoreCallingIdentity(identity);
13017 }
13018 }
13019
Hui Wang9b5793a2022-12-05 14:38:06 -060013020 /**
13021 * Get current cell broadcast ranges.
13022 */
13023 @Override
13024 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13025 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13026 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13027 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013028
13029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13030 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13031
Hui Wang9b5793a2022-12-05 14:38:06 -060013032 final long identity = Binder.clearCallingIdentity();
13033 try {
13034 return getPhone(subId).getCellBroadcastIdRanges();
13035 } finally {
13036 Binder.restoreCallingIdentity(identity);
13037 }
13038 }
13039
13040 /**
13041 * Set reception of cell broadcast messages with the list of the given ranges
13042 *
13043 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13044 */
13045 @Override
13046 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13047 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13048 @Nullable IIntegerConsumer callback) {
13049 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13050 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013051
13052 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13053 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13054
Hui Wang9b5793a2022-12-05 14:38:06 -060013055 final long identity = Binder.clearCallingIdentity();
13056 try {
13057 Phone phone = getPhoneFromSubId(subId);
13058 if (DBG) {
13059 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13060 }
13061 phone.setCellBroadcastIdRanges(ranges, result -> {
13062 if (callback != null) {
13063 try {
13064 callback.accept(result);
13065 } catch (RemoteException e) {
13066 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13067 }
13068 }
13069 });
13070 } finally {
13071 Binder.restoreCallingIdentity(identity);
13072 }
13073 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013074
13075 /**
13076 * Returns whether the device supports the domain selection service.
13077 *
13078 * @return {@code true} if the device supports the domain selection service.
13079 */
13080 @Override
13081 public boolean isDomainSelectionSupported() {
13082 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13083 "isDomainSelectionSupported");
13084
13085 final long identity = Binder.clearCallingIdentity();
13086 try {
13087 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13088 } finally {
13089 Binder.restoreCallingIdentity(identity);
13090 }
13091 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013092
13093 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013094 * Returns whether the AOSP domain selection service is supported.
13095 *
13096 * @return {@code true} if the AOSP domain selection service is supported,
13097 * {@code false} otherwise.
13098 */
13099 @Override
13100 public boolean isAospDomainSelectionService() {
13101 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13102 "isAospDomainSelectionService");
13103
13104 final long identity = Binder.clearCallingIdentity();
13105 try {
13106 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13107 String dssComponentName = mApp.getResources().getString(
13108 R.string.config_domain_selection_service_component_name);
13109 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13110 TelephonyDomainSelectionService.class.getName());
13111 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13112 + ", aosp=" + componentName.flattenToString());
13113 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13114 }
13115 } finally {
13116 Binder.restoreCallingIdentity(identity);
13117 }
13118 return false;
13119 }
13120
13121 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013122 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13123 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13124 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013125 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013126 * @param enableSatellite {@code true} to enable the satellite modem and
13127 * {@code false} to disable.
13128 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013129 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013130 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013131 *
13132 * @throws SecurityException if the caller doesn't have the required permission.
13133 */
13134 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013135 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013136 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013137 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013138 if (enableSatellite) {
13139 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13140 @Override
13141 protected void onReceiveResult(int resultCode, Bundle resultData) {
13142 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13143 + ", resultData=" + resultData);
13144 boolean isAllowed = false;
13145 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13146 callback::accept);
13147 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13148 if (resultData != null
13149 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13150 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13151 } else {
13152 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13153 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013154 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013155 result.accept(resultCode);
13156 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013157 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013158 if (isAllowed) {
13159 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013160 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013161 } else {
13162 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13163 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013164 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013165 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013166 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
joonhunshin83da7cd2024-08-22 08:53:35 +000013167 resultReceiver);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013168 } else {
13169 // No need to check if satellite is allowed at current location when disabling satellite
13170 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013171 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013172 }
Sarah Chin503828c2023-02-01 23:54:20 -080013173 }
13174
13175 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013176 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013177 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013178 * @param result The result receiver that returns whether the satellite modem is enabled
13179 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013180 *
13181 * @throws SecurityException if the caller doesn't have the required permission.
13182 */
13183 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013184 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013185 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013186 mSatelliteController.requestIsSatelliteEnabled(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013187 }
13188
13189 /**
Sarah Chin43457982023-02-15 17:50:38 -080013190 * Request to get whether the satellite service demo mode is enabled.
13191 *
Sarah Chin43457982023-02-15 17:50:38 -080013192 * @param result The result receiver that returns whether the satellite demo mode is enabled
13193 * if the request is successful or an error code if the request failed.
13194 *
13195 * @throws SecurityException if the caller doesn't have the required permission.
13196 */
13197 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013198 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013199 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013200 mSatelliteController.requestIsDemoModeEnabled(result);
Sarah Chin43457982023-02-15 17:50:38 -080013201 }
13202
13203 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013204 * Request to get whether the satellite service is enabled with emergency mode.
13205 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013206 * @param result The result receiver that returns whether the satellite emergency mode is
13207 * enabled if the request is successful or an error code if the request failed.
13208 *
13209 * @throws SecurityException if the caller doesn't have the required permission.
13210 */
13211 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013212 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013213 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013214 mSatelliteController.requestIsEmergencyModeEnabled(result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013215 }
13216
13217 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013218 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013219 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013220 * @param result The result receiver that returns whether the satellite service is supported on
13221 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013222 */
13223 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013224 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
13225 mSatelliteController.requestIsSatelliteSupported(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013226 }
13227
13228 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013229 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013230 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013231 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13232 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013233 *
13234 * @throws SecurityException if the caller doesn't have required permission.
13235 */
13236 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013237 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013238 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
joonhunshin83da7cd2024-08-22 08:53:35 +000013239 mSatelliteController.requestSatelliteCapabilities(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013240 }
13241
13242 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013243 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013244 * This can be called by the pointing UI when the user starts pointing to the satellite.
13245 * Modem should continue to report the pointing input as the device or satellite moves.
13246 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013247 * @param resultCallback The callback to get the result of the request.
13248 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013249 *
13250 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013251 */
13252 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013253 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013254 @NonNull IIntegerConsumer resultCallback,
13255 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13256 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013257 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013258 }
13259
13260 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013261 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013262 * This can be called by the pointing UI when the user stops pointing to the satellite.
13263 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013264 * @param resultCallback The callback to get the result of the request.
13265 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013266 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
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
joonhunshin83da7cd2024-08-22 08:53:35 +000013271 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013272 @NonNull IIntegerConsumer resultCallback,
13273 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13274 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013275 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013276 }
13277
13278 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013279 * Register the subscription with a satellite provider.
13280 * This is needed to register the subscription if the provider allows dynamic registration.
13281 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013282 * @param token The token to be used as a unique identifier for provisioning with satellite
13283 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013284 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013285 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013286 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013287 * @return The signal transport used by the caller to cancel the provision request,
13288 * or {@code null} if the request failed.
13289 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013290 * @throws SecurityException if the caller doesn't have the required permission.
13291 */
13292 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013293 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013294 @NonNull String token, @NonNull byte[] provisionData,
13295 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013296 enforceSatelliteCommunicationPermission("provisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013297 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013298 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013299 }
13300
13301 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013302 * Unregister the device/subscription with the satellite provider.
13303 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013304 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013305 * should report as deprovisioned.
13306 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013307 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013308 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013309 *
13310 * @throws SecurityException if the caller doesn't have the required permission.
13311 */
13312 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013313 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013314 @NonNull String token, @NonNull IIntegerConsumer callback) {
13315 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013316 mSatelliteController.deprovisionSatelliteService(token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013317 }
13318
13319 /**
Sarah Chin43457982023-02-15 17:50:38 -080013320 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013321 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013322 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013323 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013324 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013325 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013326 * @throws SecurityException if the caller doesn't have the required permission.
13327 */
13328 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013329 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013330 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013331 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013332 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013333 }
13334
13335 /**
Sarah Chin43457982023-02-15 17:50:38 -080013336 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013337 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013338 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013339 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013340 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013341 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013342 * @throws SecurityException if the caller doesn't have the required permission.
13343 */
13344 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013345 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013346 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013347 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013348 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013349 }
13350
13351 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013352 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013353 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013354 * @param result The result receiver that returns whether the device is provisioned with a
13355 * satellite provider if the request is successful or an error code if the
13356 * request failed.
13357 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013358 * @throws SecurityException if the caller doesn't have the required permission.
13359 */
13360 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013361 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013362 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
joonhunshin83da7cd2024-08-22 08:53:35 +000013363 mSatelliteController.requestIsSatelliteProvisioned(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013364 }
13365
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013366 /**
Sarah Chin43457982023-02-15 17:50:38 -080013367 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 *
Sarah Chin43457982023-02-15 17:50:38 -080013369 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013370 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013371 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013372 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013373 * @throws SecurityException if the caller doesn't have the required permission.
13374 */
13375 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013376 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013377 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013378 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013379 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013380 }
13381
13382 /**
Sarah Chin43457982023-02-15 17:50:38 -080013383 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013384 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013385 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013386 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013387 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013388 *
13389 * @throws SecurityException if the caller doesn't have the required permission.
13390 */
13391 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013392 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013393 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013394 mSatelliteController.unregisterForModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013395 }
13396
13397 /**
13398 * Register to receive incoming datagrams over satellite.
13399 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013400 * @param callback The callback to handle incoming datagrams over satellite.
13401 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013402 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013403 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013404 * @throws SecurityException if the caller doesn't have the required permission.
13405 */
13406 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013407 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013408 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013409 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013410 return mSatelliteController.registerForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013411 }
13412
13413 /**
13414 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013415 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013416 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013417 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013418 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013419 *
13420 * @throws SecurityException if the caller doesn't have the required permission.
13421 */
13422 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013423 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013424 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013425 mSatelliteController.unregisterForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013426 }
13427
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013428 /**
13429 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013430 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013431 * This method requests modem to check if there are any pending datagrams to be received over
13432 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013433 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013434 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013435 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013436 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013437 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013438 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013439 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013440 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
joonhunshin83da7cd2024-08-22 08:53:35 +000013441 mSatelliteController.pollPendingDatagrams(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013442 }
13443
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013444 /**
13445 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013446 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013447 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13448 * input to this method. Datagram received here will be passed down to modem without any
13449 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013450 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013451 * @param datagramType datagram type indicating whether the datagram is of type
13452 * SOS_SMS or LOCATION_SHARING.
13453 * @param datagram encoded gateway datagram which is encrypted by the caller.
13454 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013455 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13456 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013457 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013458 *
13459 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013460 */
13461 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013462 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013463 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13464 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013465 enforceSatelliteCommunicationPermission("sendDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013466 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013467 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013468 }
13469
Sarah Chindf715ec2023-02-13 13:46:24 -080013470 /**
13471 * Request to get whether satellite communication is allowed for the current location.
13472 *
13473 * @param subId The subId of the subscription to check whether satellite communication is
13474 * allowed for the current location for.
13475 * @param result The result receiver that returns whether satellite communication is allowed
13476 * for the current location if the request is successful or an error code
13477 * if the request failed.
13478 *
13479 * @throws SecurityException if the caller doesn't have the required permission.
13480 */
13481 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013482 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013483 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013484 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
joonhunshin83da7cd2024-08-22 08:53:35 +000013485 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013486 }
13487
13488 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013489 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013490 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013491 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013492 * be visible if the request is successful or an error code if the request failed.
13493 *
13494 * @throws SecurityException if the caller doesn't have the required permission.
13495 */
13496 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013497 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013498 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
joonhunshin83da7cd2024-08-22 08:53:35 +000013499 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013500 }
13501
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013502 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013503 * Inform that Device is aligned to satellite for demo mode.
13504 *
Hakjun Choiae365972023-04-25 11:00:31 +000013505 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13506 * {@code false} Device fails to align with the satellite for demo mode.
13507 *
13508 * @throws SecurityException if the caller doesn't have required permission.
13509 */
13510 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13511
joonhunshin83da7cd2024-08-22 08:53:35 +000013512 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013513 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
joonhunshin83da7cd2024-08-22 08:53:35 +000013514 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013515 }
13516
13517 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013518 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13519 * by modem.
13520 *
13521 * @param subId The subId of the subscription to request for.
13522 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013523 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013524 * operation.
13525 *
13526 * @throws SecurityException if the caller doesn't have required permission.
13527 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013528 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013529 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13530 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013531 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013532 final long identity = Binder.clearCallingIdentity();
13533 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013534 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013535 } finally {
13536 Binder.restoreCallingIdentity(identity);
13537 }
13538 }
13539
13540 /**
13541 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13542 * by modem.
13543 *
13544 * @param subId The subId of the subscription to request for.
13545 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013546 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013547 * operation.
13548 *
13549 * @throws SecurityException if the caller doesn't have required permission.
13550 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013551 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013552 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13553 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013554 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013555 final long identity = Binder.clearCallingIdentity();
13556 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013557 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013558 } finally {
13559 Binder.restoreCallingIdentity(identity);
13560 }
13561 }
13562
13563 /**
13564 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013565 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013566 *
13567 * @param subId The subId of the subscription to request for.
13568 *
13569 * @return Integer array of reasons for disallowing satellite communication.
13570 *
13571 * @throws SecurityException if the caller doesn't have the required permission.
13572 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013573 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013574 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013575 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013576 final long identity = Binder.clearCallingIdentity();
13577 try {
13578 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013579 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013580 return reasonSet.stream().mapToInt(i->i).toArray();
13581 } finally {
13582 Binder.restoreCallingIdentity(identity);
13583 }
13584 }
13585
13586 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013587 * Request to get the signal strength of the satellite connection.
13588 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013589 * @param result Result receiver to get the error code of the request and the current signal
13590 * strength of the satellite connection.
13591 *
13592 * @throws SecurityException if the caller doesn't have required permission.
13593 */
13594 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013595 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013596 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13597 final long identity = Binder.clearCallingIdentity();
13598 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013599 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013600 } finally {
13601 Binder.restoreCallingIdentity(identity);
13602 }
13603 }
13604
13605 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013606 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13607 * is not successful, a {@link ServiceSpecificException} that contains
13608 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013609 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013610 * @param callback The callback to handle the NTN signal strength changed event. If the
13611 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13612 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13613 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13614 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013615 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013616 * @throws SecurityException If the caller doesn't have the required permission.
13617 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013618 */
13619 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013620 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013621 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013622 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13623 final long identity = Binder.clearCallingIdentity();
13624 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013625 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013626 } finally {
13627 Binder.restoreCallingIdentity(identity);
13628 }
13629 }
13630
13631 /**
13632 * Unregisters for NTN signal strength changed from satellite modem.
13633 * If callback was not registered before, the request will be ignored.
13634 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013635 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013636 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013637 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013638 *
13639 * @throws SecurityException if the caller doesn't have the required permission.
13640 */
13641 @Override
13642 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013643 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013644 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13645 final long identity = Binder.clearCallingIdentity();
13646 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013647 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013648 } finally {
13649 Binder.restoreCallingIdentity(identity);
13650 }
13651 }
13652
13653 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013654 * Registers for satellite capabilities change event from the satellite service.
13655 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013656 * @param callback The callback to handle the satellite capabilities changed event.
13657 *
13658 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13659 *
13660 * @throws SecurityException if the caller doesn't have required permission.
13661 */
13662 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013663 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013664 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013665 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013666 final long identity = Binder.clearCallingIdentity();
13667 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013668 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013669 } finally {
13670 Binder.restoreCallingIdentity(identity);
13671 }
13672 }
13673
13674 /**
13675 * Unregisters for satellite capabilities change event from the satellite service.
13676 * If callback was not registered before, the request will be ignored.
13677 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013678 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013679 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013680 *
13681 * @throws SecurityException if the caller doesn't have required permission.
13682 */
13683 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013684 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013685 @NonNull ISatelliteCapabilitiesCallback callback) {
13686 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013687 final long identity = Binder.clearCallingIdentity();
13688 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013689 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013690 } finally {
13691 Binder.restoreCallingIdentity(identity);
13692 }
13693 }
13694
13695 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013696 * Registers for the satellite supported state changed.
13697 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013698 * @param callback The callback to handle the satellite supported state changed event.
13699 *
13700 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13701 *
13702 * @throws SecurityException if the caller doesn't have the required permission.
13703 */
13704 @Override
13705 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013706 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013707 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013708 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013709 }
13710
13711 /**
13712 * Unregisters for the satellite supported state changed.
13713 * If callback was not registered before, the request will be ignored.
13714 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013715 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013716 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000013717 *
13718 * @throws SecurityException if the caller doesn't have the required permission.
13719 */
13720 @Override
13721 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013722 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013723 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013724 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013725 }
13726
13727 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013728 * This API can be used by only CTS to update satellite vendor service package name.
13729 *
13730 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013731 * @param provisioned Whether satellite should be provisioned or not.
13732 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013733 * @return {@code true} if the satellite vendor service is set successfully,
13734 * {@code false} otherwise.
13735 */
Hakjun Choic3393242024-06-26 18:02:08 +000013736 public boolean setSatelliteServicePackageName(String servicePackageName,
13737 String provisioned) {
13738 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13739 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013740 TelephonyPermissions.enforceShellOnly(
13741 Binder.getCallingUid(), "setSatelliteServicePackageName");
13742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13743 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13744 "setSatelliteServicePackageName");
Hakjun Choic3393242024-06-26 18:02:08 +000013745 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13746 provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013747 }
13748
13749 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013750 * This API can be used by only CTS to update satellite gateway service package name.
13751 *
13752 * @param servicePackageName The package name of the satellite gateway service.
13753 * @return {@code true} if the satellite gateway service is set successfully,
13754 * {@code false} otherwise.
13755 */
13756 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13757 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13758 TelephonyPermissions.enforceShellOnly(
13759 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13761 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13762 "setSatelliteGatewayServicePackageName");
13763 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13764 }
13765
13766 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013767 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13768 *
13769 * @param packageName The package name of the satellite pointing UI app.
13770 * @param className The class name of the satellite pointing UI app.
13771 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13772 * {@code false} otherwise.
13773 */
13774 public boolean setSatellitePointingUiClassName(
13775 @Nullable String packageName, @Nullable String className) {
13776 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13777 + ", className=" + className);
13778 TelephonyPermissions.enforceShellOnly(
13779 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13781 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13782 "setSatelliteGatewayServicePackageName");
13783 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13784 }
13785
13786 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013787 * This API can be used by only CTS to update the timeout duration in milliseconds that
13788 * satellite should stay at listening mode to wait for the next incoming page before disabling
13789 * listening mode.
13790 *
13791 * @param timeoutMillis The timeout duration in millisecond.
13792 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13793 */
13794 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13795 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13796 TelephonyPermissions.enforceShellOnly(
13797 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13799 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13800 "setSatelliteListeningTimeoutDuration");
13801 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13802 }
13803
13804 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013805 * This API can be used by only CTS to override the timeout durations used by the
13806 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013807 *
13808 * @param timeoutMillis The timeout duration in millisecond.
13809 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13810 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013811 public boolean setDatagramControllerTimeoutDuration(
13812 boolean reset, int timeoutType, long timeoutMillis) {
13813 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13814 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013815 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013816 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13818 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013819 "setDatagramControllerTimeoutDuration");
13820 return mSatelliteController.setDatagramControllerTimeoutDuration(
13821 reset, timeoutType, timeoutMillis);
13822 }
13823
13824 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013825 * This API can be used by only CTS to override the boolean configs used by the
13826 * DatagramController module.
13827 *
13828 * @param enable Whether to enable or disable boolean config.
13829 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13830 */
13831 public boolean setDatagramControllerBooleanConfig(
13832 boolean reset, int booleanType, boolean enable) {
13833 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13834 + ", reset=" + reset + ", enable=" + enable);
13835 TelephonyPermissions.enforceShellOnly(
13836 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13838 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13839 "ssetDatagramControllerBooleanConfig");
13840 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13841 }
13842
13843
13844 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013845 * This API can be used by only CTS to override the timeout durations used by the
13846 * SatelliteController module.
13847 *
13848 * @param timeoutMillis The timeout duration in millisecond.
13849 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13850 */
13851 public boolean setSatelliteControllerTimeoutDuration(
13852 boolean reset, int timeoutType, long timeoutMillis) {
13853 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13854 + reset + ", timeoutMillis=" + timeoutMillis);
13855 TelephonyPermissions.enforceShellOnly(
13856 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13858 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13859 "setSatelliteControllerTimeoutDuration");
13860 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13861 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013862 }
13863
13864 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013865 * This API can be used in only testing to override connectivity status in monitoring emergency
13866 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13867 *
13868 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13869 * of the following values to enable the override:
13870 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13871 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13872 * To disable the override, use -1 for handoverType.
13873 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13874 * delaySeconds after the emergency call starts.
13875 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13876 */
13877 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13878 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13879 TelephonyPermissions.enforceShellOnly(
13880 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13882 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13883 "setEmergencyCallToSatelliteHandoverType");
13884 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13885 handoverType, delaySeconds);
13886 }
13887
13888 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013889 * This API can be used in only testing to override oem-enabled satellite provision status.
13890 *
13891 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13892 * otherwise.
13893 * @param isProvisioned The overriding provision status.
13894 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13895 */
13896 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13897 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13898 + ", isProvisioned=" + isProvisioned);
13899 TelephonyPermissions.enforceShellOnly(
13900 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13902 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13903 "setOemEnabledSatelliteProvisionStatus");
13904 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13905 }
13906
13907 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013908 * This API should be used by only CTS tests to forcefully set telephony country codes.
13909 *
13910 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13911 */
13912 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13913 Map cachedNetworkCountryCodes, String locationCountryCode,
13914 long locationCountryCodeTimestampNanos) {
13915 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13916 + String.join(", ", currentNetworkCountryCodes)
13917 + ", locationCountryCode=" + locationCountryCode
13918 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13919 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13920 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13921 TelephonyPermissions.enforceShellOnly(
13922 Binder.getCallingUid(), "setCachedLocationCountryCode");
13923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13924 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13925 "setCachedLocationCountryCode");
youngtaecha31b141d2024-07-15 12:01:39 +000013926 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), mFeatureFlags)
13927 .setCountryCodes(reset, currentNetworkCountryCodes, cachedNetworkCountryCodes,
13928 locationCountryCode, locationCountryCodeTimestampNanos);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013929 }
13930
13931 /**
13932 * This API should be used by only CTS tests to override the overlay configs of satellite
13933 * access controller.
13934 *
13935 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13936 * otherwise.
13937 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13938 */
13939 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13940 String s2CellFile, long locationFreshDurationNanos,
13941 List<String> satelliteCountryCodes) {
13942 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13943 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13944 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13945 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13946 ? String.join(", ", satelliteCountryCodes) : null));
13947 TelephonyPermissions.enforceShellOnly(
13948 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13950 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13951 "setSatelliteAccessControlOverlayConfigs");
13952 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13953 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13954 }
13955
13956 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013957 * This API can be used by only CTS to override the cached value for the device overlay config
13958 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13959 * outgoing satellite datagrams should be sent to modem in demo mode.
13960 *
13961 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13962 * satellite modem or not.
13963 *
13964 * @return {@code true} if the operation is successful, {@code false} otherwise.
13965 */
13966 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13967 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13968 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13969 + "disabled");
13970 return false;
13971 }
13972 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13973 TelephonyPermissions.enforceShellOnly(
13974 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13976 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13977 "setShouldSendDatagramToModemInDemoMode");
13978 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13979 shouldSendToModemInDemoMode);
13980 }
13981
13982 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013983 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13984 *
13985 * @param state a state indicates whether satellite access allowed state should be cached and
13986 * the allowed state.
13987 * @return {@code true} if the setting is successful, {@code false} otherwise.
13988 */
13989 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13990 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13991 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13992 + "oemEnabledSatelliteFlag is disabled");
13993 return false;
13994 }
13995
13996 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13997 + "state=" + state);
13998 TelephonyPermissions.enforceShellOnly(
13999 Binder.getCallingUid(),
14000 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14002 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14003 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14004 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14005 state);
14006 }
14007
14008 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014009 * Sets the service defined in ComponentName to be bound.
14010 *
14011 * This should only be used for testing.
14012 * @return {@code true} if the DomainSelectionService to bind to was set,
14013 * {@code false} otherwise.
14014 */
14015 @Override
14016 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14017 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14018
14019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14020 "setDomainSelectionServiceOverride");
14021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14022 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14023
14024 final long identity = Binder.clearCallingIdentity();
14025 try {
14026 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14027 return DomainSelectionResolver.getInstance()
14028 .setDomainSelectionServiceOverride(componentName);
14029 }
14030 } finally {
14031 Binder.restoreCallingIdentity(identity);
14032 }
14033 return false;
14034 }
14035
14036 /**
14037 * Clears the DomainSelectionService override.
14038 *
14039 * This should only be used for testing.
14040 * @return {@code true} if the DomainSelectionService override was cleared,
14041 * {@code false} otherwise.
14042 */
14043 @Override
14044 public boolean clearDomainSelectionServiceOverride() {
14045 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14046
14047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14048 "clearDomainSelectionServiceOverride");
14049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14050 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14051
14052 final long identity = Binder.clearCallingIdentity();
14053 try {
14054 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14055 return DomainSelectionResolver.getInstance()
14056 .clearDomainSelectionServiceOverride();
14057 }
14058 } finally {
14059 Binder.restoreCallingIdentity(identity);
14060 }
14061 return false;
14062 }
14063
14064 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014065 * Enable or disable notifications sent for cellular identifier disclosure events.
14066 *
14067 * Disclosure events are defined as instances where a device has sent a cellular identifier
14068 * on the Non-access stratum (NAS) before a security context is established. As a result the
14069 * identifier is sent in the clear, which has privacy implications for the user.
14070 *
14071 * @param enable if notifications about disclosure events should be enabled
14072 * @throws SecurityException if the caller does not have the required privileges
14073 * @throws UnsupportedOperationException if the modem does not support this feature.
14074 */
14075 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014076 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014077 enforceModifyPermission();
14078 checkForIdentifierDisclosureNotificationSupport();
14079
14080 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14081 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14082 editor.apply();
14083
14084 // Each phone instance is responsible for updating its respective modem immediately
14085 // after we've made a preference change.
14086 for (Phone phone : PhoneFactory.getPhones()) {
14087 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14088 }
14089 }
14090
14091 /**
14092 * Get whether or not cellular identifier disclosure notifications are enabled.
14093 *
14094 * @throws SecurityException if the caller does not have the required privileges
14095 * @throws UnsupportedOperationException if the modem does not support this feature.
14096 */
14097 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014098 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014099 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14100 checkForIdentifierDisclosureNotificationSupport();
14101 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14102 }
14103
14104 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014105 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14106 * are in use by the cellular modem.
14107 *
14108 * @throws IllegalStateException if the Telephony process is not currently available
14109 * @throws SecurityException if the caller does not have the required privileges
14110 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14111 * and integrity algorithms in use
14112 * @hide
14113 */
14114 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014115 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014116 enforceModifyPermission();
14117 checkForNullCipherNotificationSupport();
14118
14119 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14120 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14121 editor.apply();
14122
14123 // Each phone instance is responsible for updating its respective modem immediately
14124 // after a preference change.
14125 for (Phone phone : PhoneFactory.getPhones()) {
14126 phone.handleNullCipherNotificationPreferenceChanged();
14127 }
14128 }
14129
14130 /**
14131 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14132 * cellular modem.
14133 *
14134 * @throws IllegalStateException if the Telephony process is not currently available
14135 * @throws SecurityException if the caller does not have the required privileges
14136 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14137 * and integrity algorithms in use
14138 * @hide
14139 */
14140 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14141 public boolean isNullCipherNotificationsEnabled() {
14142 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14143 checkForNullCipherNotificationSupport();
14144 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14145 }
14146
14147 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014148 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14149 *
14150 * <p>This method behaves in one of the following ways:
14151 * <ul>
14152 * <li>return true : if the calling package has the appop permission {@link
14153 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14154 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14155 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14156 * Owner device identifier access check, or the calling package has carrier privileges</>
14157 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14158 * </ul>
14159 */
14160 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14161 String callingPackage, @Nullable String callingFeatureId, String message) {
14162 for (Phone phone : PhoneFactory.getPhones()) {
14163 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14164 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14165 return true;
14166 }
14167 }
14168 return false;
14169 }
arunvoddud7401012022-12-15 16:08:12 +000014170
14171 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014172 * @return The subscription manager service instance.
14173 */
14174 public SubscriptionManagerService getSubscriptionManagerService() {
14175 return SubscriptionManagerService.getInstance();
14176 }
14177
14178 /**
arunvoddud7401012022-12-15 16:08:12 +000014179 * Class binds the consumer[callback] and carrierId.
14180 */
14181 private static class CallerCallbackInfo {
14182 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014183 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014184
Steve Statia28b7cb32024-03-11 23:58:50 +000014185 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014186 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014187 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014188 }
14189
14190 public Consumer<Integer> getConsumer() {
14191 return mConsumer;
14192 }
14193
Steve Statia28b7cb32024-03-11 23:58:50 +000014194 public Set<Integer> getCarrierIds() {
14195 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014196 }
14197 }
joonhunshin4ac60942023-11-15 15:23:39 +000014198
14199 /*
14200 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14201 * But the context that is passed in is unused if the phone app is already alive.
14202 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14203 */
14204 @VisibleForTesting
14205 public void setPackageManager(PackageManager packageManager) {
14206 mPackageManager = packageManager;
14207 }
14208
14209 /*
Nate Myren453c3472024-03-13 11:28:11 -070014210 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14211 * But the context that is passed in is unused if the phone app is already alive.
14212 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14213 */
14214 @VisibleForTesting
14215 public void setAppOpsManager(AppOpsManager appOps) {
14216 mAppOps = appOps;
14217 }
14218
14219 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014220 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14221 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14222 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14223 */
14224 @VisibleForTesting
14225 public void setFeatureFlags(FeatureFlags featureFlags) {
14226 mFeatureFlags = featureFlags;
14227 }
14228
14229 /**
14230 * Make sure the device has required telephony feature
14231 *
14232 * @throws UnsupportedOperationException if the device does not have required telephony feature
14233 */
14234 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14235 @NonNull String telephonyFeature, @NonNull String methodName) {
14236 if (callingPackage == null || mPackageManager == null) {
14237 return;
14238 }
14239
14240 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14241 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014242 Binder.getCallingUserHandle())
14243 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14244 // Skip to check associated telephony feature,
14245 // if compatibility change is not enabled for the current process or
14246 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014247 return;
14248 }
14249
14250 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14251 throw new UnsupportedOperationException(
14252 methodName + " is unsupported without " + telephonyFeature);
14253 }
14254 }
youngtaecha5d483d52024-04-29 17:05:45 +000014255
14256 /**
14257 * Registers for the satellite communication allowed state changed.
14258 *
14259 * @param subId The subId of the subscription to register for the satellite communication
14260 * allowed state changed.
14261 * @param callback The callback to handle the satellite communication allowed
14262 * state changed event.
14263 *
14264 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14265 *
14266 * @throws SecurityException if the caller doesn't have the required permission.
14267 */
14268 @Override
14269 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14270 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14271 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014272 final long identity = Binder.clearCallingIdentity();
14273 try {
14274 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14275 subId, callback);
14276 } finally {
14277 Binder.restoreCallingIdentity(identity);
14278 }
youngtaecha5d483d52024-04-29 17:05:45 +000014279 }
14280
14281 /**
14282 * Unregisters for the satellite communication allowed state changed.
14283 * If callback was not registered before, the request will be ignored.
14284 *
14285 * @param subId The subId of the subscription to unregister for the satellite communication
14286 * allowed state changed.
14287 * @param callback The callback that was passed to
14288 * {@link #registerForCommunicationAllowedStateChanged(int,
14289 * ISatelliteCommunicationAllowedStateCallback)}. *
14290 * @throws SecurityException if the caller doesn't have the required permission.
14291 */
14292 @Override
14293 public void unregisterForCommunicationAllowedStateChanged(
14294 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14295 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014296 final long identity = Binder.clearCallingIdentity();
14297 try {
14298 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14299 callback);
14300 } finally {
14301 Binder.restoreCallingIdentity(identity);
14302 }
youngtaecha5d483d52024-04-29 17:05:45 +000014303 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014304
14305 /**
14306 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14307 *
14308 * @param subId The subId of the subscription to the satellite session stats for.
14309 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14310 * if the request is successful or an error code if the request failed.
14311 *
14312 * @throws SecurityException if the caller doesn't have required permission.
14313 */
14314 @Override
14315 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14316 enforceModifyPermission();
14317 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014318 final long identity = Binder.clearCallingIdentity();
14319 try {
14320 mSatelliteController.requestSatelliteSessionStats(subId, result);
14321 } finally {
14322 Binder.restoreCallingIdentity(identity);
14323 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014324 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014325
14326 /**
14327 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14328 *
14329 * @param result The result receiver, which returns the list of prioritized satellite tokens
14330 * to be used for provision if the request is successful or an error code if the request failed.
14331 *
14332 * @throws SecurityException if the caller doesn't have the required permission.
14333 */
14334 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014335 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14336 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014337 final long identity = Binder.clearCallingIdentity();
14338 try {
14339 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14340 } finally {
14341 Binder.restoreCallingIdentity(identity);
14342 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014343 }
14344
14345 /**
14346 * Deliver the list of provisioned satellite subscriber ids.
14347 *
14348 * @param list List of provisioned satellite subscriber ids.
14349 * @param result The result receiver that returns whether deliver success or fail.
14350 *
14351 * @throws SecurityException if the caller doesn't have the required permission.
14352 */
14353 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014354 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014355 @NonNull ResultReceiver result) {
14356 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014357 final long identity = Binder.clearCallingIdentity();
14358 try {
14359 mSatelliteController.provisionSatellite(list, result);
14360 } finally {
14361 Binder.restoreCallingIdentity(identity);
14362 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014363 }
Jack Yufa8ed012023-02-11 15:42:28 -080014364}