blob: be4b94c9d67c389b4f88f3bddd07ec51aca5c355 [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) {
Rambo Wang7eb26962024-07-11 19:48:30 +00008162 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8163 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8164 "Invalid package:" + callingPackage);
8165 } else {
8166 try {
8167 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8168 Binder.getCallingUid())) {
8169 throw new SecurityException("Invalid package:" + callingPackage);
8170 }
8171 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008172 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008173 }
Hall Liu82694d52020-12-11 18:22:04 -08008174 }
joonhunshin4ac60942023-11-15 15:23:39 +00008175
8176 enforceTelephonyFeatureWithException(callingPackage,
8177 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8178
Hall Liu82694d52020-12-11 18:22:04 -08008179 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008180 List<String> dialerRoleHolders;
8181 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8182 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8183 UserHandle.of(ActivityManager.getCurrentUser()));
8184 } else {
8185 dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8186 }
Hall Liu82694d52020-12-11 18:22:04 -08008187 if (!dialerRoleHolders.contains(callingPackage)) {
8188 throw new SecurityException("App must be the dialer role holder to"
8189 + " upload a call composer pic");
8190 }
8191
8192 Executors.newSingleThreadExecutor().execute(() -> {
8193 ByteArrayOutputStream output = new ByteArrayOutputStream(
8194 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8195 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8196 boolean readUntilEnd = false;
8197 int totalBytesRead = 0;
8198 byte[] buffer = new byte[16 * 1024];
8199 while (true) {
8200 int numRead;
8201 try {
8202 numRead = input.read(buffer);
8203 } catch (IOException e) {
8204 try {
8205 fd.checkError();
8206 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8207 null);
8208 } catch (IOException e1) {
8209 // This means that the other side closed explicitly with an error. If this
8210 // happens, log and ignore.
8211 loge("Remote end of call composer picture pipe closed: " + e1);
8212 }
8213 break;
8214 }
8215 if (numRead == -1) {
8216 readUntilEnd = true;
8217 break;
8218 }
8219 totalBytesRead += numRead;
8220 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8221 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8222 try {
8223 input.close();
8224 } catch (IOException e) {
8225 // ignore
8226 }
8227 break;
8228 }
8229 output.write(buffer, 0, numRead);
8230 }
8231 // Generally, the remote end will close the file descriptors. The only case where we
8232 // close is above, where the picture size is too big.
8233
8234 try {
8235 fd.checkError();
8236 } catch (IOException e) {
8237 loge("Remote end for call composer closed with an error: " + e);
8238 return;
8239 }
8240
Hall Liuaa4211e2021-01-20 15:43:39 -08008241 if (!readUntilEnd) {
8242 loge("Did not finish reading entire image; aborting");
8243 return;
8244 }
Hall Liu82694d52020-12-11 18:22:04 -08008245
Hall Liuaa4211e2021-01-20 15:43:39 -08008246 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8247 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8248 new CallComposerPictureTransfer.Factory() {},
8249 imageData,
8250 (result) -> {
8251 if (result.first != null) {
8252 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8253 Bundle outputResult = new Bundle();
8254 outputResult.putParcelable(
8255 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8256 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8257 outputResult);
8258 } else {
8259 callback.send(result.second, null);
8260 }
8261 }
8262 );
Hall Liu82694d52020-12-11 18:22:04 -08008263 });
8264 }
8265
8266 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008267 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008268 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
joonhunshin4ac60942023-11-15 15:23:39 +00008271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8272 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 final long identity = Binder.clearCallingIdentity();
8275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008276 ImsManager.getInstance(defaultPhone.getContext(),
8277 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008281 }
8282
8283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008284 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008285 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8287 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008288 return false;
8289 }
Svet Ganovb320e182015-04-16 12:30:10 -07008290
joonhunshin4ac60942023-11-15 15:23:39 +00008291 enforceTelephonyFeatureWithException(callingPackage,
8292 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 // Check the user preference and the system-level IMS setting. Even if the user has
8297 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8298 // In the long run, we may instead need to check if there exists a connection service
8299 // which can support video calling.
8300 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 return imsManager.isVtEnabledByPlatform()
8303 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8304 && imsManager.isVtEnabledByUser();
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
8307 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008308 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008309
Andrew Leea1239f22015-03-02 17:44:07 -08008310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008311 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8312 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008314 mApp, subId, callingPackage, callingFeatureId,
8315 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 return false;
8317 }
8318
joonhunshin4ac60942023-11-15 15:23:39 +00008319 enforceTelephonyFeatureWithException(callingPackage,
8320 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 final long identity = Binder.clearCallingIdentity();
8323 try {
8324 CarrierConfigManager configManager =
8325 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008326 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
Andrew Leea1239f22015-03-02 17:44:07 -08008331 }
8332
8333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008334 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008336 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 return false;
8338 }
8339
joonhunshin4ac60942023-11-15 15:23:39 +00008340 enforceTelephonyFeatureWithException(callingPackage,
8341 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 final long identity = Binder.clearCallingIdentity();
8344 try {
8345 CarrierConfigManager configManager =
8346 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008347 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
Andrew Leea1239f22015-03-02 17:44:07 -08008352 }
8353
Andrew Lee9431b832015-03-09 18:46:45 -07008354 @Override
8355 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008356 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008357 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008358 }
8359
8360 @Override
8361 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8363 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 final long identity = Binder.clearCallingIdentity();
8366 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008367 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
Andrew Lee9431b832015-03-09 18:46:45 -07008371 }
8372
Hall Liuf6668912018-10-31 17:05:23 -07008373 /**
8374 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8375 * support for the feature and device firmware support.
8376 *
8377 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8378 */
8379 @Override
8380 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8382 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008384 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 final Phone phone = getPhone(subscriptionId);
8386 if (phone == null) {
8387 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8388 return false;
8389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008391 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008393 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8394 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8395 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 return isCarrierSupported && isDeviceSupported;
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
Hall Liu98187582018-01-22 19:15:32 -08008400 }
8401
Hall Liuf6668912018-10-31 17:05:23 -07008402 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008403 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8404 * RTT setting, will return true if the device and carrier both support RTT.
8405 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008406 */
8407 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408 final long identity = Binder.clearCallingIdentity();
8409 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008410 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8411 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8412 return false;
8413 }
8414 }
8415
Hall Liu5bab75c2019-12-11 23:58:20 +00008416 boolean isRttSupported = isRttSupported(subscriptionId);
8417 boolean isUserRttSettingOn = Settings.Secure.getInt(
8418 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8419 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8420 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8421 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008425 }
8426
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008427 @Deprecated
8428 @Override
8429 public String getDeviceId(String callingPackage) {
8430 return getDeviceIdWithFeature(callingPackage, null);
8431 }
8432
Sanket Padawe7310cc72015-01-14 09:53:20 -08008433 /**
8434 * Returns the unique device ID of phone, for example, the IMEI for
8435 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8436 *
8437 * <p>Requires Permission:
8438 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8439 */
8440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008441 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008442 try {
8443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8444 } catch (SecurityException se) {
8445 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8446 throw new SecurityException("Package " + callingPackage + " does not belong to "
8447 + Binder.getCallingUid());
8448 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008449 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008450 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008451 return null;
8452 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008453 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008454 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008455 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008456 return null;
8457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458
8459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 return phone.getDeviceId();
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008465 }
8466
Ping Sunc67b7c22016-03-02 19:16:45 +08008467 /**
8468 * {@hide}
8469 * Returns the IMS Registration Status on a particular subid
8470 *
8471 * @param subId
8472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008473 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008474 Phone phone = getPhone(subId);
8475 if (phone != null) {
8476 return phone.isImsRegistered();
8477 } else {
8478 return false;
8479 }
8480 }
8481
Santos Cordon7a1885b2015-02-03 11:15:19 -08008482 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008483 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008484 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008486 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008487 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8488 }
8489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
8494 }
8495 }
8496
8497 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008498 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008499 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008500 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008501 mApp,
8502 subscriptionId,
8503 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8504 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008505
8506 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8507 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8508
Tyler Gunnf70ed162019-04-03 15:28:53 -07008509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 Phone phone = getPhone(subscriptionId);
8512 if (phone == null) {
8513 return null;
8514 }
8515 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008521 /**
8522 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008523 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008524 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 Phone phone = getPhone(subId);
8528 if (phone != null) {
8529 return phone.isWifiCallingEnabled();
8530 } else {
8531 return false;
8532 }
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008535 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008536 }
8537
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008538 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008540 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008541 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 Phone phone = getPhone(subId);
8545 if (phone != null) {
8546 return phone.isVideoEnabled();
8547 } else {
8548 return false;
8549 }
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008552 }
8553 }
8554
8555 /**
8556 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8557 * defined in {@link ImsRegistrationImplBase}.
8558 */
8559 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008560 final long identity = Binder.clearCallingIdentity();
8561 try {
8562 Phone phone = getPhone(subId);
8563 if (phone != null) {
8564 return phone.getImsRegistrationTech();
8565 } else {
8566 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8567 }
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008570 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008571 }
8572
Stuart Scott8eef64f2015-04-08 15:13:54 -07008573 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008574 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008575 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008576
8577 enforceTelephonyFeatureWithException(callingPackage,
8578 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8579
Stuart Scott981d8582015-04-21 14:09:50 -07008580 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8581 return;
8582 }
Kai Shif70f46f2021-03-03 13:59:46 -08008583 Phone defaultPhone = getDefaultPhone();
8584 if (defaultPhone != null) {
8585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8586 mApp, getDefaultPhone().getSubId(), "factoryReset");
8587 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008588 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008589
Svet Ganovcc087f82015-05-12 20:35:54 -07008590 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008591 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8592 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008593 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008594 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008595 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008596 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008597 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008598 setDataRoamingEnabled(subId, phone == null ? false
8599 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008600 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008601 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008602 // There has been issues when Sms raw table somehow stores orphan
8603 // fragments. They lead to garbled message when new fragments come
8604 // in and combined with those stale ones. In case this happens again,
8605 // user can reset all network settings which will clean up this table.
8606 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008607 // Clean up IMS settings as well here.
8608 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008609 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008610 ImsManager.getInstance(mApp, slotId).factoryReset();
8611 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008612
Kai Shif70f46f2021-03-03 13:59:46 -08008613 if (defaultPhone == null) {
8614 return;
8615 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008616 // Erase modem config if erase modem on network setting is enabled.
8617 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8618 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8619 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008620 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008621 }
Kai Shif70f46f2021-03-03 13:59:46 -08008622
8623 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008624 } finally {
8625 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008626 }
8627 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008628
SongFerngWangfd89b102021-05-27 22:44:54 +08008629 @VisibleForTesting
8630 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8631 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8632 return;
8633 }
8634 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8635 RILConstants.PREFERRED_NETWORK_MODE);
8636 SubscriptionManager.setSubscriptionProperty(subId,
8637 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8638 "user=" + defaultNetworkType);
8639 phone.loadAllowedNetworksFromSubscriptionDatabase();
8640 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8641 defaultNetworkType, null);
8642 }
8643
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008644 private void cleanUpSmsRawTable(Context context) {
8645 ContentResolver resolver = context.getContentResolver();
8646 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8647 resolver.delete(uri, null, null);
8648 }
8649
Narayan Kamath1c496c22015-04-16 14:40:19 +01008650 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008651 public String getSimLocaleForSubscriber(int subId) {
8652 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008653
8654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8655 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8656
chen xu5d3637b2019-01-21 23:31:38 -08008657 final Phone phone = getPhone(subId);
8658 if (phone == null) {
8659 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008660 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008662 final long identity = Binder.clearCallingIdentity();
8663 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008664 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8665 phone.getContext().getOpPackageName(),
8666 phone.getContext().getAttributionTag());
8667 if (info == null) {
8668 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8669 return null;
chen xu6291c472019-02-04 12:55:53 -08008670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 // Try and fetch the locale from the carrier properties or from the SIM language
8672 // preferences (EF-PL and EF-LI)...
8673 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008674 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008675 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8676 if (localeFromDefaultSim != null) {
8677 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8678 if (DBG) log("Using locale from subId: " + subId + " locale: "
8679 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008680 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008681 } else {
8682 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 }
8684 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008686 // The SIM language preferences only store a language (e.g. fr = French), not an
8687 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8688 // the SIM and carrier preferences does not include a country we add the country
8689 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008690 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008692 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008693 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008694 }
8695
8696 if (DBG) log("No locale found - returning null");
8697 return null;
8698 } finally {
8699 Binder.restoreCallingIdentity(identity);
8700 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008701 }
8702
tom hsu0b59d292022-09-29 23:49:21 +08008703 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008704 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008705 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008706 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008707 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008708 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8709 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008710 Locale.forLanguageTag(localeTag).getCountry())) {
8711 return localeTag;
8712 }
8713 }
8714 return inputLocale.toLanguageTag();
8715 }
8716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008717 /**
8718 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8719 */
8720 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008721 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008722 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008723 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008724
Gary Jian3aa9a762022-01-24 16:41:19 +08008725 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8726 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008727
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008728 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008729 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8730 * representing the state of the modem.
8731 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008732 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8733 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008734 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008735 */
8736 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008737 public void requestModemActivityInfo(ResultReceiver result) {
8738 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008739
8740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8741 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8742
vagdeviaf9a5b92018-08-15 16:01:53 -07008743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008744
8745 final long identity = Binder.clearCallingIdentity();
8746 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008747 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008748 } finally {
8749 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008750 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008751 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008752
Gary Jian76280a42022-12-07 16:18:33 +08008753 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008754 // less than total activity duration.
8755 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8756 if (info == null) {
8757 return false;
8758 }
8759 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008760 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008761 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8762
Hall Liu49656c02020-10-09 19:00:11 -07008763 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8764
Siddharth Rayb8114062018-06-17 15:02:38 -07008765 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008766 && (info.getSleepTimeMillis() <= activityDurationMs)
8767 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008768 }
8769
Gary Jian3aa9a762022-01-24 16:41:19 +08008770 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8771 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8772 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8773 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8774
8775 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8776 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8777 }
8778
8779 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8780 mLastModemActivityInfo.setReceiveTimeMillis(
8781 rat,
8782 freq,
8783 info.getReceiveTimeMillis(rat, freq)
8784 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8785 }
8786
8787 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8788 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8789 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8790 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8791
8792 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8793 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8794 }
8795 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8796 mLastModemActivityInfo.setReceiveTimeMillis(
8797 rat,
8798 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8799 }
8800
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008801 /**
8802 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8803 * @param info recent ModemActivityInfo
8804 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008805 private void mergeModemActivityInfo(ModemActivityInfo info) {
8806 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008807 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008808 boolean matched;
8809 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8810 matched = false;
8811 int rat = info.getSpecificInfoRat(i);
8812 int freq = info.getSpecificInfoFrequencyRange(i);
8813 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8814 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8815 //if it already exists
8816 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8817 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8818 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8819 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8820 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8821 updateLastModemActivityInfo(info, rat, freq);
8822 matched = true;
8823 }
8824 } else {
8825 updateLastModemActivityInfo(info, rat);
8826 matched = true;
8827 }
8828 }
8829 }
8830
8831 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008832 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008833 new ActivityStatsTechSpecificInfo(
8834 rat,
8835 freq,
8836 info.getTransmitTimeMillis(rat, freq),
8837 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008838 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008839 }
8840 }
8841 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8842 mLastModemActivitySpecificInfo =
8843 new ActivityStatsTechSpecificInfo[merged.size()];
8844 merged.toArray(mLastModemActivitySpecificInfo);
8845
8846 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8847 mLastModemActivityInfo.setSleepTimeMillis(
8848 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008849 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008850 mLastModemActivityInfo.setIdleTimeMillis(
8851 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008852 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008853
8854 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008855 new ModemActivityInfo(
8856 mLastModemActivityInfo.getTimestampMillis(),
8857 mLastModemActivityInfo.getSleepTimeMillis(),
8858 mLastModemActivityInfo.getIdleTimeMillis(),
8859 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008860 }
8861
8862 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8863 ActivityStatsTechSpecificInfo[] info) {
8864 int infoSize = info.length;
8865 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8866 for (int i = 0; i < infoSize; i++) {
8867 ret[i] = new ActivityStatsTechSpecificInfo(
8868 info[i].getRat(), info[i].getFrequencyRange(),
8869 info[i].getTransmitTimeMillis(),
8870 (int) info[i].getReceiveTimeMillis());
8871 }
8872 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008873 }
8874
Jack Yu85bd38a2015-11-09 11:34:32 -08008875 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008876 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008877 */
8878 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008879 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8880 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8881 Phone phone = PhoneFactory.getPhone(slotIndex);
8882 if (phone == null) {
8883 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8884 return null;
8885 }
8886
8887 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008890 return null;
8891 }
8892
joonhunshin4ac60942023-11-15 15:23:39 +00008893 enforceTelephonyFeatureWithException(callingPackage,
8894 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8895
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008896 boolean hasFinePermission = false;
8897 boolean hasCoarsePermission = false;
8898 if (!renounceFineLocationAccess) {
8899 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8900 LocationAccessPolicy.checkLocationPermission(mApp,
8901 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8902 .setCallingPackage(callingPackage)
8903 .setCallingFeatureId(callingFeatureId)
8904 .setCallingPid(Binder.getCallingPid())
8905 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008906 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008907 .setLogAsInfo(true)
8908 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8910 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8911 .build());
8912 hasFinePermission =
8913 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8914 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008915
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008916 if (!renounceCoarseLocationAccess) {
8917 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8918 LocationAccessPolicy.checkLocationPermission(mApp,
8919 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8920 .setCallingPackage(callingPackage)
8921 .setCallingFeatureId(callingFeatureId)
8922 .setCallingPid(Binder.getCallingPid())
8923 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008924 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008925 .setLogAsInfo(true)
8926 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8927 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8928 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8929 .build());
8930 hasCoarsePermission =
8931 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8932 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008933
Jordan Liu0f2bc442020-11-18 16:47:37 -08008934 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008936 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8937 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008938 if (subInfo != null && !subInfo.isActive()) {
8939 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008940 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008941 }
8942
Hall Liuf19c44f2018-11-27 14:38:17 -08008943 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008944 boolean isCallingPackageDataService = phone.getDataServicePackages()
8945 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008946
8947 // Scrub out the location info in ServiceState depending on what level of access
8948 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008949 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008950 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8951 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008956
8957 /**
8958 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8959 *
8960 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8961 * voicemail ringtone.
8962 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8963 * PhoneAccount.
8964 */
8965 @Override
8966 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8968 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970 final long identity = Binder.clearCallingIdentity();
8971 try {
8972 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8973 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008974 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8978 } finally {
8979 Binder.restoreCallingIdentity(identity);
8980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008981 }
8982
8983 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008984 * Sets the per-account voicemail ringtone.
8985 *
8986 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8987 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8988 *
8989 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8990 * voicemail ringtone.
8991 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8992 * PhoneAccount.
8993 */
8994 @Override
8995 public void setVoicemailRingtoneUri(String callingPackage,
8996 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008997 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008999 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9000 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9002 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9003 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005
joonhunshin4ac60942023-11-15 15:23:39 +00009006 enforceTelephonyFeatureWithException(callingPackage,
9007 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 }
9015 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009019 }
9020
9021 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009022 * Returns whether vibration is set for voicemail notification in Phone settings.
9023 *
9024 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9025 * voicemail vibration setting.
9026 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9027 */
9028 @Override
9029 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9031 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9036 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009037 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009044 }
9045
Youhan Wange64578a2016-05-02 15:32:42 -07009046 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009047 * Sets the per-account voicemail vibration.
9048 *
9049 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9050 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9051 *
9052 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9053 * voicemail vibration setting.
9054 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9055 * specific PhoneAccount.
9056 */
9057 @Override
9058 public void setVoicemailVibrationEnabled(String callingPackage,
9059 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009060 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009061 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009062 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9063 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9065 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9066 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009067 }
9068
joonhunshin4ac60942023-11-15 15:23:39 +00009069 enforceTelephonyFeatureWithException(callingPackage,
9070 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9075 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009076 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077 }
9078 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009081 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009082 }
9083
9084 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009085 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9086 *
9087 * @throws SecurityException if the caller does not have the required permission
9088 */
arunvoddud7401012022-12-15 16:08:12 +00009089 @VisibleForTesting
9090 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009092 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009093 }
9094
9095 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009096 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9097 * permission.
9098 *
9099 * @throws SecurityException if the caller does not have the required permission
9100 */
9101 private void enforceSendSmsPermission() {
9102 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9103 }
9104
9105 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009106 * Make sure either called from same process as self (phone) or IPC caller has interact across
9107 * users permission.
9108 *
9109 * @throws SecurityException if the caller does not have the required permission
9110 */
9111 private void enforceInteractAcrossUsersPermission(String message) {
9112 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9113 }
9114
9115 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009116 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009117 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009118 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009119 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009120 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009124 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125 if (componentName == null) {
9126 throw new SecurityException(
9127 "Caller not current active visual voicemail package[null]");
9128 }
9129 String vvmPackage = componentName.getPackageName();
9130 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009131 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132 }
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009135 }
9136 }
9137
9138 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009139 * Return the application ID for the app type.
9140 *
9141 * @param subId the subscription ID that this request applies to.
9142 * @param appType the uicc app type.
9143 * @return Application ID for specificied app type, or null if no uicc.
9144 */
9145 @Override
9146 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009147 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009148
9149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9150 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9151
Youhan Wange64578a2016-05-02 15:32:42 -07009152 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153
9154 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009155 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156 if (phone == null) {
9157 return null;
9158 }
9159 String aid = null;
9160 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009161 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009162 .getApplicationByType(appType).getAid();
9163 } catch (Exception e) {
9164 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9165 }
9166 return aid;
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009169 }
Youhan Wange64578a2016-05-02 15:32:42 -07009170 }
9171
Youhan Wang4001d252016-05-11 10:29:41 -07009172 /**
9173 * Return the Electronic Serial Number.
9174 *
9175 * @param subId the subscription ID that this request applies to.
9176 * @return ESN or null if error.
9177 */
9178 @Override
9179 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009180 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009181 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182
9183 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009184 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 if (phone == null) {
9186 return null;
9187 }
9188 String esn = null;
9189 try {
9190 esn = phone.getEsn();
9191 } catch (Exception e) {
9192 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9193 }
9194 return esn;
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009197 }
Youhan Wang4001d252016-05-11 10:29:41 -07009198 }
9199
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009200 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009201 * Return the Preferred Roaming List Version.
9202 *
9203 * @param subId the subscription ID that this request applies to.
9204 * @return PRLVersion or null if error.
9205 */
9206 @Override
9207 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009208 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009209
9210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9211 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9212
Youhan Wang66ad5d72016-07-18 17:56:58 -07009213 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009214
9215 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009216 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009217 if (phone == null) {
9218 return null;
9219 }
9220 String cdmaPrlVersion = null;
9221 try {
9222 cdmaPrlVersion = phone.getCdmaPrlVersion();
9223 } catch (Exception e) {
9224 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9225 }
9226 return cdmaPrlVersion;
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009229 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009230 }
9231
9232 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009233 * Get snapshot of Telephony histograms
9234 * @return List of Telephony histograms
9235 * @hide
9236 */
9237 @Override
9238 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9240 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009241
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 return RIL.getTelephonyRILTimingHistograms();
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009248 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009249
9250 /**
9251 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009252 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9253 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009254 * Require system privileges. In the future we may add this to carrier APIs.
9255 *
Michele Berionne482f8202018-11-27 18:57:59 -08009256 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009257 */
9258 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009259 @TelephonyManager.SetCarrierRestrictionResult
9260 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009261 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009262
9263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9264 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9265
vagdeviaf9a5b92018-08-15 16:01:53 -07009266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009267
Michele Berionne482f8202018-11-27 18:57:59 -08009268 if (carrierRestrictionRules == null) {
9269 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009270 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009272 final long identity = Binder.clearCallingIdentity();
9273 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009274 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009275 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009279 }
9280
9281 /**
9282 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009283 * Get the allowed carrier list and the excluded carrier list, including the priority between
9284 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009285 * Require system privileges. In the future we may add this to carrier APIs.
9286 *
Michele Berionne482f8202018-11-27 18:57:59 -08009287 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009288 */
9289 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009290 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009291 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009292
9293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9294 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9295
vagdeviaf9a5b92018-08-15 16:01:53 -07009296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009297
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009300 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9301 if (response instanceof CarrierRestrictionRules) {
9302 return (CarrierRestrictionRules) response;
9303 }
9304 // Response is an Exception of some kind,
9305 // which is signalled to the user as a NULL retval
9306 return null;
9307 } catch (Exception e) {
9308 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9309 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009313 }
9314
fionaxu59545b42016-05-25 15:53:37 -07009315 /**
arunvoddud7401012022-12-15 16:08:12 +00009316 * Fetches the carrier restriction status of the device and sends the status to the caller
9317 * through the callback.
9318 *
9319 * @param callback The callback that will be used to send the result.
9320 * @throws SecurityException if the caller does not have the required permission/privileges or
9321 * the caller is not allowlisted.
9322 */
9323 @Override
9324 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9325 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009326
9327 enforceTelephonyFeatureWithException(packageName,
9328 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9329
Steve Statia28b7cb32024-03-11 23:58:50 +00009330 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9331 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009332 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9333 throw new SecurityException("Not an authorized caller");
9334 }
9335 final long identity = Binder.clearCallingIdentity();
9336 try {
9337 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009338 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009339 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 }
9344
arunvoddu567f2b42023-04-25 17:22:00 +00009345 @Override
9346 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9347 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9348 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9349 return allowListInfo.getShaIdList(pkgName, carrierId);
9350 }
9351
arunvoddud7401012022-12-15 16:08:12 +00009352 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009353 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009354 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009355 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009356 }
9357
9358 /**
fionaxu59545b42016-05-25 15:53:37 -07009359 * Action set from carrier signalling broadcast receivers to enable/disable radio
9360 * @param subId the subscription ID that this action applies to.
9361 * @param enabled control enable or disable radio.
9362 * {@hide}
9363 */
9364 @Override
9365 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9366 enforceModifyPermission();
9367 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009368
9369 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009370 if (phone == null) {
9371 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9372 return;
9373 }
9374 try {
9375 phone.carrierActionSetRadioEnabled(enabled);
9376 } catch (Exception e) {
9377 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009378 } finally {
9379 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009380 }
9381 }
9382
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009383 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009384 * Enable or disable Voice over NR (VoNR)
9385 * @param subId the subscription ID that this action applies to.
9386 * @param enabled enable or disable VoNR.
9387 * @return operation result.
9388 */
9389 @Override
9390 public int setVoNrEnabled(int subId, boolean enabled) {
9391 enforceModifyPermission();
9392 final Phone phone = getPhone(subId);
9393
9394 final long identity = Binder.clearCallingIdentity();
9395 if (phone == null) {
9396 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9397 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9398 }
9399
9400 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9401 try {
9402 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9403 workSource);
9404 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009405
9406 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9407 if (DBG) {
9408 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9409 }
9410 SubscriptionManager.setSubscriptionProperty(
9411 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9412 (enabled ? "1" : "0"));
9413 }
9414
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009415 return result;
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
9421 /**
9422 * Is voice over NR enabled
9423 * @return true if VoNR is enabled else false
9424 */
9425 @Override
9426 public boolean isVoNrEnabled(int subId) {
9427 enforceReadPrivilegedPermission("isVoNrEnabled");
9428 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
9431 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9432 null, subId, workSource);
9433 if (DBG) log("isVoNrEnabled: " + isEnabled);
9434 return isEnabled;
9435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 }
9439
9440 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009441 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9442 * network status based on which carrier apps could apply actions accordingly,
9443 * enable/disable default url handler for example.
9444 *
9445 * @param subId the subscription ID that this action applies to.
9446 * @param report control start/stop reporting the default network status.
9447 * {@hide}
9448 */
9449 @Override
9450 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9451 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009452
9453 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9454 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9455 "carrierActionReportDefaultNetworkStatus");
9456
fionaxu8da9cb12017-05-23 15:02:46 -07009457 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009458
9459 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009460 if (phone == null) {
9461 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9462 return;
9463 }
9464 try {
9465 phone.carrierActionReportDefaultNetworkStatus(report);
9466 } catch (Exception e) {
9467 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468 } finally {
9469 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009470 }
9471 }
9472
9473 /**
fionaxud9622282017-07-17 17:51:30 -07009474 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9475 * @param subId the subscription ID that this action applies to.
9476 * {@hide}
9477 */
9478 @Override
9479 public void carrierActionResetAll(int subId) {
9480 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009481
9482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9483 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9484
fionaxud9622282017-07-17 17:51:30 -07009485 final Phone phone = getPhone(subId);
9486 if (phone == null) {
9487 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9488 return;
9489 }
9490 try {
9491 phone.carrierActionResetAll();
9492 } catch (Exception e) {
9493 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9494 }
9495 }
9496
9497 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009498 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9499 * bug report is being generated.
9500 */
9501 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009502 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009503 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9504 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009505 writer.println("Permission Denial: can't dump Phone from pid="
9506 + Binder.getCallingPid()
9507 + ", uid=" + Binder.getCallingUid()
9508 + "without permission "
9509 + android.Manifest.permission.DUMP);
9510 return;
9511 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009512 try {
9513 DumpsysHandler.dump(mApp, fd, writer, args);
9514 } catch (Exception e) {
9515 writer.println("Failed to dump phone information: " + e);
9516 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009517 }
Jack Yueb89b242016-06-22 13:27:47 -07009518
Brad Ebingerdac2f002018-04-03 15:17:52 -07009519 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009520 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9521 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9522 @NonNull String[] args) {
9523 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9524 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009525 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009526 }
9527
Jack Yueb89b242016-06-22 13:27:47 -07009528 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009529 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009530 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009531 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009532 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009533 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009534 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009535 */
9536 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009537 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009538 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009539 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9540 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9541 try {
9542 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009543 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009544 } catch (SecurityException se) {
9545 enforceModifyPermission();
9546 }
9547 } else {
9548 enforceModifyPermission();
9549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009550
joonhunshin4ac60942023-11-15 15:23:39 +00009551 enforceTelephonyFeatureWithException(callingPackage,
9552 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9553
Nate Myren116695d2024-02-09 09:36:01 -08009554 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009555 final long identity = Binder.clearCallingIdentity();
9556 try {
Nate Myren116695d2024-02-09 09:36:01 -08009557 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9558 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009559 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009560 callingUid, callingPackage, null, null);
9561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009562 Phone phone = getPhone(subId);
9563 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009564 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9565 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009566 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009567 phone.getDataSettingsManager().setDataEnabled(
9568 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009570 }
9571 } finally {
9572 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009573 }
9574 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009575
9576 /**
9577 * Get Client request stats
9578 * @return List of Client Request Stats
9579 * @hide
9580 */
9581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009582 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9583 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009585 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009586 return null;
9587 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009588 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 if (phone != null) {
9593 return phone.getClientRequestStats();
9594 }
9595
9596 return null;
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009600 }
9601
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009602 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009603 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009604 if (uid == Process.ROOT_UID && packageName == null) {
9605 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9606 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9607 // exception. ROOT_UID seems not to have a valid package name returned by
9608 // PackageManager, so just fake it here to avoid issues when running telephony shell
9609 // commands that plumb through the RIL as root, like so:
9610 // $ adb root
9611 // $ adb shell cmd phone ...
9612 packageName = "root";
9613 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009614 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009615 }
Jack Yueb4124c2017-02-16 15:32:43 -08009616
9617 /**
Grace Chen70990072017-03-24 17:21:30 -07009618 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009619 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009620 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009621 * @param state State of SIM (power down, power up, pass through)
9622 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9623 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9624 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009625 *
9626 **/
9627 @Override
Grace Chen70990072017-03-24 17:21:30 -07009628 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009629 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009630
9631 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9632 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9633
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009634 Phone phone = PhoneFactory.getPhone(slotIndex);
9635
vagdeviaf9a5b92018-08-15 16:01:53 -07009636 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009641 phone.setSimPowerState(state, null, workSource);
9642 }
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
9648 /**
9649 * Set SIM card power state.
9650 *
9651 * @param slotIndex SIM slot id.
9652 * @param state State of SIM (power down, power up, pass through)
9653 * @param callback callback to trigger after success or failure
9654 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9655 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9656 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9657 *
9658 **/
9659 @Override
9660 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9661 IIntegerConsumer callback) {
9662 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009663
9664 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9665 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9666 "setSimPowerStateForSlotWithCallback");
9667
Jordan Liu109698e2020-11-24 14:50:34 -08009668 Phone phone = PhoneFactory.getPhone(slotIndex);
9669
9670 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9671
9672 final long identity = Binder.clearCallingIdentity();
9673 try {
9674 if (phone != null) {
9675 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9676 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009677 }
9678 } finally {
9679 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009680 }
9681 }
Shuo Qiandd210312017-04-12 22:11:33 +00009682
Tyler Gunn65d45c22017-06-05 11:22:26 -07009683 private boolean isUssdApiAllowed(int subId) {
9684 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009685 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009686 if (configManager == null) {
9687 return false;
9688 }
9689 PersistableBundle pb = configManager.getConfigForSubId(subId);
9690 if (pb == null) {
9691 return false;
9692 }
9693 return pb.getBoolean(
9694 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9695 }
9696
Shuo Qiandd210312017-04-12 22:11:33 +00009697 /**
Ling Mac28f0212023-03-24 16:07:15 -07009698 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009699 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009700 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009701 */
goneil9c5f4872017-12-05 14:07:56 -08009702 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009703 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009704 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009705
9706 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9707 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009709 final long identity = Binder.clearCallingIdentity();
9710 try {
Ling Mac28f0212023-03-24 16:07:15 -07009711 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009712 } finally {
9713 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009714 }
9715 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009716
9717 /**
9718 * Get the current signal strength information for the given subscription.
9719 * Because this information is not updated when the device is in a low power state
9720 * it should not be relied-upon to be current.
9721 * @param subId Subscription index
9722 * @return the most recent cached signal strength info from the modem
9723 */
9724 @Override
9725 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009726 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9727 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009729 final long identity = Binder.clearCallingIdentity();
9730 try {
9731 Phone p = getPhone(subId);
9732 if (p == null) {
9733 return null;
9734 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009736 return p.getSignalStrength();
9737 } finally {
9738 Binder.restoreCallingIdentity(identity);
9739 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009740 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009741
Pengquan Meng77b7f132018-08-22 14:49:57 -07009742 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009743 * Get the current modem radio state for the given slot.
9744 * @param slotIndex slot index.
9745 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009746 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009747 * @return the current radio power state from the modem
9748 */
9749 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009750 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009751 Phone phone = PhoneFactory.getPhone(slotIndex);
9752 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9754 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009755 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9756 }
9757
joonhunshin4ac60942023-11-15 15:23:39 +00009758 enforceTelephonyFeatureWithException(callingPackage,
9759 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9760
Chen Xuf792fd62018-10-17 17:54:36 +00009761 final long identity = Binder.clearCallingIdentity();
9762 try {
9763 return phone.getRadioPowerState();
9764 } finally {
9765 Binder.restoreCallingIdentity(identity);
9766 }
9767 }
9768 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9769 }
9770
9771 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009772 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9773 *
9774 * <p>Requires one of the following permissions:
9775 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009776 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009777 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9778 * privileges.
9779 *
9780 * @param subId subscription id
9781 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9782 * {@code false}.
9783 */
9784 @Override
9785 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009786 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009787 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009788 try {
9789 mApp.enforceCallingOrSelfPermission(
9790 android.Manifest.permission.ACCESS_NETWORK_STATE,
9791 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009792 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009793 mApp.enforceCallingOrSelfPermission(
9794 permission.READ_BASIC_PHONE_STATE, functionName);
9795 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009796 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009797 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009798 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009799 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009800
joonhunshin4ac60942023-11-15 15:23:39 +00009801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9802 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9803
Pengquan Menga1bb6272018-09-06 09:59:22 -07009804 boolean isEnabled = false;
9805 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009806 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009807 Phone phone = getPhone(subId);
9808 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009809 } finally {
9810 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009811 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009812 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009813 }
9814
9815
9816 /**
9817 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9818 *
9819 * <p> Requires permission:
9820 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9821 * privileges.
9822 *
9823 * @param subId subscription id
9824 * @param isEnabled {@code true} means enable, {@code false} means disable.
9825 */
9826 @Override
9827 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9829 mApp, subId, "setDataRoamingEnabled");
9830
joonhunshin4ac60942023-11-15 15:23:39 +00009831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9832 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9833
Pengquan Menga1bb6272018-09-06 09:59:22 -07009834 final long identity = Binder.clearCallingIdentity();
9835 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009836 Phone phone = getPhone(subId);
9837 if (phone != null) {
9838 phone.setDataRoamingEnabled(isEnabled);
9839 }
9840 } finally {
9841 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009842 }
9843 }
9844
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009845 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009846 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009847 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009848 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009849 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009850
joonhunshin4ac60942023-11-15 15:23:39 +00009851 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9852 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9853
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009854 boolean isAllowed = true;
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009857 Phone phone = getPhone(subId);
9858 if (phone != null) {
9859 isAllowed = phone.isCspPlmnEnabled();
9860 }
9861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 return isAllowed;
9865 }
9866
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009867 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9868 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009869 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009870 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009871 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009872 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9873 if (phone == null) {
9874 return false;
9875 }
9876 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9877 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9878 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009879 }
9880
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009881 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009882 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009883 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009884 mApp.getSystemService(AppOpsManager.class)
9885 .checkPackage(Binder.getCallingUid(), callingPackage);
9886
Jordan Liu1e142fc2019-04-22 15:10:43 -07009887 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009888 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009889 try {
9890 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009891 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009892 } catch (SecurityException e) {
9893 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9894 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009895 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009896 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009897 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009898 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009899 }
joonhunshin4ac60942023-11-15 15:23:39 +00009900
9901 enforceTelephonyFeatureWithException(callingPackage,
9902 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9903
sandeepjsb6c87872021-09-27 15:34:44 +00009904 // checking compatibility, if calling app's target SDK is T and beyond.
9905 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9906 Binder.getCallingUid())) {
9907 isIccIdAccessRestricted = true;
9908 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009909 final long identity = Binder.clearCallingIdentity();
9910 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009911 UiccController uiccController = UiccController.getInstance();
9912 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009913 if (hasReadPermission) {
9914 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009915 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009916
9917 // Remove private info if the caller doesn't have access
9918 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9919 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009920 //setting the value after compatibility check
9921 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009922 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9923 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009924 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009925 if (card == null) {
9926 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009927 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009928 continue;
9929 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009930 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9931 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009932 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009933 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009934 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009935 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9936 for (UiccPortInfo portInfo : portInfos) {
9937 UiccPort port = uiccController.getUiccPortForSlot(
9938 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9939 if (port == null) {
9940 // assume no access if port is null
9941 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9942 continue;
9943 }
9944 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9945 uiccPortInfos.add(portInfo);
9946 } else {
9947 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9948 }
9949 }
9950 filteredInfos.add(new UiccCardInfo(
9951 cardInfo.isEuicc(),
9952 cardInfo.getCardId(),
9953 null,
9954 cardInfo.getPhysicalSlotIndex(),
9955 cardInfo.isRemovable(),
9956 cardInfo.isMultipleEnabledProfilesSupported(),
9957 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009958 }
9959 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 }
9964
sandeepjsb6c87872021-09-27 15:34:44 +00009965 /**
9966 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9967 * generally private and require carrier privileges to view.
9968 *
9969 * @hide
9970 */
9971 @NonNull
9972 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9973 List<UiccPortInfo> portinfo = new ArrayList<>();
9974 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9975 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9976 }
9977 return new UiccCardInfo(
9978 cardInfo.isEuicc(),
9979 cardInfo.getCardId(),
9980 null,
9981 cardInfo.getPhysicalSlotIndex(),
9982 cardInfo.isRemovable(),
9983 cardInfo.isMultipleEnabledProfilesSupported(),
9984 portinfo
9985 );
9986 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009987
sandeepjsb6c87872021-09-27 15:34:44 +00009988 /**
9989 * @hide
9990 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9991 * These values are generally private and require carrier privileges to view.
9992 */
9993 @NonNull
9994 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9995 return new UiccPortInfo(
9996 UiccPortInfo.ICCID_REDACTED,
9997 portInfo.getPortIndex(),
9998 portInfo.getLogicalSlotIndex(),
9999 portInfo.isActive()
10000 );
10001 }
10002 @Override
10003 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010004 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010005 mApp.getSystemService(AppOpsManager.class)
10006 .checkPackage(Binder.getCallingUid(), callingPackage);
10007
sandeepjsb6c87872021-09-27 15:34:44 +000010008 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010009
Aman Guptaf3c90b32022-03-17 04:54:16 +000010010 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10011 // we are reading iccId which is PII data.
10012 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010013
joonhunshin4ac60942023-11-15 15:23:39 +000010014 enforceTelephonyFeatureWithException(callingPackage,
10015 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10016
sandeepjsb6c87872021-09-27 15:34:44 +000010017 // checking compatibility, if calling app's target SDK is T and beyond.
10018 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10019 Binder.getCallingUid())) {
10020 isLogicalSlotAccessRestricted = true;
10021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010022 final long identity = Binder.clearCallingIdentity();
10023 try {
10024 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010025 if (slots == null || slots.length == 0) {
10026 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010027 return null;
10028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010029 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10030 for (int i = 0; i < slots.length; i++) {
10031 UiccSlot slot = slots[i];
10032 if (slot == null) {
10033 continue;
10034 }
10035
Jordan Liu7be7e652019-05-06 18:55:02 +000010036 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010037 UiccCard card = slot.getUiccCard();
10038 if (card != null) {
10039 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010040 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010041 cardId = slot.getEid();
10042 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010043 // If cardId is null, use iccId of default port as cardId.
10044 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010046 }
10047
Jordan Liu857451f2019-05-09 16:35:35 -070010048 if (cardId != null) {
10049 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10050 // if cardId is an EID, it's all digits so this is fine
10051 cardId = IccUtils.stripTrailingFs(cardId);
10052 }
10053
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010054 int cardState = 0;
10055 switch (slot.getCardState()) {
10056 case CARDSTATE_ABSENT:
10057 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10058 break;
10059 case CARDSTATE_PRESENT:
10060 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10061 break;
10062 case CARDSTATE_ERROR:
10063 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10064 break;
10065 case CARDSTATE_RESTRICTED:
10066 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10067 break;
10068 default:
10069 break;
10070
10071 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010072 List<UiccPortInfo> portInfos = new ArrayList<>();
10073 int[] portIndexes = slot.getPortList();
10074 for (int portIdx : portIndexes) {
10075 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010076 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010077 portInfos.add(new UiccPortInfo(iccId, portIdx,
10078 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010080 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010081 slot.isEuicc(),
10082 cardId,
10083 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010084 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010085 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010086 //setting the value after compatibility check
10087 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010088 }
10089 return infos;
10090 } finally {
10091 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010092 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010093 }
10094
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010095 /* Returns null if doesn't have read permission or carrier privilege access. */
10096 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10097 boolean hasReadPermission) {
10098 String iccId = slot.getIccId(portIndex);
10099 if (hasReadPermission) { // if has read permission
10100 return iccId;
10101 } else {
10102 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10103 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10104 // if no read permission, checking carrier privilege access
10105 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10106 return iccId;
10107 }
10108 }
10109 }
10110 // No read permission or carrier privilege access.
10111 return UiccPortInfo.ICCID_REDACTED;
10112 }
10113
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010114 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010115 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010116 public boolean switchSlots(int[] physicalSlots) {
10117 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010118
joonhunshin4ac60942023-11-15 15:23:39 +000010119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10120 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10121
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010122 final long identity = Binder.clearCallingIdentity();
10123 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010124 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10125 for (int i = 0; i < physicalSlots.length; i++) {
10126 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10127 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10128 physicalSlots[i], i));
10129 }
10130 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010131 } finally {
10132 Binder.restoreCallingIdentity(identity);
10133 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010134 }
Jack Yu4c988042018-02-27 15:30:01 -080010135
10136 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010137 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10138 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10139 enforceModifyPermission();
10140
joonhunshin4ac60942023-11-15 15:23:39 +000010141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10142 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10143
sandeepjsb6c87872021-09-27 15:34:44 +000010144 final long identity = Binder.clearCallingIdentity();
10145 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010146 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010147 } finally {
10148 Binder.restoreCallingIdentity(identity);
10149 }
10150 }
10151
10152 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010153 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010154 enforceTelephonyFeatureWithException(callingPackage,
10155 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10156
Jordan Liu7de49fa2018-12-06 14:48:49 -080010157 final long identity = Binder.clearCallingIdentity();
10158 try {
10159 return UiccController.getInstance().getCardIdForDefaultEuicc();
10160 } finally {
10161 Binder.restoreCallingIdentity(identity);
10162 }
10163 }
10164
Pengquan Meng85728fb2018-03-12 16:31:21 -070010165 /**
goneil47ffb6e2018-04-06 15:40:58 -070010166 * A test API to reload the UICC profile.
10167 *
10168 * <p>Requires that the calling app has permission
10169 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10170 * @hide
10171 */
10172 @Override
10173 public void refreshUiccProfile(int subId) {
10174 enforceModifyPermission();
10175
10176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 Phone phone = getPhone(subId);
10179 if (phone == null) {
10180 return;
10181 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010182 UiccPort uiccPort = phone.getUiccPort();
10183 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010184 return;
10185 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010186 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010187 if (uiccProfile == null) {
10188 return;
10189 }
10190 uiccProfile.refresh();
10191 } finally {
10192 Binder.restoreCallingIdentity(identity);
10193 }
10194 }
10195
10196 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010197 * Returns false if the mobile data is disabled by default, otherwise return true.
10198 */
10199 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010200 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010201 }
10202
10203 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010204 * Returns the default network type for the given {@code subId}, if the default network type is
10205 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10206 */
10207 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010208 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010209 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010210 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10211 return list.get(phoneId);
10212 }
10213 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010214 }
fionaxua13278b2018-03-21 00:08:13 -070010215
10216 @Override
10217 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010218 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010219 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010220
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 final Phone phone = getPhone(subId);
10224 if (phone == null) {
10225 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10226 return;
10227 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010228 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10229 if (cpt != null) {
10230 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10231 }
10232 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010233 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10234 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010235 if (carrierPrivilegeRules == null) {
10236 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10237 } else {
10238 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010240 } finally {
10241 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010242 }
fionaxua13278b2018-03-21 00:08:13 -070010243 }
10244
10245 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010246 public void setCarrierServicePackageOverride(
10247 int subId, String carrierServicePackage, String callingPackage) {
10248 TelephonyPermissions.enforceShellOnly(
10249 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10250
Benedict Wong66477622023-02-03 23:30:57 +000010251 final long identity = Binder.clearCallingIdentity();
10252 try {
10253 final Phone phone = getPhone(subId);
10254 if (phone == null || phone.getSubId() != subId) {
10255 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10256 throw new IllegalArgumentException("No phone for subid");
10257 }
10258 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10259 if (cpt == null) {
10260 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10261 throw new IllegalStateException("No CPT for phone");
10262 }
10263 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10264 } finally {
10265 Binder.restoreCallingIdentity(identity);
10266 }
10267 }
10268
10269 @Override
fionaxua13278b2018-03-21 00:08:13 -070010270 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010271 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010272
10273 final long identity = Binder.clearCallingIdentity();
10274 try {
10275 final Phone phone = getPhone(subId);
10276 if (phone == null) {
10277 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10278 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10279 }
10280 return phone.getCarrierIdListVersion();
10281 } finally {
10282 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010283 }
fionaxua13278b2018-03-21 00:08:13 -070010284 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010285
10286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010287 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10288 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010290 mApp, subId, callingPackage, callingFeatureId,
10291 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010292 return -1;
10293 }
10294
10295 final long identity = Binder.clearCallingIdentity();
10296 try {
10297 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10298 } finally {
10299 Binder.restoreCallingIdentity(identity);
10300 }
10301 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010302
10303 @Override
10304 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010305 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010306 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010307 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010308
joonhunshin4ac60942023-11-15 15:23:39 +000010309 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10310 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10311
Pengquan Menga1bb6272018-09-06 09:59:22 -070010312 final long identity = Binder.clearCallingIdentity();
10313 try {
10314 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10315 } finally {
10316 Binder.restoreCallingIdentity(identity);
10317 }
10318 }
10319
10320 @Override
10321 public boolean setCdmaRoamingMode(int subId, int mode) {
10322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10323 mApp, subId, "setCdmaRoamingMode");
10324
joonhunshin4ac60942023-11-15 15:23:39 +000010325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10326 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10327
Pengquan Menga1bb6272018-09-06 09:59:22 -070010328 final long identity = Binder.clearCallingIdentity();
10329 try {
10330 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
10336 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010337 public int getCdmaSubscriptionMode(int subId) {
10338 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010339 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010340 mApp, subId, "getCdmaSubscriptionMode");
10341
joonhunshin4ac60942023-11-15 15:23:39 +000010342 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10343 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10344
Sarah Chinbaab1432020-10-28 13:46:24 -070010345 final long identity = Binder.clearCallingIdentity();
10346 try {
10347 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351 }
10352
10353 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010354 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10356 mApp, subId, "setCdmaSubscriptionMode");
10357
joonhunshin4ac60942023-11-15 15:23:39 +000010358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10359 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10360
Pengquan Menga1bb6272018-09-06 09:59:22 -070010361 final long identity = Binder.clearCallingIdentity();
10362 try {
10363 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10364 } finally {
10365 Binder.restoreCallingIdentity(identity);
10366 }
10367 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010368
sqianc5eccab2018-10-19 18:46:41 -070010369 @Override
sqian8c685422019-02-22 15:55:18 -080010370 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010371 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010373 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10374 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010375 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10376 }
joonhunshin4ac60942023-11-15 15:23:39 +000010377
10378 enforceTelephonyFeatureWithException(callingPackage,
10379 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10380
sqian11b7a0e2018-12-05 18:48:28 -080010381 final long identity = Binder.clearCallingIdentity();
10382 try {
sqian854d44b2018-12-12 16:48:18 -080010383 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10384 for (Phone phone: PhoneFactory.getPhones()) {
10385 if (phone.getEmergencyNumberTracker() != null
10386 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10387 emergencyNumberListInternal.put(
10388 phone.getSubId(),
10389 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10390 }
sqian11b7a0e2018-12-05 18:48:28 -080010391 }
sqian854d44b2018-12-12 16:48:18 -080010392 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
sqianc5eccab2018-10-19 18:46:41 -070010396 }
10397
10398 @Override
sqian8c685422019-02-22 15:55:18 -080010399 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010400 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010401 if (!exactMatch) {
10402 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010403 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010404 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010405 }
joonhunshin4ac60942023-11-15 15:23:39 +000010406
10407 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10408 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10409
sqian11b7a0e2018-12-05 18:48:28 -080010410 final long identity = Binder.clearCallingIdentity();
10411 try {
sqian854d44b2018-12-12 16:48:18 -080010412 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010413 //Note: we ignore passed in param exactMatch. We can remove it once
10414 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010415 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010416 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010417 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010418 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010419 }
sqian11b7a0e2018-12-05 18:48:28 -080010420 }
10421 return false;
10422 } finally {
10423 Binder.restoreCallingIdentity(identity);
10424 }
10425 }
10426
sqianf4ca7ed2019-01-15 18:32:07 -080010427 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010428 * Start emergency callback mode for GsmCdmaPhone for testing.
10429 */
10430 @Override
10431 public void startEmergencyCallbackMode() {
10432 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10433 "startEmergencyCallbackMode");
10434 enforceModifyPermission();
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 for (Phone phone : PhoneFactory.getPhones()) {
10438 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10439 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10440 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10441 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10442 gsmCdmaPhone.obtainMessage(
10443 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10444 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10445 }
10446 }
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
10451
10452 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010453 * Update emergency number list for test mode.
10454 */
10455 @Override
10456 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10458 "updateEmergencyNumberListTestMode");
10459
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
10462 for (Phone phone: PhoneFactory.getPhones()) {
10463 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10464 if (tracker != null) {
10465 tracker.executeEmergencyNumberTestModeCommand(action, num);
10466 }
10467 }
10468 } finally {
10469 Binder.restoreCallingIdentity(identity);
10470 }
10471 }
10472
10473 /**
10474 * Get the full emergency number list for test mode.
10475 */
10476 @Override
10477 public List<String> getEmergencyNumberListTestMode() {
10478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10479 "getEmergencyNumberListTestMode");
10480
10481 final long identity = Binder.clearCallingIdentity();
10482 try {
10483 Set<String> emergencyNumbers = new HashSet<>();
10484 for (Phone phone: PhoneFactory.getPhones()) {
10485 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10486 if (tracker != null) {
10487 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10488 emergencyNumbers.add(num.getNumber());
10489 }
10490 }
10491 }
10492 return new ArrayList<>(emergencyNumbers);
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
chen xud6b45bd2018-10-30 22:27:10 -070010498 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010499 public int getEmergencyNumberDbVersion(int subId) {
10500 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10501
joonhunshin4ac60942023-11-15 15:23:39 +000010502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10503 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10504
Shuo Qian3b6ee772019-11-13 17:43:31 -080010505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 final Phone phone = getPhone(subId);
10508 if (phone == null) {
10509 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10510 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10511 }
10512 return phone.getEmergencyNumberDbVersion();
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 }
10517
10518 @Override
10519 public void notifyOtaEmergencyNumberDbInstalled() {
10520 enforceModifyPermission();
10521
joonhunshin4ac60942023-11-15 15:23:39 +000010522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10523 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10524
Shuo Qian3b6ee772019-11-13 17:43:31 -080010525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 for (Phone phone: PhoneFactory.getPhones()) {
10528 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10529 if (tracker != null) {
10530 tracker.updateOtaEmergencyNumberDatabase();
10531 }
10532 }
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
10537
10538 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010539 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010540 enforceActiveEmergencySessionPermission();
10541
joonhunshin4ac60942023-11-15 15:23:39 +000010542 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10543 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10544
Shuo Qian3b6ee772019-11-13 17:43:31 -080010545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 for (Phone phone: PhoneFactory.getPhones()) {
10548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10549 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010550 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10551 }
10552 }
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
10558 @Override
10559 public void resetOtaEmergencyNumberDbFilePath() {
10560 enforceActiveEmergencySessionPermission();
10561
joonhunshin4ac60942023-11-15 15:23:39 +000010562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10563 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10564
Shuo Qianc373f112020-03-05 17:55:34 -080010565 final long identity = Binder.clearCallingIdentity();
10566 try {
10567 for (Phone phone: PhoneFactory.getPhones()) {
10568 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10569 if (tracker != null) {
10570 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010571 }
10572 }
10573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 }
10577
10578 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010579 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10580 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10581 Phone phone = getPhone(subId);
10582 if (phone == null) {
10583 return null;
10584 }
10585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 UiccProfile profile = UiccController.getInstance()
10588 .getUiccProfileForPhone(phone.getPhoneId());
10589 if (profile != null) {
10590 return profile.getCertsFromCarrierPrivilegeAccessRules();
10591 }
10592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 return null;
10596 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010597
10598 /**
10599 * Enable or disable a modem stack.
10600 */
10601 @Override
10602 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10603 enforceModifyPermission();
10604
joonhunshin4ac60942023-11-15 15:23:39 +000010605 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10606 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10607
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010608 final long identity = Binder.clearCallingIdentity();
10609 try {
10610 Phone phone = PhoneFactory.getPhone(slotIndex);
10611 if (phone == null) {
10612 return false;
10613 } else {
10614 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10615 }
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
Michelecea4cf22018-12-21 15:00:11 -080010620
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010621 /**
10622 * Whether a modem stack is enabled or not.
10623 */
10624 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010625 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10626 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010627 Phone phone = PhoneFactory.getPhone(slotIndex);
10628 if (phone == null) return false;
10629
10630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010631 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10632 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010633 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10634 }
10635
joonhunshin4ac60942023-11-15 15:23:39 +000010636 enforceTelephonyFeatureWithException(callingPackage,
10637 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10638
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010639 final long identity = Binder.clearCallingIdentity();
10640 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010641 try {
10642 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10643 } catch (NoSuchElementException ex) {
10644 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10645 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
10650
Michelecea4cf22018-12-21 15:00:11 -080010651 @Override
Michele0ea7d782019-03-19 14:58:42 -070010652 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010653 enforceModifyPermission();
10654
joonhunshin4ac60942023-11-15 15:23:39 +000010655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10656 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10657
Michelecea4cf22018-12-21 15:00:11 -080010658 final long identity = Binder.clearCallingIdentity();
10659 try {
10660 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010661 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010662 .commit();
10663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
10668 @Override
Michele0ea7d782019-03-19 14:58:42 -070010669 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010670 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010672 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10673 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010674 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010675 }
Michelecea4cf22018-12-21 15:00:11 -080010676
joonhunshin4ac60942023-11-15 15:23:39 +000010677 enforceTelephonyFeatureWithException(callingPackage,
10678 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10679
Michelecea4cf22018-12-21 15:00:11 -080010680 final long identity = Binder.clearCallingIdentity();
10681 try {
Michele0ea7d782019-03-19 14:58:42 -070010682 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010683 } finally {
10684 Binder.restoreCallingIdentity(identity);
10685 }
10686 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010687
Michele0ea7d782019-03-19 14:58:42 -070010688 @TelephonyManager.IsMultiSimSupportedResult
10689 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010690 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10691 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10692 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010693 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10694 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010695 }
10696 // Check if the hardware supports multisim functionality. If usage of multisim is not
10697 // supported by the modem, indicate that it is restricted.
10698 PhoneCapability staticCapability =
10699 mPhoneConfigurationManager.getStaticPhoneCapability();
10700 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010701 loge("isMultiSimSupportedInternal: no static configuration available");
10702 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010703 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010704 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010705 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10706 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010707 }
10708 // Check if support of multiple SIMs is restricted by carrier
10709 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010710 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010711 }
10712
Michele0ea7d782019-03-19 14:58:42 -070010713 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010714 }
10715
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010716 /**
10717 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010718 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10719 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10720 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010721 * @param numOfSims number of active sims we want to switch to
10722 */
10723 @Override
10724 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010725 if (numOfSims == 1) {
10726 enforceModifyPermission();
10727 } else {
10728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10729 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10730 }
joonhunshin4ac60942023-11-15 15:23:39 +000010731
10732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10733 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10734
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010735 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010736
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010737 try {
Michele30b57b22019-03-01 12:01:14 -080010738 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010739 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010740 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10741 return;
10742 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010743 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
10748
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010749 @Override
10750 public boolean isApplicationOnUicc(int subId, int appType) {
10751 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010752
10753 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10754 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10755
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010756 Phone phone = getPhone(subId);
10757 if (phone == null) {
10758 return false;
10759 }
10760 final long identity = Binder.clearCallingIdentity();
10761 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010762 UiccPort uiccPort = phone.getUiccPort();
10763 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010764 return false;
10765 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010766 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010767 if (uiccProfile == null) {
10768 return false;
10769 }
10770 if (TelephonyManager.APPTYPE_SIM <= appType
10771 && appType <= TelephonyManager.APPTYPE_ISIM) {
10772 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10773 }
10774 return false;
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010780 /**
chen xub4baa772019-04-03 10:23:41 -070010781 * Get whether making changes to modem configurations will trigger reboot.
10782 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010783 */
10784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010785 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10786 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010788 mApp, subId, callingPackage, callingFeatureId,
10789 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010790 return false;
10791 }
joonhunshin4ac60942023-11-15 15:23:39 +000010792
10793 enforceTelephonyFeatureWithException(callingPackage,
10794 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10795 "doesSwitchMultiSimConfigTriggerReboot");
10796
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
Nathan Harold29f5f052019-02-15 13:41:57 -080010805 private void updateModemStateMetrics() {
10806 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10807 // TODO: check the state for each modem if the api is ready.
10808 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10809 }
10810
Pengquan Meng3889a572019-01-23 11:16:29 -080010811 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010812 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010813 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010814 // Verify that the callingPackage belongs to the calling UID
10815 mApp.getSystemService(AppOpsManager.class)
10816 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010817
10818 enforceTelephonyFeatureWithException(callingPackage,
10819 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10820
Pengquan Meng3889a572019-01-23 11:16:29 -080010821 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010822 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010823 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010824 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10825 if (slotInfos != null) {
10826 for (int i = 0; i < slotInfos.length; i++) {
10827 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10828 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10829 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10830 portInfo.getLogicalSlotIndex()));
10831 }
10832 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010833 }
10834 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010835 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010836 } finally {
10837 Binder.restoreCallingIdentity(identity);
10838 }
10839 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010840
10841 /**
10842 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010843 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010844 */
jimsunf9ec1622022-09-13 21:18:43 +080010845 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010846 @Override
10847 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010848 return getHalVersion(HAL_SERVICE_RADIO);
10849 }
10850
10851 /**
10852 * Get the HAL Version of a specific service
10853 */
10854 @Override
10855 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010856 Phone phone = getDefaultPhone();
10857 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010858 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010859 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10860 return hv.major * 100 + hv.minor;
10861 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010862
10863 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010864 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010865 *
10866 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010867 */
10868 @Override
sangyun097dcf72024-01-04 10:35:49 +090010869 public @Nullable String getCurrentPackageName() {
10870 PackageManager pm = mApp.getPackageManager();
10871 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10872 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010873 }
10874
10875 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010876 * @return The calling package name or "phone" if the caller is the phone process. This is done
10877 * because multiple Phone has multiple packages in it and the first element in the array is not
10878 * actually always the caller.
10879 * Note: This is for logging purposes only and should not be used for security checks.
10880 */
10881 private String getCurrentPackageNameOrPhone() {
10882 PackageManager pm = mApp.getPackageManager();
10883 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10884 if (uidName != null && !uidName.isEmpty()) return uidName;
10885 return getCurrentPackageName();
10886 }
10887
10888 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010889 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10890 * corresponding network requests on a subId.
10891 *
10892 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010893 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010894 * 2) APN is un-metered for this subscription, or
10895 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010896 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010897 *
10898 * @return whether data is allowed for a apn type.
10899 *
10900 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010901 */
10902 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010903 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010904 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10905 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010906
joonhunshin4ac60942023-11-15 15:23:39 +000010907 enforceTelephonyFeatureWithException(callingPackage,
10908 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10909
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010910 // Now that all security checks passes, perform the operation as ourselves.
10911 final long identity = Binder.clearCallingIdentity();
10912 try {
10913 Phone phone = getPhone(subId);
10914 if (phone == null) return false;
10915
Jack Yu27422a52022-03-21 10:38:05 -070010916 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010917 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010918 isMetered = phone.getDataNetworkController().getDataConfigManager()
10919 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10920 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010921 isDataEnabled = (phone.getDataSettingsManager() != null)
10922 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010923 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
10928
10929 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010930 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010931 enforceReadPrivilegedPermission("isApnMetered");
10932
joonhunshin4ac60942023-11-15 15:23:39 +000010933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10934 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10935
Malcolm Chene5ad5792019-04-18 13:51:02 -070010936 // Now that all security checks passes, perform the operation as ourselves.
10937 final long identity = Binder.clearCallingIdentity();
10938 try {
10939 Phone phone = getPhone(subId);
10940 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010941 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10942 DataUtils.apnTypeToNetworkCapability(apnType),
10943 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010948
10949 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010950 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10951 int subscriptionId, IBooleanConsumer resultCallback) {
10952 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010953
10954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10955 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10956
Hall Liu73f5d362020-01-20 13:42:00 -080010957 long token = Binder.clearCallingIdentity();
10958 try {
10959 Phone phone = getPhone(subscriptionId);
10960 if (phone == null) {
10961 try {
10962 if (resultCallback != null) {
10963 resultCallback.accept(false);
10964 }
10965 } catch (RemoteException e) {
10966 // ignore
10967 }
10968 return;
10969 }
10970 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10971 Pair.create(specifiers, (x) -> {
10972 try {
10973 if (resultCallback != null) {
10974 resultCallback.accept(x);
10975 }
10976 } catch (RemoteException e) {
10977 // ignore
10978 }
10979 });
10980 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10981 } finally {
10982 Binder.restoreCallingIdentity(token);
10983 }
10984 }
10985
10986 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010987 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10988 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010989 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010990 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010991
10992 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10993 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10994
Sarah Chin679c08a2020-11-18 13:39:35 -080010995 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10996 final long identity = Binder.clearCallingIdentity();
10997 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010998 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10999 if (result instanceof IllegalStateException) {
11000 throw (IllegalStateException) result;
11001 }
11002 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011003 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11004 return specifiers;
11005 } finally {
11006 Binder.restoreCallingIdentity(identity);
11007 }
11008 }
11009
11010 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011011 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011012 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011013
11014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11015 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11016
Jack Yu8b766fc2022-03-21 09:42:33 -070011017 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011018 }
11019
11020 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011021 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11022 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011023 if (callingPackage == null) {
11024 callingPackage = getCurrentPackageName();
11025 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011026 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11027 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011028 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11029 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011030 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11031 }
11032 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11033 Intent intent = new Intent();
11034 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11035 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11036 // Bring up choose default SMS subscription dialog right now
11037 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11038 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11039 mApp.startActivity(intent);
11040 }
chen xud5ca2d52019-05-28 15:20:57 -070011041
11042 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011043 public void showSwitchToManagedProfileDialog() {
11044 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011045 try {
11046 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11047 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11048 // for work telephony.
11049 Intent intent = new Intent(Intent.ACTION_SENDTO);
11050 intent.setData(Uri.parse("smsto:"));
11051 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11052 mApp.startActivity(intent);
11053 } catch (ActivityNotFoundException e) {
11054 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11055 Intent intent = new Intent();
11056 intent.setClass(mApp, ErrorDialogActivity.class);
11057 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11058 mApp.startActivity(intent);
11059 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011060 }
11061
11062 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011063 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011064 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11065 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11066
chen xud5ca2d52019-05-28 15:20:57 -070011067 //TODO investigate if this API should require proper permission check in R b/133791609
11068 final long identity = Binder.clearCallingIdentity();
11069 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011070 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11071 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11072 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11073 return carrierUAProfUrl;
11074 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011075 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11076 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011077 } finally {
11078 Binder.restoreCallingIdentity(identity);
11079 }
11080 }
11081
11082 @Override
11083 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011084 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11085 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11086
chen xud5ca2d52019-05-28 15:20:57 -070011087 //TODO investigate if this API should require proper permission check in R b/133791609
11088 final long identity = Binder.clearCallingIdentity();
11089 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011090 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11091 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11092 if (!TextUtils.isEmpty(carrierUserAgent)) {
11093 return carrierUserAgent;
11094 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011095 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11096 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011097 } finally {
11098 Binder.restoreCallingIdentity(identity);
11099 }
11100 }
Jack Yub07d4972019-05-28 16:12:25 -070011101
11102 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011103 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11104 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011105
joonhunshin4ac60942023-11-15 15:23:39 +000011106 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11107 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11108
Jack Yub07d4972019-05-28 16:12:25 -070011109 final long identity = Binder.clearCallingIdentity();
11110 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011111 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011112 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011113
Ling Maf188d502022-09-16 15:22:36 -070011114 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011115 } finally {
11116 Binder.restoreCallingIdentity(identity);
11117 }
11118 }
11119
11120 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011121 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011122 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011123 enforceModifyPermission();
11124
joonhunshin4ac60942023-11-15 15:23:39 +000011125 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11126 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11127
changbettyd5c246e2019-12-24 15:40:37 +080011128 final long identity = Binder.clearCallingIdentity();
11129 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011130 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011131 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011132
Ling Maf188d502022-09-16 15:22:36 -070011133 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011134 } finally {
11135 Binder.restoreCallingIdentity(identity);
11136 }
11137 }
11138
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011139 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011140 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011141 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11142 * otherwise.
11143 */
11144 @Override
11145 public void setCepEnabled(boolean isCepEnabled) {
11146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11147
11148 final long identity = Binder.clearCallingIdentity();
11149 try {
11150 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11151 for (Phone phone : PhoneFactory.getPhones()) {
11152 Phone defaultPhone = phone.getImsPhone();
11153 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11154 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11155 ImsPhoneCallTracker imsPhoneCallTracker =
11156 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11157 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11158 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11159 + imsPhone.getMsisdn());
11160 }
11161 }
11162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 }
allenwtsu46dcc572020-01-08 18:24:03 +080011166
11167 /**
11168 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11169 *
11170 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11171 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11172 * before being read.
11173 */
11174 @Override
11175 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11176 isCompressed) {
11177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11178 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011179 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11180 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11181 }
joonhunshin4ac60942023-11-15 15:23:39 +000011182
11183 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11184 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11185 Binder.getCallingUserHandle())) {
11186 if (!isImsAvailableOnDevice()) {
11187 // ProvisioningManager can not handle ServiceSpecificException.
11188 // Throw the IllegalStateException and annotate ProvisioningManager.
11189 throw new IllegalStateException("IMS not available on device.");
11190 }
11191 } else {
11192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11193 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11194 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011195 }
11196
11197 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011198 try {
Hui Wang761a6682020-10-31 05:12:53 +000011199 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11200 } finally {
11201 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011202 }
11203 }
zoey chene02881a2019-12-30 16:11:23 +080011204
11205 @Override
11206 public boolean isIccLockEnabled(int subId) {
11207 enforceReadPrivilegedPermission("isIccLockEnabled");
11208
joonhunshin4ac60942023-11-15 15:23:39 +000011209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11210 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11211
zoey chene02881a2019-12-30 16:11:23 +080011212 // Now that all security checks passes, perform the operation as ourselves.
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
11215 Phone phone = getPhone(subId);
11216 if (phone != null && phone.getIccCard() != null) {
11217 return phone.getIccCard().getIccLockEnabled();
11218 } else {
11219 return false;
11220 }
11221 } finally {
11222 Binder.restoreCallingIdentity(identity);
11223 }
11224 }
11225
11226 /**
11227 * Set the ICC pin lock enabled or disabled.
11228 *
11229 * @return an integer representing the status of IccLock enabled or disabled in the following
11230 * three cases:
11231 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11232 * successfully.
11233 * - Positive number and zero for remaining password attempts.
11234 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11235 *
11236 */
11237 @Override
11238 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11239 enforceModifyPermission();
11240
joonhunshin4ac60942023-11-15 15:23:39 +000011241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11242 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11243
zoey chene02881a2019-12-30 16:11:23 +080011244 Phone phone = getPhone(subId);
11245 if (phone == null) {
11246 return 0;
11247 }
11248 // Now that all security checks passes, perform the operation as ourselves.
11249 final long identity = Binder.clearCallingIdentity();
11250 try {
11251 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11252 new Pair<Boolean, String>(enabled, password), phone, null);
11253 return attemptsRemaining;
11254
11255 } catch (Exception e) {
11256 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11257 } finally {
11258 Binder.restoreCallingIdentity(identity);
11259 }
11260 return 0;
11261 }
11262
11263 /**
11264 * Change the ICC password used in ICC pin lock.
11265 *
11266 * @return an integer representing the status of IccLock changed in the following three cases:
11267 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11268 * - Positive number and zero for remaining password attempts.
11269 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11270 *
11271 */
11272 @Override
11273 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11274 enforceModifyPermission();
11275
joonhunshin4ac60942023-11-15 15:23:39 +000011276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11277 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11278
zoey chene02881a2019-12-30 16:11:23 +080011279 Phone phone = getPhone(subId);
11280 if (phone == null) {
11281 return 0;
11282 }
11283 // Now that all security checks passes, perform the operation as ourselves.
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11287 new Pair<String, String>(oldPassword, newPassword), phone, null);
11288 return attemptsRemaining;
11289
11290 } catch (Exception e) {
11291 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11292 } finally {
11293 Binder.restoreCallingIdentity(identity);
11294 }
11295 return 0;
11296 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011297
11298 /**
11299 * Request for receiving user activity notification
11300 */
11301 @Override
11302 public void requestUserActivityNotification() {
11303 if (!mNotifyUserActivity.get()
11304 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11305 mNotifyUserActivity.set(true);
11306 }
11307 }
11308
11309 /**
11310 * Called when userActivity is signalled in the power manager.
11311 * This is safe to call from any thread, with any window manager locks held or not.
11312 */
11313 @Override
11314 public void userActivity() {
11315 // ***************************************
11316 // * Inherited from PhoneWindowManager *
11317 // ***************************************
11318 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11319 // WITH ITS LOCKS HELD.
11320 //
11321 // This code must be VERY careful about the locks
11322 // it acquires.
11323 // In fact, the current code acquires way too many,
11324 // and probably has lurking deadlocks.
11325
11326 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11327 throw new SecurityException("Only the OS may call notifyUserActivity()");
11328 }
11329
11330 if (mNotifyUserActivity.getAndSet(false)) {
11331 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11332 USER_ACTIVITY_NOTIFICATION_DELAY);
11333 }
11334 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011335
11336 @Override
11337 public boolean canConnectTo5GInDsdsMode() {
11338 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11339 }
Jack Yud10cdd42020-09-28 20:28:01 -070011340
11341 @Override
11342 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11343 String callingFeatureId) {
11344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11345 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11346 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11347 }
11348
joonhunshin4ac60942023-11-15 15:23:39 +000011349 enforceTelephonyFeatureWithException(callingPackage,
11350 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11351
Jack Yud10cdd42020-09-28 20:28:01 -070011352 Phone phone = getPhone(subId);
11353 if (phone == null) {
11354 throw new RuntimeException("phone is not available");
11355 }
11356 // Now that all security checks passes, perform the operation as ourselves.
11357 final long identity = Binder.clearCallingIdentity();
11358 try {
11359 return phone.getEquivalentHomePlmns();
11360 } finally {
11361 Binder.restoreCallingIdentity(identity);
11362 }
11363 }
Daniel Bright59e67312020-11-13 11:49:37 -080011364
11365 @Override
11366 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011367 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011368 if (!mApp.getResources().getBoolean(
11369 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11370 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11371 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11372 "isRadioInterfaceCapabilitySupported");
11373 }
joonhunshin4ac60942023-11-15 15:23:39 +000011374
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011375 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011376 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011377 if (radioInterfaceCapabilities == null) {
11378 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011379 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011380 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011381 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011382
Hui Wang641e81c2020-10-12 12:14:23 -070011383 @Override
11384 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11385 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011386 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11387 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11388 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11389 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11390 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011391
11392 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11393 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11394
Hui Wang641e81c2020-10-12 12:14:23 -070011395 if (DBG) {
11396 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11397 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11398 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11399 }
11400
11401 if (!SubscriptionManager.isValidSubscriptionId(subId)
11402 || appType < TelephonyManager.APPTYPE_UNKNOWN
11403 || appType > TelephonyManager.APPTYPE_ISIM
11404 || nafUrl == null || securityProtocol == null || callback == null) {
11405 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11406 if (callback != null) {
11407 try {
11408 callback.onAuthenticationFailure(
11409 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11410 } catch (RemoteException exception) {
11411 log("Fail to notify onAuthenticationFailure due to " + exception);
11412 }
11413 return;
11414 }
11415 }
11416
11417 final long token = Binder.clearCallingIdentity();
11418 try {
11419 getGbaManager(subId).bootstrapAuthenticationRequest(
11420 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011421 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011422 } finally {
11423 Binder.restoreCallingIdentity(token);
11424 }
11425 }
11426
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011427 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011428 * Attempts to set the radio power state for all phones for thermal reason.
11429 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011430 * requested radio power state will actually be set. See {@link
11431 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11432 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011433 * @param enable {@code true} if trying to turn radio on.
11434 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11435 * false}.
11436 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011437 private boolean setRadioPowerForThermal(boolean enable) {
11438 boolean isPhoneAvailable = false;
11439 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11440 Phone phone = PhoneFactory.getPhone(i);
11441 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011442 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011443 isPhoneAvailable = true;
11444 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011445 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011446
11447 // return true if successfully informed the phone object about the thermal radio power
11448 // request.
11449 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011450 }
11451
11452 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011453 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011454 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11455 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11456 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11457 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11458 throw new IllegalArgumentException("modem does not support data throttling");
11459 }
11460
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011461 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11462 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011463 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011464 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11465 }
11466
Sarah Chinecc78c42022-03-31 21:16:48 -070011467 setDataEnabledForReason(
11468 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011469
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011470 if (isDataThrottlingSupported) {
11471 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011472 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011473 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11474 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11475 } else if (thermalMitigationResult
11476 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011477 log("Modem likely does not support data throttling on secondary carrier. Data " +
11478 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11479 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011480 }
11481 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011482 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011483
11484 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011485 }
11486
Jack Nudelman644b91a2021-03-12 14:09:48 -080011487 private static List<String> getThermalMitigationAllowlist(Context context) {
11488 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11489 for (String pckg : context.getResources()
11490 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11491 sThermalMitigationAllowlistedPackages.add(pckg);
11492 }
11493 }
11494
11495 return sThermalMitigationAllowlistedPackages;
11496 }
11497
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011498 private boolean isAnyPhoneInEmergencyState() {
11499 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11500 if (tm.isInEmergencyCall()) {
11501 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11502 return true;
11503 }
11504 for (Phone phone : PhoneFactory.getPhones()) {
11505 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11506 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011507 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11508 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011509 return true;
11510 }
11511 }
11512
11513 return false;
11514 }
11515
Jack Nudelman644b91a2021-03-12 14:09:48 -080011516 /**
11517 * Used by shell commands to add an authorized package name for thermal mitigation.
11518 * @param packageName name of package to be allowlisted
11519 * @param context
11520 */
11521 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11522 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11523 sThermalMitigationAllowlistedPackages.add(packageName);
11524 }
11525
11526 /**
11527 * Used by shell commands to remove an authorized package name for thermal mitigation.
11528 * @param packageName name of package to remove from allowlist
11529 * @param context
11530 */
11531 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11532 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11533 sThermalMitigationAllowlistedPackages.remove(packageName);
11534 }
11535
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011536 /**
11537 * Thermal mitigation request to control functionalities at modem.
11538 *
11539 * @param subId the id of the subscription.
11540 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011541 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011542 *
11543 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11544 */
11545 @Override
11546 @ThermalMitigationResult
11547 public int sendThermalMitigationRequest(
11548 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011549 ThermalMitigationRequest thermalMitigationRequest,
11550 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011551 enforceModifyPermission();
11552
Jack Nudelman644b91a2021-03-12 14:09:48 -080011553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011554
11555 enforceTelephonyFeatureWithException(callingPackage,
11556 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11557
Jack Nudelman644b91a2021-03-12 14:09:48 -080011558 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11559 .contains(callingPackage)) {
11560 throw new SecurityException("Calling package must be configured in the device config. "
11561 + "calling package: " + callingPackage);
11562 }
11563
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11565 final long identity = Binder.clearCallingIdentity();
11566
11567 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11568 try {
11569 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11570 switch (thermalMitigationAction) {
11571 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11572 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011573 handleDataThrottlingRequest(subId,
11574 thermalMitigationRequest.getDataThrottlingRequest(),
11575 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011576 break;
11577 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11578 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11579 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11580 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11581 }
11582
11583 // Ensure that radio is on. If not able to power on due to phone being
11584 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011585 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011586 thermalMitigationResult =
11587 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11588 break;
11589 }
11590
11591 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011592 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011593 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11594 break;
11595 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11596 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11597 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11598 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11599 }
11600
11601 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11602 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011603 Phone phone = getPhone(subId);
11604 if (phone == null) {
11605 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011606 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011607 break;
11608 }
11609
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011610 TelephonyConnectionService service =
11611 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011612 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011613 Log.e(LOG_TAG, "An emergency call is pending");
11614 thermalMitigationResult =
11615 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11616 break;
11617 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011618 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011619 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011620 break;
11621 }
11622 } else {
11623 thermalMitigationResult =
11624 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11625 break;
11626 }
11627
11628 // Turn radio off. If not able to power off due to phone being unavailable,
11629 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011630 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011631 thermalMitigationResult =
11632 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11633 break;
11634 }
11635 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011636 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011637 break;
11638 default:
11639 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11640 + "not exist. Requested action: " + thermalMitigationAction);
11641 }
11642 } catch (IllegalArgumentException e) {
11643 throw e;
11644 } catch (Exception e) {
11645 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11646 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11647 } finally {
11648 Binder.restoreCallingIdentity(identity);
11649 }
11650
11651 if (DBG) {
11652 log("thermalMitigationRequest returning with thermalMitigationResult: "
11653 + thermalMitigationResult);
11654 }
11655
11656 return thermalMitigationResult;
11657 }
Hui Wang641e81c2020-10-12 12:14:23 -070011658
11659 /**
11660 * Set the GbaService Package Name that Telephony will bind to.
11661 *
11662 * @param subId The sim that the GbaService is associated with.
11663 * @param packageName The name of the package to be replaced with.
11664 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11665 */
11666 @Override
11667 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11668 enforceModifyPermission();
11669
11670 final long identity = Binder.clearCallingIdentity();
11671 try {
11672 return getGbaManager(subId).overrideServicePackage(packageName);
11673 } finally {
11674 Binder.restoreCallingIdentity(identity);
11675 }
11676 }
11677
11678 /**
11679 * Return the package name of the currently bound GbaService.
11680 *
11681 * @param subId The sim that the GbaService is associated with.
11682 * @return the package name of the GbaService configuration, null if GBA is not supported.
11683 */
11684 @Override
11685 public String getBoundGbaService(int subId) {
11686 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11687
11688 final long identity = Binder.clearCallingIdentity();
11689 try {
11690 return getGbaManager(subId).getServicePackage();
11691 } finally {
11692 Binder.restoreCallingIdentity(identity);
11693 }
11694 }
11695
11696 /**
11697 * Set the release time for telephony to unbind GbaService.
11698 *
11699 * @param subId The sim that the GbaService is associated with.
11700 * @param interval The release time to unbind GbaService by millisecond.
11701 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11702 */
11703 @Override
11704 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11705 enforceModifyPermission();
11706
11707 final long identity = Binder.clearCallingIdentity();
11708 try {
11709 return getGbaManager(subId).overrideReleaseTime(interval);
11710 } finally {
11711 Binder.restoreCallingIdentity(identity);
11712 }
11713 }
11714
11715 /**
11716 * Return the release time for telephony to unbind GbaService.
11717 *
11718 * @param subId The sim that the GbaService is associated with.
11719 * @return The release time to unbind GbaService by millisecond.
11720 */
11721 @Override
11722 public int getGbaReleaseTime(int subId) {
11723 enforceReadPrivilegedPermission("getGbaReleaseTime");
11724
11725 final long identity = Binder.clearCallingIdentity();
11726 try {
11727 return getGbaManager(subId).getReleaseTime();
11728 } finally {
11729 Binder.restoreCallingIdentity(identity);
11730 }
11731 }
11732
11733 private GbaManager getGbaManager(int subId) {
11734 GbaManager instance = GbaManager.getInstance(subId);
11735 if (instance == null) {
11736 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11737 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11738 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11739 }
11740 return instance;
11741 }
Hui Wang761a6682020-10-31 05:12:53 +000011742
11743 /**
11744 * indicate whether the device and the carrier can support
11745 * RCS VoLTE single registration.
11746 */
11747 @Override
11748 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011749 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11750 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11751 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11752 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011753
11754 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11755 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11756 }
11757
11758 final long identity = Binder.clearCallingIdentity();
11759 try {
11760 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11761 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011762 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11763 if (isCapable != null) {
11764 return isCapable;
11765 }
Hui Wang761a6682020-10-31 05:12:53 +000011766 }
Hui Wang67af90e2021-06-04 16:57:15 -070011767 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11768 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011769 } finally {
11770 Binder.restoreCallingIdentity(identity);
11771 }
11772 }
11773
11774 /**
11775 * Register RCS provisioning callback.
11776 */
11777 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011778 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011779 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011780 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011781 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011782 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11783 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011784
11785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11787 }
joonhunshin4ac60942023-11-15 15:23:39 +000011788 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11789 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11790 Binder.getCallingUserHandle())) {
11791 if (!isImsAvailableOnDevice()) {
11792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11793 "IMS not available on device.");
11794 }
11795 } else {
11796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11797 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011798 }
11799
11800 final long identity = Binder.clearCallingIdentity();
11801 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011802 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011803 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011804 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11805 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011806 }
Hui Wang761a6682020-10-31 05:12:53 +000011807 } finally {
11808 Binder.restoreCallingIdentity(identity);
11809 }
11810 }
11811
11812 /**
11813 * Unregister RCS provisioning callback.
11814 */
11815 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011816 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011817 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011818 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011819 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011820 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11821 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011822
11823 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11824 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11825 }
joonhunshin4ac60942023-11-15 15:23:39 +000011826
11827 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11828 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11829 Binder.getCallingUserHandle())) {
11830 if (!isImsAvailableOnDevice()) {
11831 // operation failed silently
11832 Rlog.w(LOG_TAG, "IMS not available on device.");
11833 return;
11834 }
11835 } else {
11836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11837 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11838 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011839 }
11840
11841 final long identity = Binder.clearCallingIdentity();
11842 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011843 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011844 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011845 } finally {
11846 Binder.restoreCallingIdentity(identity);
11847 }
11848 }
11849
11850 /**
11851 * trigger RCS reconfiguration.
11852 */
11853 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011854 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11855 "triggerRcsReconfiguration",
11856 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011857
11858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11860 }
joonhunshin4ac60942023-11-15 15:23:39 +000011861 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11862 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11863 Binder.getCallingUserHandle())) {
11864 if (!isImsAvailableOnDevice()) {
11865 // ProvisioningManager can not handle ServiceSpecificException.
11866 // Throw the IllegalStateException and annotate ProvisioningManager.
11867 throw new IllegalStateException("IMS not available on device.");
11868 }
11869 } else {
11870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11871 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011872 }
11873
11874 final long identity = Binder.clearCallingIdentity();
11875 try {
11876 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11877 } finally {
11878 Binder.restoreCallingIdentity(identity);
11879 }
11880 }
11881
11882 /**
11883 * Provide the client configuration parameters of the RCS application.
11884 */
11885 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011886 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11887 "setRcsClientConfiguration",
11888 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011889
11890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11891 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11892 }
joonhunshin4ac60942023-11-15 15:23:39 +000011893 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11894 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11895 Binder.getCallingUserHandle())) {
11896 if (!isImsAvailableOnDevice()) {
11897 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11898 "IMS not available on device.");
11899 }
11900 } else {
11901 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11902 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011903 }
11904
11905 final long identity = Binder.clearCallingIdentity();
11906
11907 try {
11908 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11909 if (configBinder == null) {
11910 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011911 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11912 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011913 } else {
11914 configBinder.setRcsClientConfiguration(rcc);
11915 }
joonhunshin3e154242021-09-17 06:33:39 +000011916
11917 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11918 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011919 } catch (RemoteException e) {
11920 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011921 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11922 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011923 } finally {
11924 Binder.restoreCallingIdentity(identity);
11925 }
11926 }
11927
11928 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011929 * Enables or disables the test mode for RCS VoLTE single registration.
11930 */
11931 @Override
11932 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11934 "setRcsSingleRegistrationTestModeEnabled");
11935
11936 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11937 }
11938
11939 /**
11940 * Gets the test mode for RCS VoLTE single registration.
11941 */
11942 @Override
11943 public boolean getRcsSingleRegistrationTestModeEnabled() {
11944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11945 "getRcsSingleRegistrationTestModeEnabled");
11946
11947 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11948 }
11949
11950 /**
Hui Wang761a6682020-10-31 05:12:53 +000011951 * Overrides the config of RCS VoLTE single registration enabled for the device.
11952 */
11953 @Override
11954 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11956 "setDeviceSingleRegistrationEnabledOverride");
11957 enforceModifyPermission();
11958
11959 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11960 : Boolean.parseBoolean(enabledStr);
11961 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011962 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011963 }
11964
11965 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011966 * Sends a device to device communication message. Only usable via shell.
11967 * @param message message to send.
11968 * @param value message value.
11969 */
11970 @Override
11971 public void sendDeviceToDeviceMessage(int message, int value) {
11972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011973 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011974 enforceModifyPermission();
11975
11976 final long identity = Binder.clearCallingIdentity();
11977 try {
11978 TelephonyConnectionService service =
11979 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11980 if (service == null) {
11981 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11982 return;
11983 }
11984 service.sendTestDeviceToDeviceMessage(message, value);
11985 } finally {
11986 Binder.restoreCallingIdentity(identity);
11987 }
11988 }
11989
Tyler Gunnbabbda02021-02-10 11:05:02 -080011990 /**
11991 * Sets the specified device to device transport active.
11992 * @param transport The transport to set active.
11993 */
11994 @Override
11995 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11996 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11997 "setActiveDeviceToDeviceTransport");
11998 enforceModifyPermission();
11999
12000 final long identity = Binder.clearCallingIdentity();
12001 try {
12002 TelephonyConnectionService service =
12003 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12004 if (service == null) {
12005 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12006 return;
12007 }
12008 service.setActiveDeviceToDeviceTransport(transport);
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 }
Tyler Gunn92479152021-01-20 16:30:10 -080012013
Tyler Gunnd4339262021-05-03 14:46:49 -070012014 @Override
12015 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12017 "setDeviceToDeviceForceEnabled");
12018
12019 final long identity = Binder.clearCallingIdentity();
12020 try {
12021 Arrays.stream(PhoneFactory.getPhones()).forEach(
12022 p -> {
12023 Phone thePhone = p.getImsPhone();
12024 if (thePhone != null && thePhone instanceof ImsPhone) {
12025 ImsPhone imsPhone = (ImsPhone) thePhone;
12026 CallTracker tracker = imsPhone.getCallTracker();
12027 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12028 ImsPhoneCallTracker imsPhoneCallTracker =
12029 (ImsPhoneCallTracker) tracker;
12030 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12031 }
12032 }
12033 }
12034 );
12035 } finally {
12036 Binder.restoreCallingIdentity(identity);
12037 }
12038 }
12039
Tyler Gunn92479152021-01-20 16:30:10 -080012040 /**
Hui Wang761a6682020-10-31 05:12:53 +000012041 * Gets the config of RCS VoLTE single registration enabled for the device.
12042 */
12043 @Override
12044 public boolean getDeviceSingleRegistrationEnabled() {
12045 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12046 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12047 }
12048
12049 /**
12050 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12051 */
12052 @Override
12053 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12055 "setCarrierSingleRegistrationEnabledOverride");
12056 enforceModifyPermission();
12057
12058 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12059 : Boolean.parseBoolean(enabledStr);
12060 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12061 subId, enabled);
12062 }
12063
12064 /**
12065 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12066 */
12067 @Override
12068 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12069 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12070 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12071 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012072
12073 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012074 * Overrides the ims feature validation result
12075 */
12076 @Override
12077 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12079 "setImsFeatureValidationOverride");
12080
12081 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12082 : Boolean.parseBoolean(enabledStr);
12083 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12084 subId, enabled);
12085 }
12086
12087 /**
12088 * Gets the ims feature validation override value
12089 */
12090 @Override
12091 public boolean getImsFeatureValidationOverride(int subId) {
12092 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12093 "getImsFeatureValidationOverride");
12094 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12095 }
12096
12097 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012098 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12099 * their mobile plan.
12100 */
12101 @Override
12102 public String getMobileProvisioningUrl() {
12103 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12104 final long identity = Binder.clearCallingIdentity();
12105 try {
12106 return getDefaultPhone().getMobileProvisioningUrl();
12107 } finally {
12108 Binder.restoreCallingIdentity(identity);
12109 }
12110 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012111
James.cf Linbcdf8b32021-01-14 16:44:13 +080012112 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012113 * Get the EAB contact from the EAB database.
12114 */
12115 @Override
12116 public String getContactFromEab(String contact) {
12117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12118 enforceModifyPermission();
12119 final long identity = Binder.clearCallingIdentity();
12120 try {
12121 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12122 } finally {
12123 Binder.restoreCallingIdentity(identity);
12124 }
12125 }
12126
12127 /**
Calvin Pana1434322021-07-01 19:27:01 +080012128 * Get the EAB capability from the EAB database.
12129 */
12130 @Override
12131 public String getCapabilityFromEab(String contact) {
12132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12133 enforceModifyPermission();
12134 final long identity = Binder.clearCallingIdentity();
12135 try {
12136 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12137 } finally {
12138 Binder.restoreCallingIdentity(identity);
12139 }
12140 }
12141
12142 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012143 * Remove the EAB contacts from the EAB database.
12144 */
12145 @Override
12146 public int removeContactFromEab(int subId, String contacts) {
12147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12148 enforceModifyPermission();
12149 final long identity = Binder.clearCallingIdentity();
12150 try {
12151 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12152 } finally {
12153 Binder.restoreCallingIdentity(identity);
12154 }
12155 }
12156
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012157 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012158 public boolean getDeviceUceEnabled() {
12159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12160 final long identity = Binder.clearCallingIdentity();
12161 try {
12162 return mApp.getDeviceUceEnabled();
12163 } finally {
12164 Binder.restoreCallingIdentity(identity);
12165 }
12166 }
12167
12168 @Override
12169 public void setDeviceUceEnabled(boolean isEnabled) {
12170 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12171 final long identity = Binder.clearCallingIdentity();
12172 try {
12173 mApp.setDeviceUceEnabled(isEnabled);
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
12178
Brad Ebinger14d467f2021-02-12 06:18:28 +000012179 /**
12180 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12181 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12182 */
12183 // Used for SHELL command only right now.
12184 @Override
12185 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12186 List<String> featureTags) {
12187 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12188 "addUceRegistrationOverrideShell");
12189 final long identity = Binder.clearCallingIdentity();
12190 try {
12191 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12192 new ArraySet<>(featureTags));
12193 } catch (ImsException e) {
12194 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12195 } finally {
12196 Binder.restoreCallingIdentity(identity);
12197 }
12198 }
12199
12200 /**
12201 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12202 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12203 */
12204 // Used for SHELL command only right now.
12205 @Override
12206 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12207 List<String> featureTags) {
12208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12209 "removeUceRegistrationOverrideShell");
12210 final long identity = Binder.clearCallingIdentity();
12211 try {
12212 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12213 new ArraySet<>(featureTags));
12214 } catch (ImsException e) {
12215 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12216 } finally {
12217 Binder.restoreCallingIdentity(identity);
12218 }
12219 }
12220
12221 /**
12222 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12223 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12224 */
12225 // Used for SHELL command only right now.
12226 @Override
12227 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12228 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12229 "clearUceRegistrationOverrideShell");
12230 final long identity = Binder.clearCallingIdentity();
12231 try {
12232 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12233 } catch (ImsException e) {
12234 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12235 } finally {
12236 Binder.restoreCallingIdentity(identity);
12237 }
12238 }
12239
12240 /**
12241 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12242 */
12243 // Used for SHELL command only right now.
12244 @Override
12245 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12246 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12247 "getLatestRcsContactUceCapabilityShell");
12248 final long identity = Binder.clearCallingIdentity();
12249 try {
12250 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12251 } catch (ImsException e) {
12252 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12253 } finally {
12254 Binder.restoreCallingIdentity(identity);
12255 }
12256 }
12257
12258 /**
12259 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12260 * device does not have an active PUBLISH.
12261 */
12262 // Used for SHELL command only right now.
12263 @Override
12264 public String getLastUcePidfXmlShell(int subId) {
12265 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12266 final long identity = Binder.clearCallingIdentity();
12267 try {
12268 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12269 } catch (ImsException e) {
12270 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12271 } finally {
12272 Binder.restoreCallingIdentity(identity);
12273 }
12274 }
12275
James.cf Line8713a42021-04-29 16:04:26 +080012276 /**
12277 * Remove UCE requests cannot be sent to the network status.
12278 */
12279 // Used for SHELL command only right now.
12280 @Override
12281 public boolean removeUceRequestDisallowedStatus(int subId) {
12282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12283 final long identity = Binder.clearCallingIdentity();
12284 try {
12285 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12286 } catch (ImsException e) {
12287 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12288 } finally {
12289 Binder.restoreCallingIdentity(identity);
12290 }
12291 }
12292
James.cf Lin18bb9002021-05-25 01:37:38 +080012293 /**
12294 * Remove UCE requests cannot be sent to the network status.
12295 */
12296 // Used for SHELL command only.
12297 @Override
12298 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12300 final long identity = Binder.clearCallingIdentity();
12301 try {
12302 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12303 } catch (ImsException e) {
12304 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12305 } finally {
12306 Binder.restoreCallingIdentity(identity);
12307 }
12308 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012309
James.cf Lin4b784aa2021-01-31 03:25:15 +080012310 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012311 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12312 String callingPackage) {
12313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12314 mApp, subId, "setSignalStrengthUpdateRequest");
12315
joonhunshin4ac60942023-11-15 15:23:39 +000012316 enforceTelephonyFeatureWithException(callingPackage,
12317 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12318
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012319 final int callingUid = Binder.getCallingUid();
12320 // Verify that tha callingPackage belongs to the calling UID
12321 mApp.getSystemService(AppOpsManager.class)
12322 .checkPackage(callingUid, callingPackage);
12323
Rambo Wang3607f502021-02-01 21:51:40 -080012324 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012325
12326 final long identity = Binder.clearCallingIdentity();
12327 try {
12328 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12329 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12330
12331 if (result instanceof IllegalStateException) {
12332 throw (IllegalStateException) result;
12333 }
12334 } finally {
12335 Binder.restoreCallingIdentity(identity);
12336 }
12337 }
12338
12339 @Override
12340 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12341 String callingPackage) {
12342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12343 mApp, subId, "clearSignalStrengthUpdateRequest");
12344
joonhunshin4ac60942023-11-15 15:23:39 +000012345 enforceTelephonyFeatureWithException(callingPackage,
12346 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12347
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012348 final int callingUid = Binder.getCallingUid();
12349 // Verify that tha callingPackage belongs to the calling UID
12350 mApp.getSystemService(AppOpsManager.class)
12351 .checkPackage(callingUid, callingPackage);
12352
12353 final long identity = Binder.clearCallingIdentity();
12354 try {
12355 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12356 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12357
12358 if (result instanceof IllegalStateException) {
12359 throw (IllegalStateException) result;
12360 }
12361 } finally {
12362 Binder.restoreCallingIdentity(identity);
12363 }
12364 }
12365
Rambo Wang3607f502021-02-01 21:51:40 -080012366 private static void validateSignalStrengthUpdateRequest(Context context,
12367 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012368 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012369 // phone/system process do not have further restriction on request
12370 return;
12371 }
12372
12373 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012374 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012375 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012376 context.enforceCallingOrSelfPermission(
12377 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12378 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012379 }
12380
12381 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012382 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012383 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012384 || info.isEnabled()) {
12385 throw new IllegalArgumentException(
12386 "Only system can set hide fields in SignalThresholdInfo");
12387 }
12388
12389 // Thresholds length for each RAN need in range. This has been validated in
12390 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12391 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12392 final int[] thresholds = info.getThresholds();
12393 Objects.requireNonNull(thresholds);
12394 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12395 || thresholds.length
12396 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12397 throw new IllegalArgumentException(
12398 "thresholds length is out of range: " + thresholds.length);
12399 }
12400 }
12401 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012402
12403 /**
12404 * Gets the current phone capability.
12405 *
12406 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12407 * @return the PhoneCapability which describes the data connection capability of modem.
12408 * It's used to evaluate possible phone config change, for example from single
12409 * SIM device to multi-SIM device.
12410 */
12411 @Override
12412 public PhoneCapability getPhoneCapability() {
12413 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012414
12415 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12416 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12417
SongFerngWang8236caa2021-01-17 21:51:44 +080012418 final long identity = Binder.clearCallingIdentity();
12419 try {
12420 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12421 } finally {
12422 Binder.restoreCallingIdentity(identity);
12423 }
12424 }
Michele Berionne5e411512020-11-13 02:36:59 +000012425
12426 /**
12427 * Prepare TelephonyManager for an unattended reboot. The reboot is
12428 * required to be done shortly after the API is invoked.
12429 */
12430 @Override
12431 @TelephonyManager.PrepareUnattendedRebootResult
12432 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012434 enforceRebootPermission();
12435
joonhunshin4ac60942023-11-15 15:23:39 +000012436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12437 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12438
Michele Berionne5e411512020-11-13 02:36:59 +000012439 final long identity = Binder.clearCallingIdentity();
12440 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012441 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012442 } finally {
12443 Binder.restoreCallingIdentity(identity);
12444 }
12445 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012446
12447 /**
12448 * Request to get the current slicing configuration including URSP rules and
12449 * NSSAIs (configured, allowed and rejected).
12450 *
12451 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12452 */
12453 @Override
12454 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012455 TelephonyPermissions
12456 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12457 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012458
joonhunshin4ac60942023-11-15 15:23:39 +000012459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12460 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12461 "getSlicingConfig");
12462
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012463 final long identity = Binder.clearCallingIdentity();
12464 try {
12465 Phone phone = getDefaultPhone();
12466 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12467 } finally {
12468 Binder.restoreCallingIdentity(identity);
12469 }
12470 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012471
12472 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012473 * Check whether the given premium capability is available for purchase from the carrier.
12474 *
12475 * @param capability The premium capability to check.
12476 * @param subId The subId to check the premium capability for.
12477 *
12478 * @return Whether the given premium capability is available to purchase.
12479 */
12480 @Override
12481 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12482 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12483 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12484 log("Premium capability "
12485 + TelephonyManager.convertPremiumCapabilityToString(capability)
12486 + " is not available for purchase due to missing permissions.");
12487 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12488 + "permission READ_BASIC_PHONE_STATE.");
12489 }
12490
joonhunshin4ac60942023-11-15 15:23:39 +000012491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12492 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12493
Sarah Chin2ec39f62022-08-31 17:03:26 -070012494 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012495 if (phone == null) {
12496 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12497 return false;
12498 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012499 final long identity = Binder.clearCallingIdentity();
12500 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012501 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012502 .isPremiumCapabilityAvailableForPurchase(capability);
12503 } finally {
12504 Binder.restoreCallingIdentity(identity);
12505 }
12506 }
12507
12508 /**
12509 * Purchase the given premium capability from the carrier.
12510 *
12511 * @param capability The premium capability to purchase.
12512 * @param callback The result of the purchase request.
12513 * @param subId The subId to purchase the premium capability for.
12514 */
12515 @Override
12516 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12517 log("purchasePremiumCapability: capability="
12518 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12519 + getCurrentPackageName());
12520
12521 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12522 mApp, "purchasePremiumCapability")) {
12523 log("purchasePremiumCapability "
12524 + TelephonyManager.convertPremiumCapabilityToString(capability)
12525 + " failed due to missing permissions.");
12526 throw new SecurityException("purchasePremiumCapability requires permission "
12527 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012528 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12529 mApp, "purchasePremiumCapability")) {
12530 log("purchasePremiumCapability "
12531 + TelephonyManager.convertPremiumCapabilityToString(capability)
12532 + " failed due to missing permissions.");
12533 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012534 }
12535
joonhunshin4ac60942023-11-15 15:23:39 +000012536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12537 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12538
Sarah Chin2ec39f62022-08-31 17:03:26 -070012539 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012540 if (phone == null) {
12541 try {
12542 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12543 callback.accept(result);
12544 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12545 } catch (RemoteException e) {
12546 String logStr = "Purchase premium capability "
12547 + TelephonyManager.convertPremiumCapabilityToString(capability)
12548 + " failed due to RemoteException handling null phone: " + e;
12549 if (DBG) log(logStr);
12550 AnomalyReporter.reportAnomaly(
12551 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12552 }
12553 return;
12554 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012555
12556 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012557 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012558 callingProcess = mApp.getPackageManager().getApplicationInfo(
12559 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012560 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012561 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012562 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012563
12564 boolean isVisible = false;
12565 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12566 if (am != null) {
12567 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12568 if (processes != null) {
12569 for (ActivityManager.RunningAppProcessInfo process : processes) {
12570 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012571 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012572 if (process.processName.equals(callingProcess) && process.importance
12573 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12574 isVisible = true;
12575 break;
12576 }
12577 }
12578 }
12579 }
12580
12581 if (!isVisible) {
12582 try {
12583 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12584 callback.accept(result);
12585 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12586 } catch (RemoteException e) {
12587 String logStr = "Purchase premium capability "
12588 + TelephonyManager.convertPremiumCapabilityToString(capability)
12589 + " failed due to RemoteException handling background application: " + e;
12590 if (DBG) log(logStr);
12591 AnomalyReporter.reportAnomaly(
12592 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12593 }
12594 return;
12595 }
12596
Sarah Chin71b3a852022-09-28 15:54:19 -070012597 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012598 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012599 }
12600
12601 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012602 * Register an IMS connection state callback
12603 */
12604 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012605 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12606 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012607 if (feature == ImsFeature.FEATURE_MMTEL) {
12608 // ImsMmTelManager
12609 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12610 TelephonyPermissions
12611 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12612 mApp, subId, "registerImsStateCallback");
12613 } else if (feature == ImsFeature.FEATURE_RCS) {
12614 // ImsRcsManager or SipDelegateManager
12615 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12616 Binder.getCallingUid(), "registerImsStateCallback",
12617 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12618 Manifest.permission.READ_PRECISE_PHONE_STATE,
12619 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12620 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12621 }
12622
12623 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12624 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12625 "IMS not available on device.");
12626 }
12627
12628 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12629 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12630 }
12631
12632 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12633 if (controller == null) {
12634 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12635 "IMS not available on device.");
12636 }
12637
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012638 if (callingPackage == null) {
12639 callingPackage = getCurrentPackageName();
12640 }
12641
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012642 final long token = Binder.clearCallingIdentity();
12643 try {
12644 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012645 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012646 } catch (ImsException e) {
12647 throw new ServiceSpecificException(e.getCode());
12648 } finally {
12649 Binder.restoreCallingIdentity(token);
12650 }
12651 }
12652
12653 /**
12654 * Unregister an IMS connection state callback
12655 */
12656 @Override
12657 public void unregisterImsStateCallback(IImsStateCallback cb) {
12658 final long token = Binder.clearCallingIdentity();
12659 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12660 if (controller == null) {
12661 return;
12662 }
12663 try {
12664 controller.unregisterImsStateCallback(cb);
12665 } finally {
12666 Binder.restoreCallingIdentity(token);
12667 }
12668 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012669
12670 /**
12671 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12672 *
12673 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012674 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012675 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012676 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012677 * If there is current registered network this value will be same as the registered cell
12678 * identity. If the device goes out of service the previous cell identity is cached and
12679 * will be returned. If the cache age of the Cell identity is more than 24 hours
12680 * it will be cleared and null will be returned.
12681 *
12682 */
12683 @Override
12684 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12685 String callingFeatureId) {
12686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12687 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12688 LocationAccessPolicy.checkLocationPermission(mApp,
12689 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12690 .setCallingPackage(callingPackage)
12691 .setCallingFeatureId(callingFeatureId)
12692 .setCallingPid(Binder.getCallingPid())
12693 .setCallingUid(Binder.getCallingUid())
12694 .setMethod("getLastKnownCellIdentity")
12695 .setLogAsInfo(true)
12696 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12697 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12698 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12699 .build());
12700
12701 boolean hasFinePermission =
12702 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12703 if (!hasFinePermission
12704 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12705 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012706 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012707 }
12708
12709 final long identity = Binder.clearCallingIdentity();
12710 try {
Ling Mac28f0212023-03-24 16:07:15 -070012711 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012712 if (sst == null) return null;
12713 return sst.getLastKnownCellIdentity();
12714 } finally {
12715 Binder.restoreCallingIdentity(identity);
12716 }
12717 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012718
jimsun3b9ccac2021-10-26 15:01:23 +080012719 /**
12720 * Sets the modem service class Name that Telephony will bind to.
12721 *
12722 * @param serviceName The class name of the modem service.
12723 * @return true if the operation is succeed, otherwise false.
12724 */
12725 public boolean setModemService(String serviceName) {
12726 Log.d(LOG_TAG, "setModemService - " + serviceName);
12727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012729 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12730 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012731 return mPhoneConfigurationManager.setModemService(serviceName);
12732 }
12733
12734 /**
12735 * Return the class name of the currently bounded modem service.
12736 *
12737 * @return the class name of the modem service.
12738 */
12739 public String getModemService() {
12740 String result;
12741 Log.d(LOG_TAG, "getModemService");
12742 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12743 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012744 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012745 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12746 "getModemService");
12747 result = mPhoneConfigurationManager.getModemService();
12748 Log.d(LOG_TAG, "result = " + result);
12749 return result;
12750 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012751
Hakjun Choi3ee81112023-12-19 15:40:58 +000012752 /**
12753 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12754 * including carrier config, entitlement server, and config update.
12755 *
12756 * @param subId subId The subscription ID of the carrier.
12757 *
12758 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12759 * be returned.
12760 *
12761 * @throws SecurityException if the caller doesn't have the required permission.
12762 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012763 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12764 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012765 final long identity = Binder.clearCallingIdentity();
12766 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012767 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012768 } finally {
12769 Binder.restoreCallingIdentity(identity);
12770 }
12771 }
12772
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012773 @Override
12774 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12775 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12776 mApp.enforceCallingOrSelfPermission(
12777 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12778 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12779
12780 final long identity = Binder.clearCallingIdentity();
12781 try {
12782 Phone phone = getPhone(subId);
12783 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012784 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12785 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012786 phone.setVoiceServiceStateOverride(hasService);
12787 } finally {
12788 Binder.restoreCallingIdentity(identity);
12789 }
12790 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012791
12792 /**
12793 * set removable eSIM as default eUICC.
12794 *
12795 * @hide
12796 */
12797 @Override
12798 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12799 enforceModifyPermission();
12800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12801
12802 final long identity = Binder.clearCallingIdentity();
12803 try {
12804 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12805 } finally {
12806 Binder.restoreCallingIdentity(identity);
12807 }
12808 }
12809
12810 /**
12811 * Returns whether the removable eSIM is default eUICC or not.
12812 *
12813 * @hide
12814 */
12815 @Override
12816 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12817 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12819
12820 final long identity = Binder.clearCallingIdentity();
12821 try {
12822 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12823 } finally {
12824 Binder.restoreCallingIdentity(identity);
12825 }
12826 }
12827
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012828 /**
12829 * Get the component name of the default app to direct respond-via-message intent for the
12830 * user associated with this subscription, update the cache if there is no respond-via-message
12831 * application currently configured for this user.
12832 * @return component name of the app and class to direct Respond Via Message intent to, or
12833 * {@code null} if the functionality is not supported.
12834 * @hide
12835 */
12836 @Override
12837 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12838 boolean updateIfNeeded) {
12839 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012840
joonhunshin4ac60942023-11-15 15:23:39 +000012841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12842 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12843 "getDefaultRespondViaMessageApplication");
12844
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012845 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12846
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012847 UserHandle userHandle = null;
12848 final long identity = Binder.clearCallingIdentity();
12849 try {
12850 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12851 } finally {
12852 Binder.restoreCallingIdentity(identity);
12853 }
12854 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12855 updateIfNeeded, userHandle);
12856 }
Jack Yuf5badd92022-12-08 00:50:53 -080012857
12858 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012859 * Set whether the device is able to connect with null ciphering or integrity
12860 * algorithms. This is a global setting and will apply to all active subscriptions
12861 * and all new subscriptions after this.
12862 *
12863 * @param enabled when true, null cipher and integrity algorithms are allowed.
12864 * @hide
12865 */
12866 @Override
12867 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12868 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12869 enforceModifyPermission();
12870 checkForNullCipherAndIntegritySupport();
12871
12872 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12873 // for listening to these preference changes and applying them immediately.
12874 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12875 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12876 editor.apply();
12877
12878 for (Phone phone: PhoneFactory.getPhones()) {
12879 phone.handleNullCipherEnabledChange();
12880 }
12881 }
12882
12883
12884 /**
12885 * Get whether the device is able to connect with null ciphering or integrity
12886 * algorithms. Note that this retrieves the phone-global preference and not
12887 * the state of the radio.
12888 *
12889 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12890 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12891 * version for this feature.
12892 * @hide
12893 */
12894 @Override
12895 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12896 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12897 enforceReadPermission();
12898 checkForNullCipherAndIntegritySupport();
12899 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12900 }
12901
12902 private void checkForNullCipherAndIntegritySupport() {
12903 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12904 throw new UnsupportedOperationException(
12905 "Null cipher and integrity operations require HAL 2.1 or above");
12906 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012907 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12908 throw new UnsupportedOperationException(
12909 "Null cipher and integrity operations unsupported by modem");
12910 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012911 }
12912
Gil Cukierman06403e12023-11-29 16:33:03 +000012913 private void checkForIdentifierDisclosureNotificationSupport() {
12914 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12915 throw new UnsupportedOperationException(
12916 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12917 + "above");
12918 }
12919 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12920 throw new UnsupportedOperationException(
12921 "Cellular identifier disclosure transparency operations unsupported by modem");
12922 }
12923 }
12924
Michael Groover826b71d2023-12-21 22:08:06 -060012925 private void checkForNullCipherNotificationSupport() {
12926 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12927 throw new UnsupportedOperationException(
12928 "Null cipher notification operations require HAL 2.2 or above");
12929 }
12930 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12931 throw new UnsupportedOperationException(
12932 "Null cipher notification operations unsupported by modem");
12933 }
12934 }
12935
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012936 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012937 * Get the SIM state for the slot index.
12938 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12939 *
12940 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12941 */
12942 @Override
12943 @SimState
12944 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012945 if (!mApp.getResources().getBoolean(
12946 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12947 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12948 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12949 }
joonhunshin4ac60942023-11-15 15:23:39 +000012950
Jack Yuf5badd92022-12-08 00:50:53 -080012951 IccCardConstants.State simState;
12952 if (slotIndex < 0) {
12953 simState = IccCardConstants.State.UNKNOWN;
12954 } else {
12955 Phone phone = null;
12956 try {
12957 phone = PhoneFactory.getPhone(slotIndex);
12958 } catch (IllegalStateException e) {
12959 // ignore
12960 }
12961 if (phone == null) {
12962 simState = IccCardConstants.State.UNKNOWN;
12963 } else {
12964 IccCard icc = phone.getIccCard();
12965 if (icc == null) {
12966 simState = IccCardConstants.State.UNKNOWN;
12967 } else {
12968 simState = icc.getState();
12969 }
12970 }
12971 }
12972 return simState.ordinal();
12973 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012974
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012975 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12976 boolean enableLogcat,
12977 long logcatStartTimestampMillis, boolean enableTelecomDump,
12978 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012979 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012980 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12981 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12982 ecdDataBuilder
12983 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12984 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012985 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012986 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012987 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012988 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12989 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012990 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12991 Executors.newCachedThreadPool(), db,
12992 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012993 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012994 }
12995
12996 /**
12997 * Request telephony to persist state for debugging emergency call failures.
12998 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012999 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013000 * @param enableLogcat whether to collect logcat output
13001 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13002 * @param enableTelecomDump whether to collect telecom dumpsys
13003 * @param enableTelephonyDump whether to collect telephony dumpsys
13004 */
13005 @Override
13006 @RequiresPermission(android.Manifest.permission.DUMP)
13007 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13008 long logcatStartTimestampMillis, boolean enableTelecomDump,
13009 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013010 // Verify that the caller has READ_DROPBOX_DATA permission.
13011 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13012 && Flags.enableReadDropboxPermission()) {
13013 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13014 "persistEmergencyCallDiagnosticData");
13015 } else {
13016 // Otherwise, enforce legacy permission.
13017 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13018 "persistEmergencyCallDiagnosticData");
13019 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013020 final long identity = Binder.clearCallingIdentity();
13021 try {
13022 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13023 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13024
13025 } finally {
13026 Binder.restoreCallingIdentity(identity);
13027 }
13028 }
13029
Hui Wang9b5793a2022-12-05 14:38:06 -060013030 /**
13031 * Get current cell broadcast ranges.
13032 */
13033 @Override
13034 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13035 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13036 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13037 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013038
13039 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13040 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13041
Hui Wang9b5793a2022-12-05 14:38:06 -060013042 final long identity = Binder.clearCallingIdentity();
13043 try {
13044 return getPhone(subId).getCellBroadcastIdRanges();
13045 } finally {
13046 Binder.restoreCallingIdentity(identity);
13047 }
13048 }
13049
13050 /**
13051 * Set reception of cell broadcast messages with the list of the given ranges
13052 *
13053 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13054 */
13055 @Override
13056 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13057 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13058 @Nullable IIntegerConsumer callback) {
13059 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13060 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013061
13062 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13063 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13064
Hui Wang9b5793a2022-12-05 14:38:06 -060013065 final long identity = Binder.clearCallingIdentity();
13066 try {
13067 Phone phone = getPhoneFromSubId(subId);
13068 if (DBG) {
13069 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13070 }
13071 phone.setCellBroadcastIdRanges(ranges, result -> {
13072 if (callback != null) {
13073 try {
13074 callback.accept(result);
13075 } catch (RemoteException e) {
13076 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13077 }
13078 }
13079 });
13080 } finally {
13081 Binder.restoreCallingIdentity(identity);
13082 }
13083 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013084
13085 /**
13086 * Returns whether the device supports the domain selection service.
13087 *
13088 * @return {@code true} if the device supports the domain selection service.
13089 */
13090 @Override
13091 public boolean isDomainSelectionSupported() {
13092 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13093 "isDomainSelectionSupported");
13094
13095 final long identity = Binder.clearCallingIdentity();
13096 try {
13097 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13098 } finally {
13099 Binder.restoreCallingIdentity(identity);
13100 }
13101 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013102
13103 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013104 * Returns whether the AOSP domain selection service is supported.
13105 *
13106 * @return {@code true} if the AOSP domain selection service is supported,
13107 * {@code false} otherwise.
13108 */
13109 @Override
13110 public boolean isAospDomainSelectionService() {
13111 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13112 "isAospDomainSelectionService");
13113
13114 final long identity = Binder.clearCallingIdentity();
13115 try {
13116 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13117 String dssComponentName = mApp.getResources().getString(
13118 R.string.config_domain_selection_service_component_name);
13119 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13120 TelephonyDomainSelectionService.class.getName());
13121 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13122 + ", aosp=" + componentName.flattenToString());
13123 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13124 }
13125 } finally {
13126 Binder.restoreCallingIdentity(identity);
13127 }
13128 return false;
13129 }
13130
13131 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013132 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13133 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13134 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013135 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013136 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013137 * @param enableSatellite {@code true} to enable the satellite modem and
13138 * {@code false} to disable.
13139 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013140 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013141 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013142 *
13143 * @throws SecurityException if the caller doesn't have the required permission.
13144 */
13145 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013146 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013147 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013148 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013149 if (enableSatellite) {
13150 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13151 @Override
13152 protected void onReceiveResult(int resultCode, Bundle resultData) {
13153 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13154 + ", resultData=" + resultData);
13155 boolean isAllowed = false;
13156 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13157 callback::accept);
13158 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13159 if (resultData != null
13160 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13161 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13162 } else {
13163 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13164 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013165 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013166 result.accept(resultCode);
13167 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013168 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013169 if (isAllowed) {
13170 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013171 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013172 } else {
13173 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13174 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013175 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013176 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013177 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013178 subId, resultReceiver);
13179 } else {
13180 // No need to check if satellite is allowed at current location when disabling satellite
13181 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013182 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013183 }
Sarah Chin503828c2023-02-01 23:54:20 -080013184 }
13185
13186 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013187 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013188 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013189 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013190 * @param result The result receiver that returns whether the satellite modem is enabled
13191 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013192 *
13193 * @throws SecurityException if the caller doesn't have the required permission.
13194 */
13195 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013196 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13197 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013198 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013199 }
13200
13201 /**
Sarah Chin43457982023-02-15 17:50:38 -080013202 * Request to get whether the satellite service demo mode is enabled.
13203 *
13204 * @param subId The subId of the subscription to check whether the satellite demo mode
13205 * is enabled for.
13206 * @param result The result receiver that returns whether the satellite demo mode is enabled
13207 * 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
Sarah Chinabf081b2023-03-09 23:00:57 -080013212 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13213 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13214 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013215 }
13216
13217 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013218 * Request to get whether the satellite service is enabled with emergency mode.
13219 *
13220 * @param subId The subId of the subscription to check whether the satellite demo mode
13221 * is enabled for.
13222 * @param result The result receiver that returns whether the satellite emergency mode is
13223 * enabled if the request is successful or an error code if the request failed.
13224 *
13225 * @throws SecurityException if the caller doesn't have the required permission.
13226 */
13227 @Override
13228 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13229 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshinfd78fd52024-07-11 05:28:13 +000013230 mSatelliteController.requestIsEmergencyModeEnabled(subId, result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013231 }
13232
13233 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013234 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013235 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013236 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013237 * @param result The result receiver that returns whether the satellite service is supported on
13238 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013239 */
13240 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013241 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013242 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013243 }
13244
13245 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013246 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013247 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013248 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013249 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13250 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013251 *
13252 * @throws SecurityException if the caller doesn't have required permission.
13253 */
13254 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013255 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13256 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013257 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013258 }
13259
13260 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013261 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013262 * This can be called by the pointing UI when the user starts pointing to the satellite.
13263 * Modem should continue to report the pointing input as the device or satellite moves.
13264 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013265 * @param subId The subId of the subscription to start satellite transmission updates for.
13266 * @param resultCallback The callback to get the result of the request.
13267 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013268 *
13269 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013270 */
13271 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013272 public void startSatelliteTransmissionUpdates(int subId,
13273 @NonNull IIntegerConsumer resultCallback,
13274 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13275 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13276 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013277 }
13278
13279 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013280 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013281 * This can be called by the pointing UI when the user stops pointing to the satellite.
13282 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013283 * @param subId The subId of the subscription to stop satellite transmission updates for.
13284 * @param resultCallback The callback to get the result of the request.
13285 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13286 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013287 *
13288 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013289 */
13290 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013291 public void stopSatelliteTransmissionUpdates(int subId,
13292 @NonNull IIntegerConsumer resultCallback,
13293 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13294 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13295 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013296 }
13297
13298 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013299 * Register the subscription with a satellite provider.
13300 * This is needed to register the subscription if the provider allows dynamic registration.
13301 *
13302 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013303 * @param token The token to be used as a unique identifier for provisioning with satellite
13304 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013305 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013306 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013307 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013308 * @return The signal transport used by the caller to cancel the provision request,
13309 * or {@code null} if the request failed.
13310 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013311 * @throws SecurityException if the caller doesn't have the required permission.
13312 */
13313 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013314 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013315 @NonNull String token, @NonNull byte[] provisionData,
13316 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013317 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013318 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13319 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013320 }
13321
13322 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013323 * Unregister the device/subscription with the satellite provider.
13324 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013325 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013326 * should report as deprovisioned.
13327 *
13328 * @param subId The subId of the subscription to be deprovisioned.
13329 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013330 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013331 *
13332 * @throws SecurityException if the caller doesn't have the required permission.
13333 */
13334 @Override
13335 public void deprovisionSatelliteService(int subId,
13336 @NonNull String token, @NonNull IIntegerConsumer callback) {
13337 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013338 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013339 }
13340
13341 /**
Sarah Chin43457982023-02-15 17:50:38 -080013342 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013343 *
Sarah Chin43457982023-02-15 17:50:38 -080013344 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013345 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013346 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013347 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013348 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013349 * @throws SecurityException if the caller doesn't have the required permission.
13350 */
13351 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013352 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13353 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013354 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013355 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013356 }
13357
13358 /**
Sarah Chin43457982023-02-15 17:50:38 -080013359 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013360 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013361 *
Sarah Chin43457982023-02-15 17:50:38 -080013362 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013363 * @param callback The callback that was passed to
13364 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013365 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013366 * @throws SecurityException if the caller doesn't have the required permission.
13367 */
13368 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013369 public void unregisterForSatelliteProvisionStateChanged(
13370 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013371 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013372 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013373 }
13374
13375 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013376 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013377 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013378 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013379 * @param result The result receiver that returns whether the device is provisioned with a
13380 * satellite provider if the request is successful or an error code if the
13381 * request failed.
13382 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013383 * @throws SecurityException if the caller doesn't have the required permission.
13384 */
13385 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013386 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13387 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013388 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013389 }
13390
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013391 /**
Sarah Chin43457982023-02-15 17:50:38 -080013392 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013393 *
Sarah Chin43457982023-02-15 17:50:38 -080013394 * @param subId The subId of the subscription to register for satellite modem state changed.
13395 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013397 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013398 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013399 * @throws SecurityException if the caller doesn't have the required permission.
13400 */
13401 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013402 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013403 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013404 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013405 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013406 }
13407
13408 /**
Sarah Chin43457982023-02-15 17:50:38 -080013409 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013410 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013411 *
Sarah Chin43457982023-02-15 17:50:38 -080013412 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013413 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013414 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013415 *
13416 * @throws SecurityException if the caller doesn't have the required permission.
13417 */
13418 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013419 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013420 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013421 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13422 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013423 }
13424
13425 /**
13426 * Register to receive incoming datagrams over satellite.
13427 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013428 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013429 * @param callback The callback to handle incoming datagrams over satellite.
13430 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013431 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013432 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013433 * @throws SecurityException if the caller doesn't have the required permission.
13434 */
13435 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013436 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013437 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013438 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13439 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013440 }
13441
13442 /**
13443 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013444 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013445 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013446 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13447 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013448 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013449 *
13450 * @throws SecurityException if the caller doesn't have the required permission.
13451 */
13452 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013453 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013454 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013455 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13456 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013457 }
13458
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013459 /**
13460 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013461 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013462 * This method requests modem to check if there are any pending datagrams to be received over
13463 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013464 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013465 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013466 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013467 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013468 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013469 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013470 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013471 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13472 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13473 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013474 }
13475
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013476 /**
13477 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013478 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013479 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13480 * input to this method. Datagram received here will be passed down to modem without any
13481 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013482 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013483 * @param subId The subId of the subscription to send satellite datagrams for.
13484 * @param datagramType datagram type indicating whether the datagram is of type
13485 * SOS_SMS or LOCATION_SHARING.
13486 * @param datagram encoded gateway datagram which is encrypted by the caller.
13487 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013488 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13489 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013490 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013491 *
13492 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013493 */
13494 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013495 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013496 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13497 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013498 enforceSatelliteCommunicationPermission("sendDatagram");
13499 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13500 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013501 }
13502
Sarah Chindf715ec2023-02-13 13:46:24 -080013503 /**
13504 * Request to get whether satellite communication is allowed for the current location.
13505 *
13506 * @param subId The subId of the subscription to check whether satellite communication is
13507 * allowed for the current location for.
13508 * @param result The result receiver that returns whether satellite communication is allowed
13509 * for the current location if the request is successful or an error code
13510 * if the request failed.
13511 *
13512 * @throws SecurityException if the caller doesn't have the required permission.
13513 */
13514 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013515 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013516 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013517 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13518 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13519 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013520 }
13521
13522 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013523 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013524 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013525 * @param subId The subId to get the time after which the satellite will be visible for.
13526 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013527 * be visible if the request is successful or an error code if the request failed.
13528 *
13529 * @throws SecurityException if the caller doesn't have the required permission.
13530 */
13531 @Override
13532 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13533 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013534 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013535 }
13536
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013537 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013538 * Inform that Device is aligned to satellite for demo mode.
13539 *
13540 * @param subId The subId to get the time after which the satellite will be visible for.
13541 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13542 * {@code false} Device fails to align with the satellite for demo mode.
13543 *
13544 * @throws SecurityException if the caller doesn't have required permission.
13545 */
13546 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13547
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013548 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013549 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013550 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013551 }
13552
13553 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013554 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13555 * by modem.
13556 *
13557 * @param subId The subId of the subscription to request for.
13558 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013559 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013560 * operation.
13561 *
13562 * @throws SecurityException if the caller doesn't have required permission.
13563 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013564 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013565 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13566 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013567 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013568 final long identity = Binder.clearCallingIdentity();
13569 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013570 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013571 } finally {
13572 Binder.restoreCallingIdentity(identity);
13573 }
13574 }
13575
13576 /**
13577 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13578 * by modem.
13579 *
13580 * @param subId The subId of the subscription to request for.
13581 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013582 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013583 * operation.
13584 *
13585 * @throws SecurityException if the caller doesn't have required permission.
13586 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013587 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013588 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13589 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013590 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013591 final long identity = Binder.clearCallingIdentity();
13592 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013593 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013594 } finally {
13595 Binder.restoreCallingIdentity(identity);
13596 }
13597 }
13598
13599 /**
13600 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013601 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013602 *
13603 * @param subId The subId of the subscription to request for.
13604 *
13605 * @return Integer array of reasons for disallowing satellite communication.
13606 *
13607 * @throws SecurityException if the caller doesn't have the required permission.
13608 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013609 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013610 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013611 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013612 final long identity = Binder.clearCallingIdentity();
13613 try {
13614 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013615 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013616 return reasonSet.stream().mapToInt(i->i).toArray();
13617 } finally {
13618 Binder.restoreCallingIdentity(identity);
13619 }
13620 }
13621
13622 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013623 * Request to get the signal strength of the satellite connection.
13624 *
13625 * @param subId The subId of the subscription to request for.
13626 * @param result Result receiver to get the error code of the request and the current signal
13627 * strength of the satellite connection.
13628 *
13629 * @throws SecurityException if the caller doesn't have required permission.
13630 */
13631 @Override
13632 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13633 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13634 final long identity = Binder.clearCallingIdentity();
13635 try {
13636 mSatelliteController.requestNtnSignalStrength(subId, result);
13637 } finally {
13638 Binder.restoreCallingIdentity(identity);
13639 }
13640 }
13641
13642 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013643 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13644 * is not successful, a {@link ServiceSpecificException} that contains
13645 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013646 *
13647 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013648 * @param callback The callback to handle the NTN signal strength changed event. If the
13649 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13650 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13651 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13652 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013653 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013654 * @throws SecurityException If the caller doesn't have the required permission.
13655 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013656 */
13657 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013658 public void registerForNtnSignalStrengthChanged(int subId,
13659 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013660 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13661 final long identity = Binder.clearCallingIdentity();
13662 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013663 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013664 } finally {
13665 Binder.restoreCallingIdentity(identity);
13666 }
13667 }
13668
13669 /**
13670 * Unregisters for NTN signal strength changed from satellite modem.
13671 * If callback was not registered before, the request will be ignored.
13672 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013673 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13674 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013675 * @param callback The callback that was passed to
13676 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13677 *
13678 * @throws SecurityException if the caller doesn't have the required permission.
13679 */
13680 @Override
13681 public void unregisterForNtnSignalStrengthChanged(
13682 int subId, @NonNull INtnSignalStrengthCallback callback) {
13683 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13684 final long identity = Binder.clearCallingIdentity();
13685 try {
13686 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13687 } finally {
13688 Binder.restoreCallingIdentity(identity);
13689 }
13690 }
13691
13692 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013693 * Registers for satellite capabilities change event from the satellite service.
13694 *
13695 * @param subId The subId of the subscription to request for.
13696 * @param callback The callback to handle the satellite capabilities changed event.
13697 *
13698 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13699 *
13700 * @throws SecurityException if the caller doesn't have required permission.
13701 */
13702 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013703 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013704 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013705 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013706 final long identity = Binder.clearCallingIdentity();
13707 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013708 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013709 } finally {
13710 Binder.restoreCallingIdentity(identity);
13711 }
13712 }
13713
13714 /**
13715 * Unregisters for satellite capabilities change event from the satellite service.
13716 * If callback was not registered before, the request will be ignored.
13717 *
13718 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13719 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013720 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013721 *
13722 * @throws SecurityException if the caller doesn't have required permission.
13723 */
13724 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013725 public void unregisterForCapabilitiesChanged(int subId,
13726 @NonNull ISatelliteCapabilitiesCallback callback) {
13727 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013728 final long identity = Binder.clearCallingIdentity();
13729 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013730 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013731 } finally {
13732 Binder.restoreCallingIdentity(identity);
13733 }
13734 }
13735
13736 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013737 * Registers for the satellite supported state changed.
13738 *
13739 * @param subId The subId of the subscription to register for supported state changed.
13740 * @param callback The callback to handle the satellite supported state changed event.
13741 *
13742 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13743 *
13744 * @throws SecurityException if the caller doesn't have the required permission.
13745 */
13746 @Override
13747 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13748 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13749 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13750 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13751 }
13752
13753 /**
13754 * Unregisters for the satellite supported state changed.
13755 * If callback was not registered before, the request will be ignored.
13756 *
13757 * @param subId The subId of the subscription to unregister for supported state changed.
13758 * @param callback The callback that was passed to
13759 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13760 *
13761 * @throws SecurityException if the caller doesn't have the required permission.
13762 */
13763 @Override
13764 public void unregisterForSatelliteSupportedStateChanged(
13765 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13766 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13767 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13768 }
13769
13770 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013771 * This API can be used by only CTS to update satellite vendor service package name.
13772 *
13773 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013774 * @param provisioned Whether satellite should be provisioned or not.
13775 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013776 * @return {@code true} if the satellite vendor service is set successfully,
13777 * {@code false} otherwise.
13778 */
Hakjun Choic3393242024-06-26 18:02:08 +000013779 public boolean setSatelliteServicePackageName(String servicePackageName,
13780 String provisioned) {
13781 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13782 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013783 TelephonyPermissions.enforceShellOnly(
13784 Binder.getCallingUid(), "setSatelliteServicePackageName");
13785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13786 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13787 "setSatelliteServicePackageName");
Hakjun Choic3393242024-06-26 18:02:08 +000013788 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13789 provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013790 }
13791
13792 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013793 * This API can be used by only CTS to update satellite gateway service package name.
13794 *
13795 * @param servicePackageName The package name of the satellite gateway service.
13796 * @return {@code true} if the satellite gateway service is set successfully,
13797 * {@code false} otherwise.
13798 */
13799 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13800 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13801 TelephonyPermissions.enforceShellOnly(
13802 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13804 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13805 "setSatelliteGatewayServicePackageName");
13806 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13807 }
13808
13809 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013810 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13811 *
13812 * @param packageName The package name of the satellite pointing UI app.
13813 * @param className The class name of the satellite pointing UI app.
13814 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13815 * {@code false} otherwise.
13816 */
13817 public boolean setSatellitePointingUiClassName(
13818 @Nullable String packageName, @Nullable String className) {
13819 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13820 + ", className=" + className);
13821 TelephonyPermissions.enforceShellOnly(
13822 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13825 "setSatelliteGatewayServicePackageName");
13826 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13827 }
13828
13829 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013830 * This API can be used by only CTS to update the timeout duration in milliseconds that
13831 * satellite should stay at listening mode to wait for the next incoming page before disabling
13832 * listening mode.
13833 *
13834 * @param timeoutMillis The timeout duration in millisecond.
13835 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13836 */
13837 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13838 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13839 TelephonyPermissions.enforceShellOnly(
13840 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13842 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13843 "setSatelliteListeningTimeoutDuration");
13844 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13845 }
13846
13847 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013848 * This API can be used by only CTS to override the timeout durations used by the
13849 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013850 *
13851 * @param timeoutMillis The timeout duration in millisecond.
13852 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13853 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013854 public boolean setDatagramControllerTimeoutDuration(
13855 boolean reset, int timeoutType, long timeoutMillis) {
13856 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13857 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013858 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013859 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13861 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013862 "setDatagramControllerTimeoutDuration");
13863 return mSatelliteController.setDatagramControllerTimeoutDuration(
13864 reset, timeoutType, timeoutMillis);
13865 }
13866
13867 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013868 * This API can be used by only CTS to override the boolean configs used by the
13869 * DatagramController module.
13870 *
13871 * @param enable Whether to enable or disable boolean config.
13872 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13873 */
13874 public boolean setDatagramControllerBooleanConfig(
13875 boolean reset, int booleanType, boolean enable) {
13876 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13877 + ", reset=" + reset + ", enable=" + enable);
13878 TelephonyPermissions.enforceShellOnly(
13879 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13881 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13882 "ssetDatagramControllerBooleanConfig");
13883 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13884 }
13885
13886
13887 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013888 * This API can be used by only CTS to override the timeout durations used by the
13889 * SatelliteController module.
13890 *
13891 * @param timeoutMillis The timeout duration in millisecond.
13892 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13893 */
13894 public boolean setSatelliteControllerTimeoutDuration(
13895 boolean reset, int timeoutType, long timeoutMillis) {
13896 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13897 + reset + ", timeoutMillis=" + timeoutMillis);
13898 TelephonyPermissions.enforceShellOnly(
13899 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13901 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13902 "setSatelliteControllerTimeoutDuration");
13903 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13904 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013905 }
13906
13907 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013908 * This API can be used in only testing to override connectivity status in monitoring emergency
13909 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13910 *
13911 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13912 * of the following values to enable the override:
13913 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13914 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13915 * To disable the override, use -1 for handoverType.
13916 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13917 * delaySeconds after the emergency call starts.
13918 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13919 */
13920 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13921 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13922 TelephonyPermissions.enforceShellOnly(
13923 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13925 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13926 "setEmergencyCallToSatelliteHandoverType");
13927 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13928 handoverType, delaySeconds);
13929 }
13930
13931 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013932 * This API can be used in only testing to override oem-enabled satellite provision status.
13933 *
13934 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13935 * otherwise.
13936 * @param isProvisioned The overriding provision status.
13937 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13938 */
13939 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13940 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13941 + ", isProvisioned=" + isProvisioned);
13942 TelephonyPermissions.enforceShellOnly(
13943 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13945 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13946 "setOemEnabledSatelliteProvisionStatus");
13947 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13948 }
13949
13950 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013951 * This API should be used by only CTS tests to forcefully set telephony country codes.
13952 *
13953 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13954 */
13955 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13956 Map cachedNetworkCountryCodes, String locationCountryCode,
13957 long locationCountryCodeTimestampNanos) {
13958 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13959 + String.join(", ", currentNetworkCountryCodes)
13960 + ", locationCountryCode=" + locationCountryCode
13961 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13962 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13963 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13964 TelephonyPermissions.enforceShellOnly(
13965 Binder.getCallingUid(), "setCachedLocationCountryCode");
13966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13967 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13968 "setCachedLocationCountryCode");
13969 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13970 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13971 locationCountryCodeTimestampNanos);
13972 }
13973
13974 /**
13975 * This API should be used by only CTS tests to override the overlay configs of satellite
13976 * access controller.
13977 *
13978 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13979 * otherwise.
13980 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13981 */
13982 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13983 String s2CellFile, long locationFreshDurationNanos,
13984 List<String> satelliteCountryCodes) {
13985 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13986 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13987 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13988 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13989 ? String.join(", ", satelliteCountryCodes) : null));
13990 TelephonyPermissions.enforceShellOnly(
13991 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13993 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13994 "setSatelliteAccessControlOverlayConfigs");
13995 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13996 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13997 }
13998
13999 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014000 * This API can be used by only CTS to override the cached value for the device overlay config
14001 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14002 * outgoing satellite datagrams should be sent to modem in demo mode.
14003 *
14004 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14005 * satellite modem or not.
14006 *
14007 * @return {@code true} if the operation is successful, {@code false} otherwise.
14008 */
14009 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14010 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14011 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14012 + "disabled");
14013 return false;
14014 }
14015 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14016 TelephonyPermissions.enforceShellOnly(
14017 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14019 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14020 "setShouldSendDatagramToModemInDemoMode");
14021 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14022 shouldSendToModemInDemoMode);
14023 }
14024
14025 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014026 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14027 *
14028 * @param state a state indicates whether satellite access allowed state should be cached and
14029 * the allowed state.
14030 * @return {@code true} if the setting is successful, {@code false} otherwise.
14031 */
14032 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14033 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14034 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14035 + "oemEnabledSatelliteFlag is disabled");
14036 return false;
14037 }
14038
14039 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14040 + "state=" + state);
14041 TelephonyPermissions.enforceShellOnly(
14042 Binder.getCallingUid(),
14043 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14045 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14046 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14047 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14048 state);
14049 }
14050
14051 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014052 * Sets the service defined in ComponentName to be bound.
14053 *
14054 * This should only be used for testing.
14055 * @return {@code true} if the DomainSelectionService to bind to was set,
14056 * {@code false} otherwise.
14057 */
14058 @Override
14059 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14060 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14061
14062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14063 "setDomainSelectionServiceOverride");
14064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14065 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14066
14067 final long identity = Binder.clearCallingIdentity();
14068 try {
14069 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14070 return DomainSelectionResolver.getInstance()
14071 .setDomainSelectionServiceOverride(componentName);
14072 }
14073 } finally {
14074 Binder.restoreCallingIdentity(identity);
14075 }
14076 return false;
14077 }
14078
14079 /**
14080 * Clears the DomainSelectionService override.
14081 *
14082 * This should only be used for testing.
14083 * @return {@code true} if the DomainSelectionService override was cleared,
14084 * {@code false} otherwise.
14085 */
14086 @Override
14087 public boolean clearDomainSelectionServiceOverride() {
14088 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14089
14090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14091 "clearDomainSelectionServiceOverride");
14092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14093 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14094
14095 final long identity = Binder.clearCallingIdentity();
14096 try {
14097 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14098 return DomainSelectionResolver.getInstance()
14099 .clearDomainSelectionServiceOverride();
14100 }
14101 } finally {
14102 Binder.restoreCallingIdentity(identity);
14103 }
14104 return false;
14105 }
14106
14107 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014108 * Enable or disable notifications sent for cellular identifier disclosure events.
14109 *
14110 * Disclosure events are defined as instances where a device has sent a cellular identifier
14111 * on the Non-access stratum (NAS) before a security context is established. As a result the
14112 * identifier is sent in the clear, which has privacy implications for the user.
14113 *
14114 * @param enable if notifications about disclosure events should be enabled
14115 * @throws SecurityException if the caller does not have the required privileges
14116 * @throws UnsupportedOperationException if the modem does not support this feature.
14117 */
14118 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014119 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014120 enforceModifyPermission();
14121 checkForIdentifierDisclosureNotificationSupport();
14122
14123 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14124 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14125 editor.apply();
14126
14127 // Each phone instance is responsible for updating its respective modem immediately
14128 // after we've made a preference change.
14129 for (Phone phone : PhoneFactory.getPhones()) {
14130 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14131 }
14132 }
14133
14134 /**
14135 * Get whether or not cellular identifier disclosure notifications are enabled.
14136 *
14137 * @throws SecurityException if the caller does not have the required privileges
14138 * @throws UnsupportedOperationException if the modem does not support this feature.
14139 */
14140 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014141 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014142 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14143 checkForIdentifierDisclosureNotificationSupport();
14144 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14145 }
14146
14147 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014148 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14149 * are in use by the cellular modem.
14150 *
14151 * @throws IllegalStateException if the Telephony process is not currently available
14152 * @throws SecurityException if the caller does not have the required privileges
14153 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14154 * and integrity algorithms in use
14155 * @hide
14156 */
14157 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014158 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014159 enforceModifyPermission();
14160 checkForNullCipherNotificationSupport();
14161
14162 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14163 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14164 editor.apply();
14165
14166 // Each phone instance is responsible for updating its respective modem immediately
14167 // after a preference change.
14168 for (Phone phone : PhoneFactory.getPhones()) {
14169 phone.handleNullCipherNotificationPreferenceChanged();
14170 }
14171 }
14172
14173 /**
14174 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14175 * cellular modem.
14176 *
14177 * @throws IllegalStateException if the Telephony process is not currently available
14178 * @throws SecurityException if the caller does not have the required privileges
14179 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14180 * and integrity algorithms in use
14181 * @hide
14182 */
14183 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14184 public boolean isNullCipherNotificationsEnabled() {
14185 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14186 checkForNullCipherNotificationSupport();
14187 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14188 }
14189
14190 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014191 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14192 *
14193 * <p>This method behaves in one of the following ways:
14194 * <ul>
14195 * <li>return true : if the calling package has the appop permission {@link
14196 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14197 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14198 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14199 * Owner device identifier access check, or the calling package has carrier privileges</>
14200 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14201 * </ul>
14202 */
14203 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14204 String callingPackage, @Nullable String callingFeatureId, String message) {
14205 for (Phone phone : PhoneFactory.getPhones()) {
14206 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14207 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14208 return true;
14209 }
14210 }
14211 return false;
14212 }
arunvoddud7401012022-12-15 16:08:12 +000014213
14214 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014215 * @return The subscription manager service instance.
14216 */
14217 public SubscriptionManagerService getSubscriptionManagerService() {
14218 return SubscriptionManagerService.getInstance();
14219 }
14220
14221 /**
arunvoddud7401012022-12-15 16:08:12 +000014222 * Class binds the consumer[callback] and carrierId.
14223 */
14224 private static class CallerCallbackInfo {
14225 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014226 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014227
Steve Statia28b7cb32024-03-11 23:58:50 +000014228 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014229 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014230 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014231 }
14232
14233 public Consumer<Integer> getConsumer() {
14234 return mConsumer;
14235 }
14236
Steve Statia28b7cb32024-03-11 23:58:50 +000014237 public Set<Integer> getCarrierIds() {
14238 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014239 }
14240 }
joonhunshin4ac60942023-11-15 15:23:39 +000014241
14242 /*
14243 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14244 * But the context that is passed in is unused if the phone app is already alive.
14245 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14246 */
14247 @VisibleForTesting
14248 public void setPackageManager(PackageManager packageManager) {
14249 mPackageManager = packageManager;
14250 }
14251
14252 /*
Nate Myren453c3472024-03-13 11:28:11 -070014253 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14254 * But the context that is passed in is unused if the phone app is already alive.
14255 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14256 */
14257 @VisibleForTesting
14258 public void setAppOpsManager(AppOpsManager appOps) {
14259 mAppOps = appOps;
14260 }
14261
14262 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014263 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14264 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14265 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14266 */
14267 @VisibleForTesting
14268 public void setFeatureFlags(FeatureFlags featureFlags) {
14269 mFeatureFlags = featureFlags;
14270 }
14271
14272 /**
14273 * Make sure the device has required telephony feature
14274 *
14275 * @throws UnsupportedOperationException if the device does not have required telephony feature
14276 */
14277 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14278 @NonNull String telephonyFeature, @NonNull String methodName) {
14279 if (callingPackage == null || mPackageManager == null) {
14280 return;
14281 }
14282
14283 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14284 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014285 Binder.getCallingUserHandle())
14286 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14287 // Skip to check associated telephony feature,
14288 // if compatibility change is not enabled for the current process or
14289 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014290 return;
14291 }
14292
14293 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14294 throw new UnsupportedOperationException(
14295 methodName + " is unsupported without " + telephonyFeature);
14296 }
14297 }
youngtaecha5d483d52024-04-29 17:05:45 +000014298
14299 /**
14300 * Registers for the satellite communication allowed state changed.
14301 *
14302 * @param subId The subId of the subscription to register for the satellite communication
14303 * allowed state changed.
14304 * @param callback The callback to handle the satellite communication allowed
14305 * state changed event.
14306 *
14307 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14308 *
14309 * @throws SecurityException if the caller doesn't have the required permission.
14310 */
14311 @Override
14312 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14313 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14314 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14315 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14316 subId, callback);
14317 }
14318
14319 /**
14320 * Unregisters for the satellite communication allowed state changed.
14321 * If callback was not registered before, the request will be ignored.
14322 *
14323 * @param subId The subId of the subscription to unregister for the satellite communication
14324 * allowed state changed.
14325 * @param callback The callback that was passed to
14326 * {@link #registerForCommunicationAllowedStateChanged(int,
14327 * ISatelliteCommunicationAllowedStateCallback)}. *
14328 * @throws SecurityException if the caller doesn't have the required permission.
14329 */
14330 @Override
14331 public void unregisterForCommunicationAllowedStateChanged(
14332 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14333 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14334 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14335 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014336
14337 /**
14338 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14339 *
14340 * @param subId The subId of the subscription to the satellite session stats for.
14341 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14342 * if the request is successful or an error code if the request failed.
14343 *
14344 * @throws SecurityException if the caller doesn't have required permission.
14345 */
14346 @Override
14347 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14348 enforceModifyPermission();
14349 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14350 mSatelliteController.requestSatelliteSessionStats(subId, result);
14351 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014352
14353 /**
14354 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14355 *
14356 * @param result The result receiver, which returns the list of prioritized satellite tokens
14357 * to be used for provision if the request is successful or an error code if the request failed.
14358 *
14359 * @throws SecurityException if the caller doesn't have the required permission.
14360 */
14361 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014362 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14363 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
14364 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014365 }
14366
14367 /**
14368 * Deliver the list of provisioned satellite subscriber ids.
14369 *
14370 * @param list List of provisioned satellite subscriber ids.
14371 * @param result The result receiver that returns whether deliver success or fail.
14372 *
14373 * @throws SecurityException if the caller doesn't have the required permission.
14374 */
14375 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014376 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014377 @NonNull ResultReceiver result) {
14378 enforceSatelliteCommunicationPermission("provisionSatellite");
14379 mSatelliteController.provisionSatellite(list, result);
14380 }
Jack Yufa8ed012023-02-11 15:42:28 -080014381}