blob: 251976ba5331df3675cbf1ca07da8bb3fff2398e [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
Jack Yu26735292024-09-25 14:33:49 -0700445 @Nullable
446 private ComponentName mTestEuiccUiComponent;
447
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800449 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800450 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800451 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800452
Derek Tan97ebb422014-09-05 16:55:38 -0700453 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
454 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800455 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800456 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700457
Michelecea4cf22018-12-21 15:00:11 -0800458 // String to store multi SIM allowed
459 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
460
Derek Tan740e1672017-06-27 14:56:27 -0700461 // The AID of ISD-R.
462 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
463
yinxub1bed742017-04-17 11:45:04 -0700464 private NetworkScanRequestTracker mNetworkScanRequestTracker;
465
David Kelly5e06a7f2018-03-12 14:10:59 +0000466 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
467 private static final int MANUFACTURER_CODE_LENGTH = 8;
468
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800469 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800470 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800471
Sarah Chin2ec39f62022-08-31 17:03:26 -0700472 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
473 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
474
Derek Tan89e89d42014-07-08 17:00:10 -0700475 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700476 * Experiment flag to enable erase modem config on reset network, default value is false
477 */
478 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
479 "reset_network_erase_modem_config_enabled";
480
Nathan Harolddc3bcec2024-05-16 14:06:40 -0700481 private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800482
Gary Jian76280a42022-12-07 16:18:33 +0800483 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
484
arunvoddub1365e62024-07-31 09:42:31 +0000485 private static final int LINE1_NUMBER_MAX_LEN = 50;
486
sandeepjsb6c87872021-09-27 15:34:44 +0000487 /**
488 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
489 * one ICCID active at the same time.
490 * Apps should use below API signatures if targeting SDK is T and beyond.
491 *
492 * @hide
493 */
494 @ChangeId
495 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
496 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800497
Naina Nallurid63128d2019-09-17 14:10:30 -0700498 /**
Chen Xu540470b2021-12-14 17:15:47 -0800499 * Apps targeting on Android T and beyond will get exception whenever icc close channel
500 * operation fails.
501 */
502 @ChangeId
503 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
504 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
505
506 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 * A request object to use for transmitting data to an ICC.
508 */
509 private static final class IccAPDUArgument {
510 public int channel, cla, command, p1, p2, p3;
511 public String data;
512
513 public IccAPDUArgument(int channel, int cla, int command,
514 int p1, int p2, int p3, String data) {
515 this.channel = channel;
516 this.cla = cla;
517 this.command = command;
518 this.p1 = p1;
519 this.p2 = p2;
520 this.p3 = p3;
521 this.data = data;
522 }
523 }
524
525 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700526 * A request object to use for transmitting data to an ICC.
527 */
528 private static final class ManualNetworkSelectionArgument {
529 public OperatorInfo operatorInfo;
530 public boolean persistSelection;
531
532 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
533 this.operatorInfo = operatorInfo;
534 this.persistSelection = persistSelection;
535 }
536 }
537
Sarah Chin71b3a852022-09-28 15:54:19 -0700538 private static final class PurchasePremiumCapabilityArgument {
539 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 public @NonNull IIntegerConsumer callback;
541
542 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800543 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700544 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700545 this.callback = callback;
546 }
547 }
548
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700549 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
551 * request after sending. The main thread will notify the request when it is complete.
552 */
553 private static final class MainThreadRequest {
554 /** The argument to use for the request */
555 public Object argument;
556 /** The result of the request that is run on the main thread */
557 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800558 // The subscriber id that this request applies to. Defaults to
559 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
560 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561
Nathan Harold92bed182018-10-12 18:16:49 -0700562 // In cases where subId is unavailable, the caller needs to specify the phone.
563 public Phone phone;
564
vagdeviaf9a5b92018-08-15 16:01:53 -0700565 public WorkSource workSource;
566
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 public MainThreadRequest(Object argument) {
568 this.argument = argument;
569 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800570
Nathan Harold92bed182018-10-12 18:16:49 -0700571 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
572 this.argument = argument;
573 if (phone != null) {
574 this.phone = phone;
575 }
576 this.workSource = workSource;
577 }
578
vagdeviaf9a5b92018-08-15 16:01:53 -0700579 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800580 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800581 if (subId != null) {
582 this.subId = subId;
583 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700584 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586 }
587
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800588 private static final class IncomingThirdPartyCallArgs {
589 public final ComponentName component;
590 public final String callId;
591 public final String callerDisplayName;
592
593 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
594 String callerDisplayName) {
595 this.component = component;
596 this.callId = callId;
597 this.callerDisplayName = callerDisplayName;
598 }
599 }
600
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 /**
602 * A handler that processes messages on the main thread in the phone process. Since many
603 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
604 * inbound binder threads to the main thread in the phone process. The Binder thread
605 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
606 * on, which will be notified when the operation completes and will contain the result of the
607 * request.
608 *
609 * <p>If a MainThreadRequest object is provided in the msg.obj field,
610 * note that request.result must be set to something non-null for the calling thread to
611 * unblock.
612 */
613 private final class MainThreadHandler extends Handler {
614 @Override
615 public void handleMessage(Message msg) {
616 MainThreadRequest request;
617 Message onCompleted;
618 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000619 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800621 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622
623 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 case CMD_HANDLE_USSD_REQUEST: {
625 request = (MainThreadRequest) msg.obj;
626 final Phone phone = getPhoneFromRequest(request);
627 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800628 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700630
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 if (!isUssdApiAllowed(request.subId)) {
632 // Carrier does not support use of this API, return failure.
633 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
634 UssdResponse response = new UssdResponse(ussdRequest, null);
635 Bundle returnData = new Bundle();
636 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
637 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 request.result = true;
640 notifyRequester(request);
641 return;
642 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700643
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 try {
645 request.result = phone != null
646 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
647 } catch (CallStateException cse) {
648 request.result = false;
649 }
650 // Wake up the requesting thread
651 notifyRequester(request);
652 break;
pkanwar32d516d2016-10-14 19:37:38 -0700653 }
654
Yorke Lee716f67e2015-06-17 15:39:16 -0700655 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700657 final Phone phone = getPhoneFromRequest(request);
658 request.result = phone != null ?
659 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
660 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000669 uiccPort = getUiccPortFromRequest(request);
670 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800672 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800676 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800678 iccArgument.channel, iccArgument.cla, iccArgument.command,
679 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
680 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
687 if (ar.exception == null && ar.result != null) {
688 request.result = ar.result;
689 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800690 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 if (ar.result == null) {
692 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800693 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800695 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 } else {
697 loge("iccTransmitApduLogicalChannel: Unknown exception");
698 }
699 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
704 request = (MainThreadRequest) msg.obj;
705 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000706 uiccPort = getUiccPortFromRequest(request);
707 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 } else {
712 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000714 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800715 iccArgument.cla, iccArgument.command, iccArgument.p1,
716 iccArgument.p2,
717 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 }
719 break;
720
721 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result;
726 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800727 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 if (ar.result == null) {
729 loge("iccTransmitApduBasicChannel: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("iccTransmitApduBasicChannel: CommandException: " +
732 ar.exception);
733 } else {
734 loge("iccTransmitApduBasicChannel: Unknown exception");
735 }
736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 break;
739
740 case CMD_EXCHANGE_SIM_IO:
741 request = (MainThreadRequest) msg.obj;
742 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
744 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700745 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800746 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700748 } else {
749 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
750 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000751 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700752 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
753 iccArgument.data, onCompleted);
754 }
755 break;
756
757 case EVENT_EXCHANGE_SIM_IO_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result;
762 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800763 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 break;
767
Derek Tan4d5e5c12014-02-04 11:54:58 -0800768 case CMD_SEND_ENVELOPE:
769 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000770 uiccPort = getUiccPortFromRequest(request);
771 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800773 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 } else {
776 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800777 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700778 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800779 break;
780
781 case EVENT_SEND_ENVELOPE_DONE:
782 ar = (AsyncResult) msg.obj;
783 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700784 if (ar.exception == null && ar.result != null) {
785 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800786 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800787 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700788 if (ar.result == null) {
789 loge("sendEnvelopeWithStatus: Empty response");
790 } else if (ar.exception instanceof CommandException) {
791 loge("sendEnvelopeWithStatus: CommandException: " +
792 ar.exception);
793 } else {
794 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
795 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800796 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800798 break;
799
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 case CMD_OPEN_CHANNEL:
801 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000802 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800803 IccLogicalChannelRequest openChannelRequest =
804 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000805 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800807 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800808 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700809 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700810 } else {
811 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800812 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
813 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 break;
816
817 case EVENT_OPEN_CHANNEL_DONE:
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700820 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700822 int[] result = (int[]) ar.result;
823 int channelId = result[0];
824 byte[] selectResponse = null;
825 if (result.length > 1) {
826 selectResponse = new byte[result.length - 1];
827 for (int i = 1; i < result.length; ++i) {
828 selectResponse[i - 1] = (byte) result[i];
829 }
830 }
831 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800832 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800833
834 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700835 if (uiccPort == null) {
836 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
837 } else {
838 IccLogicalChannelRequest channelRequest =
839 (IccLogicalChannelRequest) request.argument;
840 channelRequest.channel = channelId;
841 uiccPort.onLogicalChannelOpened(channelRequest);
842 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 if (ar.result == null) {
845 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700847 if (ar.exception != null) {
848 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
849 }
850
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700852 if (ar.exception instanceof CommandException) {
853 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800854 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700855 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700856 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700857 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700858 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700859 }
860 }
861 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800862 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700864 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700865 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700866 break;
867
868 case CMD_CLOSE_CHANNEL:
869 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000870 uiccPort = getUiccPortFromRequest(request);
871 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700872 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800873 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800874 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800875 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700876 } else {
877 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000878 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700879 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 break;
881
882 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null) {
886 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800887 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700888 if (uiccPort == null) {
889 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
890 } else {
891 final int channelId = (Integer) request.argument;
892 uiccPort.onLogicalChannelClosed(channelId);
893 }
Chen Xu540470b2021-12-14 17:15:47 -0800894 } else {
895 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800896 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800897 if (ar.exception instanceof CommandException) {
898 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
899 CommandException.Error error =
900 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800901 if (error == CommandException.Error.INVALID_ARGUMENTS) {
902 // should only throw exceptions from the binder threads.
903 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800904 "iccCloseLogicalChannel: invalid argument ");
905 }
906 } else {
907 loge("iccCloseLogicalChannel: Unknown exception");
908 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800909 request.result = (exception != null) ? exception :
910 new IllegalStateException(
911 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800912 }
913 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
916 case CMD_NV_READ_ITEM:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
920 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
923 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 ar = (AsyncResult) msg.obj;
925 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800926 if (ar.exception == null && ar.result != null) {
927 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800929 request.result = "";
930 if (ar.result == null) {
931 loge("nvReadItem: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("nvReadItem: CommandException: " +
934 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800936 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700940 break;
941
Jake Hambye994d462014-02-03 13:10:13 -0800942 case CMD_NV_WRITE_ITEM:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
945 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800946 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700947 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800948 break;
949
950 case EVENT_NV_WRITE_ITEM_DONE:
951 handleNullReturnEvent(msg, "nvWriteItem");
952 break;
953
954 case CMD_NV_WRITE_CDMA_PRL:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800957 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800958 break;
959
960 case EVENT_NV_WRITE_CDMA_PRL_DONE:
961 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
962 break;
963
chen xu6dac5ab2018-10-26 17:39:23 -0700964 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800965 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700966 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800967 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800968 break;
969
chen xu6dac5ab2018-10-26 17:39:23 -0700970 case EVENT_RESET_MODEM_CONFIG_DONE:
971 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800972 break;
973
Sooraj Sasindran37444802020-08-11 10:40:43 -0700974 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
977 request);
978 Phone phone = getPhoneFromRequest(request);
979 if (phone != null) {
980 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
981 } else {
982 loge("isNRDualConnectivityEnabled: No phone object");
983 request.result = false;
984 notifyRequester(request);
985 }
986 break;
987 }
988
989 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null && ar.result != null) {
993 request.result = ar.result;
994 } else {
995 // request.result must be set to something non-null
996 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700997 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700998 request.result = ar.result;
999 } else {
1000 request.result = false;
1001 }
1002 if (ar.result == null) {
1003 loge("isNRDualConnectivityEnabled: Empty response");
1004 } else if (ar.exception instanceof CommandException) {
1005 loge("isNRDualConnectivityEnabled: CommandException: "
1006 + ar.exception);
1007 } else {
1008 loge("isNRDualConnectivityEnabled: Unknown exception");
1009 }
1010 }
1011 notifyRequester(request);
1012 break;
1013
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001014 case CMD_IS_VONR_ENABLED: {
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1017 request);
1018 Phone phone = getPhoneFromRequest(request);
1019 if (phone != null) {
1020 phone.isVoNrEnabled(onCompleted, request.workSource);
1021 } else {
1022 loge("isVoNrEnabled: No phone object");
1023 request.result = false;
1024 notifyRequester(request);
1025 }
1026 break;
1027 }
1028
1029 case EVENT_IS_VONR_ENABLED_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null && ar.result != null) {
1033 request.result = ar.result;
1034 } else {
1035 // request.result must be set to something non-null
1036 // for the calling thread to unblock
1037 if (ar.result != null) {
1038 request.result = ar.result;
1039 } else {
1040 request.result = false;
1041 }
1042 if (ar.result == null) {
1043 loge("isVoNrEnabled: Empty response");
1044 } else if (ar.exception instanceof CommandException) {
1045 loge("isVoNrEnabled: CommandException: "
1046 + ar.exception);
1047 } else {
1048 loge("isVoNrEnabled: Unknown exception");
1049 }
1050 }
1051 notifyRequester(request);
1052 break;
1053
Sooraj Sasindran37444802020-08-11 10:40:43 -07001054 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1057 Phone phone = getPhoneFromRequest(request);
1058 if (phone != null) {
1059 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1060 request.workSource);
1061 } else {
1062 loge("enableNrDualConnectivity: No phone object");
1063 request.result =
1064 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1065 notifyRequester(request);
1066 }
1067 break;
1068 }
1069
1070 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
1073 if (ar.exception == null) {
1074 request.result =
1075 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1076 } else {
1077 request.result =
1078 TelephonyManager
1079 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1080 if (ar.exception instanceof CommandException) {
1081 CommandException.Error error =
1082 ((CommandException) (ar.exception)).getCommandError();
1083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1084 request.result =
1085 TelephonyManager
1086 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001087 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1088 request.result =
1089 TelephonyManager
1090 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001091 }
1092 loge("enableNrDualConnectivity" + ": CommandException: "
1093 + ar.exception);
1094 } else {
1095 loge("enableNrDualConnectivity" + ": Unknown exception");
1096 }
1097 }
1098 notifyRequester(request);
1099 break;
1100 }
1101
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001102 case CMD_ENABLE_VONR: {
1103 request = (MainThreadRequest) msg.obj;
1104 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1105 Phone phone = getPhoneFromRequest(request);
1106 if (phone != null) {
1107 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1108 request.workSource);
1109 } else {
1110 loge("setVoNrEnabled: No phone object");
1111 request.result =
1112 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1113 notifyRequester(request);
1114 }
1115 break;
1116 }
1117
1118 case EVENT_ENABLE_VONR_DONE: {
1119 ar = (AsyncResult) msg.obj;
1120 request = (MainThreadRequest) ar.userObj;
1121 if (ar.exception == null) {
1122 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1123 } else {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1129 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1130 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1131 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1132 } else {
1133 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1134 }
1135 loge("setVoNrEnabled" + ": CommandException: "
1136 + ar.exception);
1137 } else {
1138 loge("setVoNrEnabled" + ": Unknown exception");
1139 }
1140 }
1141 notifyRequester(request);
1142 break;
1143 }
1144
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1148 request);
1149 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 break;
1151
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 if (ar.exception == null && ar.result != null) {
1156 request.result = ar.result; // Integer
1157 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301158 // request.result must be set to something non-null
1159 // for the calling thread to unblock
1160 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 loge("getAllowedNetworkTypesBitmask: CommandException: "
1165 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001167 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 }
1169 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 break;
1172
SongFerngWang3ef3e072020-12-21 16:41:52 +08001173 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1176 request);
1177 Pair<Integer, Long> reasonWithNetworkTypes =
1178 (Pair<Integer, Long>) request.argument;
1179 getPhoneFromRequest(request).setAllowedNetworkTypes(
1180 reasonWithNetworkTypes.first,
1181 reasonWithNetworkTypes.second,
1182 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001183 break;
1184
SongFerngWang3ef3e072020-12-21 16:41:52 +08001185 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1186 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001187 break;
1188
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001189 case CMD_SET_VOICEMAIL_NUMBER:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1192 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001193 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1194 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001195 break;
1196
1197 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1198 handleNullReturnEvent(msg, "setVoicemailNumber");
1199 break;
1200
Stuart Scott54788802015-03-30 13:18:01 -07001201 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1204 request);
1205 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1206 break;
1207
1208 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1209 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1210 break;
1211
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 case CMD_PERFORM_NETWORK_SCAN:
1213 request = (MainThreadRequest) msg.obj;
1214 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1215 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1216 break;
1217
Hall Liu27d24262020-09-18 19:04:59 -07001218 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001221 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1222 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1223 request.argument;
1224 int callForwardingReason = args.first;
1225 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
Hall Liu27d24262020-09-18 19:04:59 -07001227 }
1228 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001229 ar = (AsyncResult) msg.obj;
1230 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001231 TelephonyManager.CallForwardingInfoCallback callback =
1232 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1233 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001235 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001236 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1237 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1238 // Service Class is a bit mask per 3gpp 27.007. Search for
1239 // any service for voice call.
1240 if ((callForwardInfo.serviceClass
1241 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001242 callForwardingInfo = new CallForwardingInfo(
1243 callForwardInfo.status
1244 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001245 callForwardInfo.reason,
1246 callForwardInfo.number,
1247 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
1249 }
1250 }
1251 // Didn't find a call forward info for voice call.
1252 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001253 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1254 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
Hall Liu27d24262020-09-18 19:04:59 -07001256 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 } else {
1258 if (ar.result == null) {
1259 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1260 }
1261 if (ar.exception != null) {
1262 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1263 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001264 int errorCode = TelephonyManager
1265 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager
1271 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001273 errorCode = TelephonyManager
1274 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
1276 }
Hall Liu27d24262020-09-18 19:04:59 -07001277 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281
Hall Liu27d24262020-09-18 19:04:59 -07001282 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001283 request = (MainThreadRequest) msg.obj;
1284 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001285 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001286 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001287 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1288 request.argument).first;
1289 request.phone.setCallForwardingOption(
1290 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001291 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001292 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001293 callForwardingInfoToSet.getReason(),
1294 callForwardingInfoToSet.getNumber(),
1295 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1296 break;
Hall Liu27d24262020-09-18 19:04:59 -07001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298
Hall Liu27d24262020-09-18 19:04:59 -07001299 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001300 ar = (AsyncResult) msg.obj;
1301 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001302 Consumer<Integer> callback =
1303 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1304 request.argument).second;
1305 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001306 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001307 int errorCode = TelephonyManager.CallForwardingInfoCallback
1308 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001309 if (ar.exception instanceof CommandException) {
1310 CommandException.Error error =
1311 ((CommandException) (ar.exception)).getCommandError();
1312 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001313 errorCode = TelephonyManager.CallForwardingInfoCallback
1314 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001315 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001316 errorCode = TelephonyManager.CallForwardingInfoCallback
1317 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
1319 }
1320 callback.accept(errorCode);
1321 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001322 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001323 }
Shuo Qian4a594052020-01-23 11:59:30 -08001324 break;
Hall Liu27d24262020-09-18 19:04:59 -07001325 }
Shuo Qian4a594052020-01-23 11:59:30 -08001326
Hall Liu27d24262020-09-18 19:04:59 -07001327 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001328 request = (MainThreadRequest) msg.obj;
1329 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1330 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1331 break;
Hall Liu27d24262020-09-18 19:04:59 -07001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333
Hall Liu27d24262020-09-18 19:04:59 -07001334 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001337 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001340 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 // Service Class is a bit mask per 3gpp 27.007.
1342 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001343 if (callForwardResults.length > 1
1344 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001345 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001347 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1348 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001349 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001350 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001351 }
1352 } else {
1353 if (ar.result == null) {
1354 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1355 }
1356 if (ar.exception != null) {
1357 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1358 }
1359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001363 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001364 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001365 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1366 callWaitingStatus =
1367 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001368 }
1369 }
1370 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001371 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001372 break;
Hall Liu27d24262020-09-18 19:04:59 -07001373 }
Shuo Qian4a594052020-01-23 11:59:30 -08001374
Hall Liu27d24262020-09-18 19:04:59 -07001375 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001376 request = (MainThreadRequest) msg.obj;
1377 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001378 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1379 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001380 break;
Hall Liu27d24262020-09-18 19:04:59 -07001381 }
Shuo Qian4a594052020-01-23 11:59:30 -08001382
Hall Liu27d24262020-09-18 19:04:59 -07001383 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001386 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1387 Consumer<Integer> callback =
1388 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1389 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001390 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001391 if (ar.exception instanceof CommandException) {
1392 CommandException.Error error =
1393 ((CommandException) (ar.exception)).getCommandError();
1394 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001396 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1397 callback.accept(
1398 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001399 } else {
1400 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1401 }
1402 } else {
1403 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1404 }
1405 } else {
1406 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1407 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001408 }
Shuo Qian4a594052020-01-23 11:59:30 -08001409 break;
Hall Liu27d24262020-09-18 19:04:59 -07001410 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001411 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 CellNetworkScanResult cellScanResult;
1415 if (ar.exception == null && ar.result != null) {
1416 cellScanResult = new CellNetworkScanResult(
1417 CellNetworkScanResult.STATUS_SUCCESS,
1418 (List<OperatorInfo>) ar.result);
1419 } else {
1420 if (ar.result == null) {
1421 loge("getCellNetworkScanResults: Empty response");
1422 }
1423 if (ar.exception != null) {
1424 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1425 }
1426 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1427 if (ar.exception instanceof CommandException) {
1428 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001429 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1431 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1432 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1433 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1434 }
1435 }
1436 cellScanResult = new CellNetworkScanResult(errorCode, null);
1437 }
1438 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001440 break;
1441
1442 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1443 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001444 ManualNetworkSelectionArgument selArg =
1445 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001446 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1447 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001448 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1449 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001450 break;
1451
1452 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 if (ar.exception == null) {
1456 request.result = true;
1457 } else {
1458 request.result = false;
1459 loge("setNetworkSelectionModeManual " + ar.exception);
1460 }
1461 notifyRequester(request);
1462 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001463 break;
1464
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 case CMD_GET_MODEM_ACTIVITY_INFO:
1466 request = (MainThreadRequest) msg.obj;
1467 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001468 if (defaultPhone != null) {
1469 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001470 } else {
1471 ResultReceiver result = (ResultReceiver) request.argument;
1472 Bundle bundle = new Bundle();
1473 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001474 new ModemActivityInfo(0, 0, 0,
1475 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001476 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001477 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 break;
1479
Hall Liud0f208c2020-10-14 16:54:44 -07001480 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001481 ar = (AsyncResult) msg.obj;
1482 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001483 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001484 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001485 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001486 if (mLastModemActivityInfo == null) {
1487 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1488 mLastModemActivitySpecificInfo[0] =
1489 new ActivityStatsTechSpecificInfo(
1490 0,
1491 0,
1492 new int[ModemActivityInfo.getNumTxPowerLevels()],
1493 0);
1494 mLastModemActivityInfo =
1495 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1496 }
1497
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001498 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001499 // Update the last modem activity info and the result of the request.
1500 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1501 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001502 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001503 } else {
1504 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001505 }
Kai Shi917fdc62022-11-28 14:01:02 -08001506 // This is needed to decouple ret from mLastModemActivityInfo
1507 // We don't want to return mLastModemActivityInfo which is updated
1508 // inside mergeModemActivityInfo()
1509 ret = new ModemActivityInfo(
1510 mLastModemActivityInfo.getTimestampMillis(),
1511 mLastModemActivityInfo.getSleepTimeMillis(),
1512 mLastModemActivityInfo.getIdleTimeMillis(),
1513 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001514
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else {
1516 if (ar.result == null) {
1517 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001518 error = TelephonyManager.ModemActivityInfoException
1519 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001521 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001522 error = TelephonyManager.ModemActivityInfoException
1523 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524 } else {
1525 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001526 error = TelephonyManager.ModemActivityInfoException
1527 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001528 }
1529 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001530 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001531 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001532 bundle.putParcelable(
1533 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001534 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001535 } else {
1536 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1537 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001538 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001539 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001540 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001541 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001542
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001543 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001545 CarrierRestrictionRules argument =
1546 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001548 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001550 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551
1552 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1553 ar = (AsyncResult) msg.obj;
1554 request = (MainThreadRequest) ar.userObj;
1555 if (ar.exception == null && ar.result != null) {
1556 request.result = ar.result;
1557 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001558 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1559 if (ar.exception instanceof CommandException) {
1560 loge("setAllowedCarriers: CommandException: " + ar.exception);
1561 CommandException.Error error =
1562 ((CommandException) (ar.exception)).getCommandError();
1563 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1564 request.result =
1565 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1566 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 } else {
1568 loge("setAllowedCarriers: Unknown exception");
1569 }
1570 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001572 break;
1573
1574 case CMD_GET_ALLOWED_CARRIERS:
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001577 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001578 break;
1579
1580 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1581 ar = (AsyncResult) msg.obj;
1582 request = (MainThreadRequest) ar.userObj;
1583 if (ar.exception == null && ar.result != null) {
1584 request.result = ar.result;
1585 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001586 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001587 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001588 if (ar.result == null) {
1589 loge("getAllowedCarriers: Empty response");
1590 } else if (ar.exception instanceof CommandException) {
1591 loge("getAllowedCarriers: CommandException: " +
1592 ar.exception);
1593 } else {
1594 loge("getAllowedCarriers: Unknown exception");
1595 }
1596 }
arunvoddud7401012022-12-15 16:08:12 +00001597 if (request.argument != null) {
1598 // This is for the implementation of carrierRestrictionStatus.
1599 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1600 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001601 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001602 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1603 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1604 CarrierRestrictionRules carrierRestrictionRules =
1605 (CarrierRestrictionRules) ar.result;
1606 int carrierId = -1;
1607 try {
1608 CarrierIdentifier carrierIdentifier =
1609 carrierRestrictionRules.getAllowedCarriers().get(0);
1610 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1611 carrierIdentifier);
1612 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1613 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1614 }
1615 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001616 int restrictedStatus =
1617 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1618 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1619 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001620 lockStatus = TelephonyManager
1621 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001622 }
1623 } else {
1624 Rlog.e(LOG_TAG,
1625 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1626 }
1627 callback.accept(lockStatus);
1628 } else {
1629 // This is for the implementation of getAllowedCarriers.
1630 notifyRequester(request);
1631 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001632 break;
1633
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1635 ar = (AsyncResult) msg.obj;
1636 request = (MainThreadRequest) ar.userObj;
1637 if (ar.exception == null && ar.result != null) {
1638 request.result = ar.result;
1639 } else {
1640 request.result = new IllegalArgumentException(
1641 "Failed to retrieve Forbidden Plmns");
1642 if (ar.result == null) {
1643 loge("getForbiddenPlmns: Empty response");
1644 } else {
1645 loge("getForbiddenPlmns: Unknown exception");
1646 }
1647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001648 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 break;
1650
1651 case CMD_GET_FORBIDDEN_PLMNS:
1652 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 uiccPort = getUiccPortFromRequest(request);
1654 if (uiccPort == null) {
1655 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001657 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 break;
1660 }
1661 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001662 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 if (uiccApp == null) {
1664 loge("getForbiddenPlmns() no app with specified type -- "
1665 + appType);
1666 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001667 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001668 break;
1669 } else {
1670 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1671 + " specified type -- " + appType);
1672 }
1673 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1674 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001675 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001676 break;
1677
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 case CMD_SWITCH_SLOTS:
1679 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001680 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001681 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001682 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001683 break;
1684
1685 case EVENT_SWITCH_SLOTS_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001689 notifyRequester(request);
1690 break;
1691 case CMD_GET_NETWORK_SELECTION_MODE:
1692 request = (MainThreadRequest) msg.obj;
1693 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1694 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1695 break;
1696
1697 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception != null) {
1701 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1702 } else {
1703 int mode = ((int[]) ar.result)[0];
1704 if (mode == 0) {
1705 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1706 } else {
1707 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1708 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001710 notifyRequester(request);
1711 break;
1712 case CMD_GET_CDMA_ROAMING_MODE:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1715 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1716 break;
1717 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1718 ar = (AsyncResult) msg.obj;
1719 request = (MainThreadRequest) ar.userObj;
1720 if (ar.exception != null) {
1721 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1722 } else {
1723 request.result = ((int[]) ar.result)[0];
1724 }
1725 notifyRequester(request);
1726 break;
1727 case CMD_SET_CDMA_ROAMING_MODE:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1730 int mode = (int) request.argument;
1731 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1732 break;
1733 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 request.result = ar.exception == null;
1737 notifyRequester(request);
1738 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001739 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1740 request = (MainThreadRequest) msg.obj;
1741 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1742 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1743 break;
1744 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1745 ar = (AsyncResult) msg.obj;
1746 request = (MainThreadRequest) ar.userObj;
1747 if (ar.exception != null) {
1748 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1749 } else {
1750 request.result = ((int[]) ar.result)[0];
1751 }
1752 notifyRequester(request);
1753 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001754 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1755 request = (MainThreadRequest) msg.obj;
1756 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1757 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001758 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1759 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001760 break;
1761 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 request.result = ar.exception == null;
1765 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001766 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 case CMD_GET_ALL_CELL_INFO:
1768 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001770 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001771 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001772 case EVENT_GET_ALL_CELL_INFO_DONE:
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001775 // If a timeout occurs, the response will be null
1776 request.result = (ar.exception == null && ar.result != null)
1777 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001778 synchronized (request) {
1779 request.notifyAll();
1780 }
1781 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001782 case CMD_REQUEST_CELL_INFO_UPDATE:
1783 request = (MainThreadRequest) msg.obj;
1784 request.phone.requestCellInfoUpdate(request.workSource,
1785 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1786 break;
1787 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1791 try {
1792 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001794 cb.onError(
1795 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1796 ar.exception.getClass().getName(),
1797 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001798 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001799 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001800 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001801 } else {
1802 // use the result as returned
1803 cb.onCellInfo((List<CellInfo>) ar.result);
1804 }
1805 } catch (RemoteException re) {
1806 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1807 }
1808 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 request = (MainThreadRequest) msg.obj;
1811 WorkSource ws = (WorkSource) request.argument;
1812 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001813 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001814 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001815 }
1816 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null) {
1820 request.result = ar.result;
1821 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001823 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001824 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001825 }
1826
1827 synchronized (request) {
1828 request.notifyAll();
1829 }
1830 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001831 }
chen xu6dac5ab2018-10-26 17:39:23 -07001832 case CMD_MODEM_REBOOT:
1833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001835 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001836 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001837 case EVENT_CMD_MODEM_REBOOT_DONE:
1838 handleNullReturnEvent(msg, "rebootModem");
1839 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001840 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 request = (MainThreadRequest) msg.obj;
1842 boolean enable = (boolean) request.argument;
1843 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001844 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001845 PhoneConfigurationManager.getInstance()
1846 .enablePhone(request.phone, enable, onCompleted);
1847 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001848 }
Michele Berionne5e411512020-11-13 02:36:59 +00001849 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001853 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001854 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001855 if ((boolean) request.result) {
1856 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1857 updateModemStateMetrics();
1858 } else {
1859 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1860 + ar.exception);
1861 }
1862 notifyRequester(request);
1863 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001865 case CMD_GET_MODEM_STATUS:
1866 request = (MainThreadRequest) msg.obj;
1867 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1868 PhoneConfigurationManager.getInstance()
1869 .getPhoneStatusFromModem(request.phone, onCompleted);
1870 break;
1871 case EVENT_GET_MODEM_STATUS_DONE:
1872 ar = (AsyncResult) msg.obj;
1873 request = (MainThreadRequest) ar.userObj;
1874 int id = request.phone.getPhoneId();
1875 if (ar.exception == null && ar.result != null) {
1876 request.result = ar.result;
1877 //update the cache as modem status has changed
1878 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1879 (boolean) request.result);
1880 } else {
1881 // Return true if modem status cannot be retrieved. For most cases,
1882 // modem status is on. And for older version modems, GET_MODEM_STATUS
1883 // and disable modem are not supported. Modem is always on.
1884 // TODO: this should be fixed in R to support a third
1885 // status UNKNOWN b/131631629
1886 request.result = true;
1887 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1888 + ar.exception);
1889 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001890 notifyRequester(request);
1891 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001892 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1895 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1896 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1897 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1898 break;
1899 }
1900 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1901 ar = (AsyncResult) msg.obj;
1902 request = (MainThreadRequest) ar.userObj;
1903 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1904 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1905 args.second.accept(ar.exception == null);
1906 notifyRequester(request);
1907 break;
1908 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001909 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1912 Phone phone = getPhoneFromRequest(request);
1913 if (phone != null) {
1914 phone.getSystemSelectionChannels(onCompleted);
1915 } else {
1916 loge("getSystemSelectionChannels: No phone object");
1917 request.result = new ArrayList<RadioAccessSpecifier>();
1918 notifyRequester(request);
1919 }
1920 break;
1921 }
1922 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 if (ar.exception == null && ar.result != null) {
1926 request.result = ar.result;
1927 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001928 request.result = new IllegalStateException(
1929 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001930 if (ar.result == null) {
1931 loge("getSystemSelectionChannels: Empty response");
1932 } else {
1933 loge("getSystemSelectionChannels: Unknown exception");
1934 }
1935 }
1936 notifyRequester(request);
1937 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001938 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 if (ar.exception == null && ar.result != null) {
1942 request.result = ar.result;
1943 } else {
1944 request.result = -1;
1945 loge("Failed to set Forbidden Plmns");
1946 if (ar.result == null) {
1947 loge("setForbidenPlmns: Empty response");
1948 } else if (ar.exception != null) {
1949 loge("setForbiddenPlmns: Exception: " + ar.exception);
1950 request.result = -1;
1951 } else {
1952 loge("setForbiddenPlmns: Unknown exception");
1953 }
1954 }
1955 notifyRequester(request);
1956 break;
1957 case CMD_SET_FORBIDDEN_PLMNS:
1958 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001959 uiccPort = getUiccPortFromRequest(request);
1960 if (uiccPort == null) {
1961 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001962 request.result = -1;
1963 notifyRequester(request);
1964 break;
1965 }
1966 Pair<Integer, List<String>> setFplmnsArgs =
1967 (Pair<Integer, List<String>>) request.argument;
1968 appType = setFplmnsArgs.first;
1969 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001970 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001971 if (uiccApp == null) {
1972 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1973 request.result = -1;
1974 loge("Failed to get UICC App");
1975 notifyRequester(request);
1976 } else {
1977 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1978 ((SIMRecords) uiccApp.getIccRecords())
1979 .setForbiddenPlmns(onCompleted, fplmns);
1980 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001981 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001982 case CMD_ERASE_MODEM_CONFIG:
1983 request = (MainThreadRequest) msg.obj;
1984 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1985 defaultPhone.eraseModemConfig(onCompleted);
1986 break;
1987 case EVENT_ERASE_MODEM_CONFIG_DONE:
1988 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001989 break;
zoey chene02881a2019-12-30 16:11:23 +08001990
Kai Shif70f46f2021-03-03 13:59:46 -08001991 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1992 request = (MainThreadRequest) msg.obj;
1993 request.result = defaultPhone.eraseDataInSharedPreferences();
1994 notifyRequester(request);
1995 break;
1996
zoey chene02881a2019-12-30 16:11:23 +08001997 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2000 Pair<String, String> changed = (Pair<String, String>) request.argument;
2001 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2002 changed.first, changed.second, onCompleted);
2003 break;
2004 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 if (ar.exception == null) {
2008 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002009 // If the operation is successful, update the PIN storage
2010 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2011 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002012 UiccController.getInstance().getPinStorage()
2013 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002014 } else {
2015 request.result = msg.arg1;
2016 }
2017 notifyRequester(request);
2018 break;
2019
Michele Berionne5e411512020-11-13 02:36:59 +00002020 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002021 request = (MainThreadRequest) msg.obj;
2022 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2023 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2024 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2025 enabled.first, enabled.second, onCompleted);
2026 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002027 }
zoey chene02881a2019-12-30 16:11:23 +08002028 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 if (ar.exception == null) {
2032 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002033 // If the operation is successful, update the PIN storage
2034 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2035 int phoneId = getPhoneFromRequest(request).getPhoneId();
2036 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002037 UiccController.getInstance().getPinStorage()
2038 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002039 } else {
2040 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2041 }
zoey chene02881a2019-12-30 16:11:23 +08002042 } else {
2043 request.result = msg.arg1;
2044 }
Michele Berionne5e411512020-11-13 02:36:59 +00002045
2046
zoey chene02881a2019-12-30 16:11:23 +08002047 notifyRequester(request);
2048 break;
2049
Peter Wangdafb9ac2020-01-15 14:13:38 -08002050 case MSG_NOTIFY_USER_ACTIVITY:
2051 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002052 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002053 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2054 getDefaultPhone().getContext().sendBroadcastAsUser(
2055 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2056 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002057
2058 case CMD_SET_DATA_THROTTLING: {
2059 request = (MainThreadRequest) msg.obj;
2060 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2061 DataThrottlingRequest dataThrottlingRequest =
2062 (DataThrottlingRequest) request.argument;
2063 Phone phone = getPhoneFromRequest(request);
2064 if (phone != null) {
2065 phone.setDataThrottling(onCompleted,
2066 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2067 dataThrottlingRequest.getCompletionDurationMillis());
2068 } else {
2069 loge("setDataThrottling: No phone object");
2070 request.result =
2071 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2072 notifyRequester(request);
2073 }
2074
2075 break;
2076 }
2077 case EVENT_SET_DATA_THROTTLING_DONE:
2078 ar = (AsyncResult) msg.obj;
2079 request = (MainThreadRequest) ar.userObj;
2080
2081 if (ar.exception == null) {
2082 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2083 } else if (ar.exception instanceof CommandException) {
2084 loge("setDataThrottling: CommandException: " + ar.exception);
2085 CommandException.Error error =
2086 ((CommandException) (ar.exception)).getCommandError();
2087
2088 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2089 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002090 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002091 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2092 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002093 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2094 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002095 } else {
2096 request.result =
2097 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2098 }
2099 } else {
2100 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2101 }
2102 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2103 notifyRequester(request);
2104 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002105
2106 case CMD_SET_SIM_POWER: {
2107 request = (MainThreadRequest) msg.obj;
2108 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2109 request = (MainThreadRequest) msg.obj;
2110 int stateToSet =
2111 ((Pair<Integer, IIntegerConsumer>)
2112 request.argument).first;
2113 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2114 break;
2115 }
2116 case EVENT_SET_SIM_POWER_DONE: {
2117 ar = (AsyncResult) msg.obj;
2118 request = (MainThreadRequest) ar.userObj;
2119 IIntegerConsumer callback =
2120 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2121 if (ar.exception != null) {
2122 loge("setSimPower exception: " + ar.exception);
2123 int errorCode = TelephonyManager.CallForwardingInfoCallback
2124 .RESULT_ERROR_UNKNOWN;
2125 if (ar.exception instanceof CommandException) {
2126 CommandException.Error error =
2127 ((CommandException) (ar.exception)).getCommandError();
2128 if (error == CommandException.Error.SIM_ERR) {
2129 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2130 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2132 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2133 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2134 } else {
2135 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2136 }
2137 }
2138 try {
2139 callback.accept(errorCode);
2140 } catch (RemoteException e) {
2141 // Ignore if the remote process is no longer available to call back.
2142 Log.w(LOG_TAG, "setSimPower: callback not available.");
2143 }
2144 } else {
2145 try {
2146 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2147 } catch (RemoteException e) {
2148 // Ignore if the remote process is no longer available to call back.
2149 Log.w(LOG_TAG, "setSimPower: callback not available.");
2150 }
2151 }
2152 break;
2153 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002154 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2155 request = (MainThreadRequest) msg.obj;
2156
2157 final Phone phone = getPhoneFromRequest(request);
2158 if (phone == null || phone.getServiceStateTracker() == null) {
2159 request.result = new IllegalStateException("Phone or SST is null");
2160 notifyRequester(request);
2161 break;
2162 }
2163
2164 Pair<Integer, SignalStrengthUpdateRequest> pair =
2165 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2166 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2167 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002168 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002169 request.subId, pair.first /*callingUid*/,
2170 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002171 break;
2172 }
2173 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2174 ar = (AsyncResult) msg.obj;
2175 request = (MainThreadRequest) ar.userObj;
2176 // request.result will be the exception of ar if present, true otherwise.
2177 // Be cautious not to leave result null which will wait() forever
2178 request.result = ar.exception != null ? ar.exception : true;
2179 notifyRequester(request);
2180 break;
2181 }
2182 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2183 request = (MainThreadRequest) msg.obj;
2184
2185 Phone phone = getPhoneFromRequest(request);
2186 if (phone == null || phone.getServiceStateTracker() == null) {
2187 request.result = new IllegalStateException("Phone or SST is null");
2188 notifyRequester(request);
2189 break;
2190 }
2191
2192 Pair<Integer, SignalStrengthUpdateRequest> pair =
2193 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2194 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2195 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002196 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002197 request.subId, pair.first /*callingUid*/,
2198 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002199 break;
2200 }
2201 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2202 ar = (AsyncResult) msg.obj;
2203 request = (MainThreadRequest) ar.userObj;
2204 request.result = ar.exception != null ? ar.exception : true;
2205 notifyRequester(request);
2206 break;
2207 }
Jordan Liu109698e2020-11-24 14:50:34 -08002208
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 case CMD_GET_SLICING_CONFIG: {
2210 request = (MainThreadRequest) msg.obj;
2211 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2212 request.phone.getSlicingConfig(onCompleted);
2213 break;
2214 }
2215 case EVENT_GET_SLICING_CONFIG_DONE: {
2216 ar = (AsyncResult) msg.obj;
2217 request = (MainThreadRequest) ar.userObj;
2218 ResultReceiver result = (ResultReceiver) request.argument;
2219
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002221 Bundle bundle = new Bundle();
2222 int resultCode = 0;
2223 if (ar.exception != null) {
2224 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2225 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002226 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002227 } else if (ar.result == null) {
2228 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002229 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002230 } else {
2231 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002232 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2233 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002234 }
2235
2236 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002237 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002238 }
2239 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2240 result.send(resultCode, bundle);
2241 notifyRequester(request);
2242 break;
2243 }
2244
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 request = (MainThreadRequest) msg.obj;
2247 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 PurchasePremiumCapabilityArgument arg =
2249 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002250 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2251 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 ar = (AsyncResult) msg.obj;
2257 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 PurchasePremiumCapabilityArgument arg =
2259 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002260 try {
2261 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002262 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002265 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002266 + TelephonyManager.convertPurchaseResultToString(result));
2267 } catch (RemoteException e) {
2268 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002269 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002270 + " failed: " + e;
2271 if (DBG) log(logStr);
2272 AnomalyReporter.reportAnomaly(
2273 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2274 }
2275 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002276 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002277
Michele Berionne5e411512020-11-13 02:36:59 +00002278 case CMD_PREPARE_UNATTENDED_REBOOT:
2279 request = (MainThreadRequest) msg.obj;
2280 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002281 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002282 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002283 notifyRequester(request);
2284 break;
2285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 default:
2287 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2288 break;
2289 }
2290 }
Jake Hambye994d462014-02-03 13:10:13 -08002291
Pengquan Menga1bb6272018-09-06 09:59:22 -07002292 private void notifyRequester(MainThreadRequest request) {
2293 synchronized (request) {
2294 request.notifyAll();
2295 }
2296 }
2297
Jake Hambye994d462014-02-03 13:10:13 -08002298 private void handleNullReturnEvent(Message msg, String command) {
2299 AsyncResult ar = (AsyncResult) msg.obj;
2300 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2301 if (ar.exception == null) {
2302 request.result = true;
2303 } else {
2304 request.result = false;
2305 if (ar.exception instanceof CommandException) {
2306 loge(command + ": CommandException: " + ar.exception);
2307 } else {
2308 loge(command + ": Unknown exception");
2309 }
2310 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002311 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete, and returns the result.
2318 * @see #sendRequestAsync
2319 */
2320 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2322 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002323 }
2324
2325 /**
2326 * Posts the specified command to be executed on the main thread,
2327 * waits for the request to complete, and returns the result.
2328 * @see #sendRequestAsync
2329 */
2330 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2331 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002340 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2342 }
2343
2344 /**
2345 * Posts the specified command to be executed on the main thread,
2346 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2347 * if not timeout or null otherwise.
2348 * @see #sendRequestAsync
2349 */
2350 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2351 long timeoutInMs) {
2352 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002353 }
2354
2355 /**
2356 * Posts the specified command to be executed on the main thread,
2357 * waits for the request to complete, and returns the result.
2358 * @see #sendRequestAsync
2359 */
Nathan Harold92bed182018-10-12 18:16:49 -07002360 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002361 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002362 }
2363
2364 /**
2365 * Posts the specified command to be executed on the main thread,
2366 * waits for the request to complete, and returns the result.
2367 * @see #sendRequestAsync
2368 */
2369 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2371 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002372 }
2373
2374 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2376 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2377 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002378 * @see #sendRequestAsync
2379 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2381 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2383 throw new RuntimeException("This method will deadlock if called from the main thread.");
2384 }
2385
Nathan Harold92bed182018-10-12 18:16:49 -07002386 MainThreadRequest request = null;
2387 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2388 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2389 } else if (phone != null) {
2390 request = new MainThreadRequest(argument, phone, workSource);
2391 } else {
2392 request = new MainThreadRequest(argument, subId, workSource);
2393 }
2394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 Message msg = mMainThreadHandler.obtainMessage(command, request);
2396 msg.sendToTarget();
2397
Rambo Wang0f050d82021-02-12 11:43:36 -08002398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 if (timeoutInMs >= 0) {
2401 // Wait for at least timeoutInMs before returning null request result
2402 long now = SystemClock.elapsedRealtime();
2403 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002404 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002405 try {
2406 request.wait(deadline - now);
2407 } catch (InterruptedException e) {
2408 // Do nothing, go back and check if request is completed or timeout
2409 } finally {
2410 now = SystemClock.elapsedRealtime();
2411 }
2412 }
2413 } else {
2414 // Wait for the request to complete
2415 while (request.result == null) {
2416 try {
2417 request.wait();
2418 } catch (InterruptedException e) {
2419 // Do nothing, go back and wait until the request is complete
2420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422 }
2423 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002424 if (request.result == null) {
2425 Log.wtf(LOG_TAG,
2426 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 return request.result;
2429 }
2430
2431 /**
2432 * Asynchronous ("fire and forget") version of sendRequest():
2433 * Posts the specified command to be executed on the main thread, and
2434 * returns immediately.
2435 * @see #sendRequest
2436 */
2437 private void sendRequestAsync(int command) {
2438 mMainThreadHandler.sendEmptyMessage(command);
2439 }
2440
2441 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002442 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002443 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002444 */
2445 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002446 sendRequestAsync(command, argument, null, null);
2447 }
2448
2449 /**
2450 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2451 * @see {@link #sendRequest(int,Object)}
2452 */
2453 private void sendRequestAsync(
2454 int command, Object argument, Phone phone, WorkSource workSource) {
2455 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002456 Message msg = mMainThreadHandler.obtainMessage(command, request);
2457 msg.sendToTarget();
2458 }
2459
2460 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 * Initialize the singleton PhoneInterfaceManager instance.
2462 * This is only done once, at startup, from PhoneApp.onCreate().
2463 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 synchronized (PhoneInterfaceManager.class) {
2466 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002467 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 } else {
2469 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2470 }
2471 return sInstance;
2472 }
2473 }
2474
2475 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002476 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002478 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002479 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002481 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002482 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002483 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2485 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002486 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002487 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002488 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002489 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002490 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002491 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002492 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2493 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002494 mVendorApiLevel = SystemProperties.getInt(
2495 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2496
Tyler Gunn64144d92022-03-17 14:16:41 -07002497 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 publish();
arunvoddud7401012022-12-15 16:08:12 +00002499 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002500
2501 // Create the SatelliteEntitlementController singleton, for using the get the
2502 // entitlementStatus for satellite service.
2503 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002506 @VisibleForTesting
2507 public SharedPreferences getSharedPreferences() {
2508 return mTelephonySharedPreferences;
2509 }
2510
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002511 /**
2512 * Get the default phone for this device.
2513 */
2514 @VisibleForTesting
2515 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002516 Phone thePhone = getPhone(getDefaultSubscription());
2517 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2518 }
2519
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 private void publish() {
2521 if (DBG) log("publish: " + this);
2522
Peter Wangc035ce42020-01-08 21:00:22 -08002523 TelephonyFrameworkInitializer
2524 .getTelephonyServiceManager()
2525 .getTelephonyServiceRegisterer()
2526 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
Stuart Scott584921c2015-01-15 17:10:34 -08002529 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002530 if (request.phone != null) {
2531 return request.phone;
2532 } else {
2533 return getPhoneFromSubId(request.subId);
2534 }
2535 }
2536
2537 private Phone getPhoneFromSubId(int subId) {
2538 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2539 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002540 }
2541
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002542 /**
2543 * Get phone object associated with a subscription.
2544 * Return default phone if phone object associated with subscription is null
2545 * @param subId - subscriptionId
2546 * @return phone object associated with a subscription or default phone if null.
2547 */
Ling Mac28f0212023-03-24 16:07:15 -07002548 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002549 Phone phone = getPhoneFromSubId(subId);
2550 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002551 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002552 phone = getDefaultPhone();
2553 }
2554 return phone;
2555 }
2556
Rambo Wange53e07d2022-05-10 13:01:13 -07002557 @Nullable
2558 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002559 Phone phone = getPhoneFromRequest(request);
2560 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002561 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002562 }
2563
Ling Mac28f0212023-03-24 16:07:15 -07002564 /**
2565 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2566 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2567 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2568 * @return The Phone associated the sub Id
2569 */
2570 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002571 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573
Kai Shif70f46f2021-03-03 13:59:46 -08002574 private void sendEraseModemConfig(@NonNull Phone phone) {
2575 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2576 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2577 }
2578
2579 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2580 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2581 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002582 }
2583
Peter Wang44b186e2020-01-13 23:33:09 -08002584 private boolean isImsAvailableOnDevice() {
2585 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2586 if (pm == null) {
2587 // For some reason package manger is not available.. This will fail internally anyway,
2588 // so do not throw error and allow.
2589 return true;
2590 }
2591 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2592 }
2593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2596 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2597
Wink Savilleadd7cc52014-09-08 14:23:09 -07002598 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 if (DBG) log("dial: " + number);
2603 // No permission check needed here: This is just a wrapper around the
2604 // ACTION_DIAL intent, which is available to any app since it puts up
2605 // the UI before it does anything.
2606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 String url = createTelUrl(number);
2610 if (url == null) {
2611 return;
2612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 // PENDING: should we just silently fail if phone is offhook or ringing?
2615 PhoneConstants.State state = mCM.getState(subId);
2616 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2617 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2618 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002619 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 }
2624 }
2625
2626 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002627 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002628 }
2629
Wink Savilleb564aae2014-10-23 10:18:09 -07002630 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 if (DBG) log("call: " + number);
2632
2633 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002634 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 // from the context of the phone app.
2636 enforceCallPermission();
2637
Jordan Liu1617b712019-07-10 15:06:26 -07002638 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 != AppOpsManager.MODE_ALLOWED) {
2640 return;
2641 }
2642
joonhunshin4ac60942023-11-15 15:23:39 +00002643 enforceTelephonyFeatureWithException(callingPackage,
2644 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 String url = createTelUrl(number);
2649 if (url == null) {
2650 return;
2651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 boolean isValid = false;
2654 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2655 if (slist != null) {
2656 for (SubscriptionInfo subInfoRecord : slist) {
2657 if (subInfoRecord.getSubscriptionId() == subId) {
2658 isValid = true;
2659 break;
2660 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002661 }
Wink Saville08874612014-08-31 19:19:58 -07002662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 if (!isValid) {
2664 return;
2665 }
Wink Saville08874612014-08-31 19:19:58 -07002666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2668 intent.putExtra(SUBSCRIPTION_KEY, subId);
2669 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002670 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
Wink Savilleb564aae2014-10-23 10:18:09 -07002676 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002678 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002682 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002683 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2684 }
2685
Wink Savilleb564aae2014-10-23 10:18:09 -07002686 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
joonhunshin4ac60942023-11-15 15:23:39 +00002689 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2690 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2691 "supplyPinReportResultForSubscriber");
2692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 final long identity = Binder.clearCallingIdentity();
2694 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002695 Phone phone = getPhone(subId);
2696 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 checkSimPin.start();
2698 return checkSimPin.unlockSim(null, pin);
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 }
2703
Wink Savilleb564aae2014-10-23 10:18:09 -07002704 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706
joonhunshin4ac60942023-11-15 15:23:39 +00002707 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2708 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 final long identity = Binder.clearCallingIdentity();
2711 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002712 Phone phone = getPhone(subId);
2713 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 checkSimPuk.start();
2715 return checkSimPuk.unlockSim(puk, pin);
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
2718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 }
2720
2721 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002722 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 * a synchronous one.
2724 */
2725 private static class UnlockSim extends Thread {
2726
2727 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002728 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729
2730 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002731 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2732 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733
2734 // For replies from SimCard interface
2735 private Handler mHandler;
2736
2737 // For async handler to identify request type
2738 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002739 private static final int SUPPLY_PIN_DELAYED = 101;
2740 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2741 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2742 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743
Michele Berionne5e411512020-11-13 02:36:59 +00002744 UnlockSim(int phoneId, IccCard simCard) {
2745 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 mSimCard = simCard;
2747 }
2748
2749 @Override
2750 public void run() {
2751 Looper.prepare();
2752 synchronized (UnlockSim.this) {
2753 mHandler = new Handler() {
2754 @Override
2755 public void handleMessage(Message msg) {
2756 AsyncResult ar = (AsyncResult) msg.obj;
2757 switch (msg.what) {
2758 case SUPPLY_PIN_COMPLETE:
2759 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2760 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002761 mRetryCount = msg.arg1;
2762 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002763 CommandException.Error error = null;
2764 if (ar.exception instanceof CommandException) {
2765 error = ((CommandException) (ar.exception))
2766 .getCommandError();
2767 }
2768 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002769 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002770 } else if (error == CommandException.Error.ABORTED) {
2771 /* When UiccCardApp dispose, handle message and return
2772 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002773 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002774 } else {
2775 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2776 }
2777 } else {
2778 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002781 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 UnlockSim.this.notifyAll();
2783 }
2784 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002785 case SUPPLY_PIN_DELAYED:
2786 if(!mDone) {
2787 String logStr = "Delay in receiving SIM PIN response ";
2788 if (DBG) log(logStr);
2789 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2790 }
2791 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793 }
2794 };
2795 UnlockSim.this.notifyAll();
2796 }
2797 Looper.loop();
2798 }
2799
2800 /*
2801 * Use PIN or PUK to unlock SIM card
2802 *
2803 * If PUK is null, unlock SIM card with PIN
2804 *
2805 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302806 *
2807 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2808 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 */
Wink Saville9de0f752013-10-22 19:04:03 -07002810 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811
2812 while (mHandler == null) {
2813 try {
2814 wait();
2815 } catch (InterruptedException e) {
2816 Thread.currentThread().interrupt();
2817 }
2818 }
2819 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2820
2821 if (puk == null) {
2822 mSimCard.supplyPin(pin, callback);
2823 } else {
2824 mSimCard.supplyPuk(puk, pin, callback);
2825 }
2826
2827 while (!mDone) {
2828 try {
2829 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002830 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2831 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 wait();
2833 } catch (InterruptedException e) {
2834 // Restore the interrupted status
2835 Thread.currentThread().interrupt();
2836 }
2837 }
2838 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002839 int[] resultArray = new int[2];
2840 resultArray[0] = mResult;
2841 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002842
2843 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002844 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002845 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302846 // This instance is no longer reused, so quit its thread's looper.
2847 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002848
Wink Saville9de0f752013-10-22 19:04:03 -07002849 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851 }
2852
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002853 /**
2854 * This method has been removed due to privacy and stability concerns.
2855 */
2856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002858 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2859 return;
Wink Saville36469e72014-06-11 15:17:00 -07002860 }
2861
Nathan Harold1f889d82020-06-04 17:05:26 -07002862 @Override
2863 public void updateServiceLocationWithPackageName(String callingPackage) {
2864 mApp.getSystemService(AppOpsManager.class)
2865 .checkPackage(Binder.getCallingUid(), callingPackage);
2866
Nathan Haroldf096d982020-11-18 17:18:06 -08002867 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002868 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2869 // Callers targeting S have no business invoking this method.
2870 return;
2871 }
2872
2873 LocationAccessPolicy.LocationPermissionResult locationResult =
2874 LocationAccessPolicy.checkLocationPermission(mApp,
2875 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2876 .setCallingPackage(callingPackage)
2877 .setCallingFeatureId(null)
2878 .setCallingPid(Binder.getCallingPid())
2879 .setCallingUid(Binder.getCallingUid())
2880 .setMethod("updateServiceLocation")
2881 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2882 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2883 .build());
2884 // Apps that lack location permission have no business calling this method;
2885 // however, because no permission was declared in the public API, denials must
2886 // all be "soft".
2887 switch (locationResult) {
2888 case DENIED_HARD: /* fall through */
2889 case DENIED_SOFT:
2890 return;
2891 }
2892
2893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 final long identity = Binder.clearCallingIdentity();
2895 try {
Ling Mac28f0212023-03-24 16:07:15 -07002896 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 } finally {
2898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002900 }
2901
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002902 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002903 @Override
2904 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002905 return isRadioOnWithFeature(callingPackage, null);
2906 }
2907
2908
2909 @Override
2910 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2911 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2912 callingFeatureId);
2913 }
2914
2915 @Deprecated
2916 @Override
2917 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2918 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002919 }
2920
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002922 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2923 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002925 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002926 return false;
2927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928
joonhunshin4ac60942023-11-15 15:23:39 +00002929 enforceTelephonyFeatureWithException(callingPackage,
2930 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 return isRadioOnForSubscriber(subId);
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002938 }
2939
2940 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 final Phone phone = getPhone(subId);
2944 if (phone != null) {
2945 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2946 } else {
2947 return false;
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002955 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 }
Wink Saville36469e72014-06-11 15:17:00 -07002957
Wink Savilleb564aae2014-10-23 10:18:09 -07002958 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
joonhunshin4ac60942023-11-15 15:23:39 +00002961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2962 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 final Phone phone = getPhone(subId);
2967 if (phone != null) {
2968 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2969 }
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002972 }
Wink Saville36469e72014-06-11 15:17:00 -07002973 }
2974
2975 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002976 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002977 }
2978
Wink Savilleb564aae2014-10-23 10:18:09 -07002979 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 final Phone phone = getPhone(subId);
2985 if (phone == null) {
2986 return false;
2987 }
2988 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2989 toggleRadioOnOffForSubscriber(subId);
2990 }
2991 return true;
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
Wink Saville36469e72014-06-11 15:17:00 -07002996
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002997 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002998 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002999
Tomasz Wasilczykef763582024-09-17 13:50:32 -07003000 if (!mApp.getResources().getBoolean(
3001 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3003 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3004 }
joonhunshin4ac60942023-11-15 15:23:39 +00003005
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003006 /*
3007 * If any of the Radios are available, it will need to be
3008 * shutdown. So return true if any Radio is available.
3009 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3013 Phone phone = PhoneFactory.getPhone(i);
3014 if (phone != null && phone.isRadioAvailable()) return true;
3015 }
3016 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3017 return false;
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003020 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003021 }
3022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003024 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 enforceModifyPermission();
3026
joonhunshin4ac60942023-11-15 15:23:39 +00003027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3028 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3033 logv("Shutting down Phone " + i);
3034 shutdownRadioUsingPhoneId(i);
3035 }
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003038 }
3039 }
3040
3041 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003042 Phone phone = PhoneFactory.getPhone(phoneId);
3043 if (phone != null && phone.isRadioAvailable()) {
3044 phone.shutdownRadio();
3045 }
3046 }
3047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
Ling Ma83dc5ea2023-01-12 15:06:04 -08003051 if (!turnOn) {
3052 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3053 }
3054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3058 if (defaultPhone != null) {
3059 defaultPhone.setRadioPower(turnOn);
3060 return true;
3061 } else {
3062 loge("There's no default phone.");
3063 return false;
3064 }
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003067 }
Wink Saville36469e72014-06-11 15:17:00 -07003068 }
3069
Wink Savilleb564aae2014-10-23 10:18:09 -07003070 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
Ling Ma83dc5ea2023-01-12 15:06:04 -08003073 if (!turnOn) {
3074 log("setRadioPowerForSubscriber off: subId=" + subId
3075 + ",callingPackage=" + getCurrentPackageName());
3076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 final Phone phone = getPhone(subId);
3080 if (phone != null) {
3081 phone.setRadioPower(turnOn);
3082 return true;
3083 } else {
3084 return false;
3085 }
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
3090
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003091 /**
3092 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3093 * no reason to power it off. When any of the voters want to power it off, it will be turned
3094 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3095 * powering it off, and these radio off votes will be cleared.
3096 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3097 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3098 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3099 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3100 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3101 * check its vote.
3102 *
3103 * @param subId The subscription ID.
3104 * @param reason The reason for powering off radio.
3105 * @return true on success and false on failure.
3106 */
3107 public boolean requestRadioPowerOffForReason(int subId,
3108 @TelephonyManager.RadioPowerReason int reason) {
3109 enforceModifyPermission();
3110
joonhunshin4ac60942023-11-15 15:23:39 +00003111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3112 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3113
Ling Ma83dc5ea2023-01-12 15:06:04 -08003114 log("requestRadioPowerOffForReason: subId=" + subId
3115 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003116 final long identity = Binder.clearCallingIdentity();
3117 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003118 boolean result = false;
3119 for (Phone phone : PhoneFactory.getPhones()) {
3120 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003121 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003122 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003123 if (!result) {
3124 loge("requestRadioPowerOffForReason: no phone exists");
3125 }
3126 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 /**
3133 * Remove the vote on powering off the radio for a reason, as requested by
3134 * {@link requestRadioPowerOffForReason}.
3135 *
3136 * @param subId The subscription ID.
3137 * @param reason The reason for powering off radio.
3138 * @return true on success and false on failure.
3139 */
3140 public boolean clearRadioPowerOffForReason(int subId,
3141 @TelephonyManager.RadioPowerReason int reason) {
3142 enforceModifyPermission();
3143
joonhunshin4ac60942023-11-15 15:23:39 +00003144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3145 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3146
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003147 final long identity = Binder.clearCallingIdentity();
3148 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003149 boolean result = false;
3150 for (Phone phone : PhoneFactory.getPhones()) {
3151 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003152 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003154 if (!result) {
3155 loge("clearRadioPowerOffForReason: no phone exists");
3156 }
3157 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 }
3162
3163 /**
3164 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3165 *
3166 * @param subId The subscription ID.
3167 * @param callingPackage The package making the call.
3168 * @param callingFeatureId The feature in the package.
3169 * @return List of reasons for powering off radio.
3170 */
3171 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3172 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3173
joonhunshin4ac60942023-11-15 15:23:39 +00003174 enforceTelephonyFeatureWithException(callingPackage,
3175 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3176
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003177 final long identity = Binder.clearCallingIdentity();
3178 List result = new ArrayList();
3179 try {
3180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3181 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3182 return result;
3183 }
3184
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003185 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003186 if (phone != null) {
3187 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003188 } else {
3189 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003190 }
3191 } finally {
3192 Binder.restoreCallingIdentity(identity);
3193 }
3194 return result;
3195 }
3196
Wink Saville36469e72014-06-11 15:17:00 -07003197 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003199 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
joonhunshin4ac60942023-11-15 15:23:39 +00003202 enforceTelephonyFeatureWithException(callingPackage,
3203 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
Jack Yu285100e2022-12-02 22:48:35 -08003207 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003209 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003210 phone.getDataSettingsManager().setDataEnabled(
3211 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 return true;
3213 } else {
3214 return false;
3215 }
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220
Wink Saville36469e72014-06-11 15:17:00 -07003221 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003222 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003223 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225
joonhunshin4ac60942023-11-15 15:23:39 +00003226 enforceTelephonyFeatureWithException(callingPackage,
3227 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
Jack Yu285100e2022-12-02 22:48:35 -08003231 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003233 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003234 phone.getDataSettingsManager().setDataEnabled(
3235 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 return true;
3237 } else {
3238 return false;
3239 }
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 }
3244
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003246 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3248 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 final Phone phone = getPhone(subId);
3253 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003254 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 } else {
3256 return false;
3257 }
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
3263 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003264 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003265 }
3266
pkanwarae03a6b2016-11-06 20:37:09 -08003267 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 enforceCallPermission();
3269
joonhunshin4ac60942023-11-15 15:23:39 +00003270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3271 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3276 return;
3277 }
3278 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3279 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
pkanwar32d516d2016-10-14 19:37:38 -07003283 };
3284
Wink Savilleb564aae2014-10-23 10:18:09 -07003285 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287
joonhunshin4ac60942023-11-15 15:23:39 +00003288 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3289 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3294 return false;
3295 }
3296 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003302 /**
3303 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3304 * tag on getCallState Binder call.
3305 */
3306 @Deprecated
3307 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003309 if (CompatChanges.isChangeEnabled(
3310 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3311 Binder.getCallingUid())) {
3312 // Do not allow this API to be called on API version 31+, it should only be
3313 // called on old apps using this Binder call directly.
3314 throw new SecurityException("This method can only be used for applications "
3315 + "targeting API version 30 or less.");
3316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317 final long identity = Binder.clearCallingIdentity();
3318 try {
Ling Mac28f0212023-03-24 16:07:15 -07003319 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3320 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3328 if (CompatChanges.isChangeEnabled(
3329 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3330 Binder.getCallingUid())) {
3331 // Check READ_PHONE_STATE for API version 31+
3332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3333 featureId, "getCallStateForSubscription")) {
3334 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3335 + "targeting API level 31+.");
3336 }
3337 }
joonhunshin4ac60942023-11-15 15:23:39 +00003338
3339 enforceTelephonyFeatureWithException(callingPackage,
3340 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3341
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3346 PhoneConstantConversions.convertCallState(phone.getState());
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 }
3351
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003353 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003354 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003355 }
3356
3357 @Override
3358 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3360 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 final long identity = Binder.clearCallingIdentity();
3363 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003364 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003366 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 } else {
3368 return PhoneConstantConversions.convertDataState(
3369 PhoneConstants.DataState.DISCONNECTED);
3370 }
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003374 }
3375
Sanket Padawe356d7632015-06-22 14:03:32 -07003376 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003377 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003378 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003379 }
3380
3381 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003382 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3384 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003388 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003390 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 } else {
3392 return TelephonyManager.DATA_ACTIVITY_NONE;
3393 }
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 }
3398
3399 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003400 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003402 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003403
3404 LocationAccessPolicy.LocationPermissionResult locationResult =
3405 LocationAccessPolicy.checkLocationPermission(mApp,
3406 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3407 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003408 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003409 .setCallingPid(Binder.getCallingPid())
3410 .setCallingUid(Binder.getCallingUid())
3411 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3414 .build());
3415 switch (locationResult) {
3416 case DENIED_HARD:
3417 throw new SecurityException("Not allowed to access cell location");
3418 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003419 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3420 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003421 }
3422
joonhunshin4ac60942023-11-15 15:23:39 +00003423 enforceTelephonyFeatureWithException(callingPackage,
3424 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3425
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003426 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003430 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003431 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
Svetoslav64fad262015-04-14 14:35:21 -07003435 }
3436
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003438 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003439 if (!mApp.getResources().getBoolean(
3440 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3442 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3443 }
joonhunshin4ac60942023-11-15 15:23:39 +00003444
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003445 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3446 // registered cell info, so return a NULL country instead.
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003449 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3450 // Get default phone in this case.
3451 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3452 }
Jack Yu285100e2022-12-02 22:48:35 -08003453 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003455 if (phone == null) return "";
3456 ServiceStateTracker sst = phone.getServiceStateTracker();
3457 if (sst == null) return "";
3458 LocaleTracker lt = sst.getLocaleTracker();
3459 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003460 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003464 }
3465
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003466 /**
3467 * This method was removed due to potential issues caused by performing partial
3468 * updates of service state, and lack of a credible use case.
3469 *
3470 * This has the ability to break the telephony implementation by disabling notification of
3471 * changes in device connectivity. DO NOT USE THIS!
3472 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003473 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 public void enableLocationUpdates() {
3475 mApp.enforceCallingOrSelfPermission(
3476 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003477 }
3478
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003479 /**
3480 * This method was removed due to potential issues caused by performing partial
3481 * updates of service state, and lack of a credible use case.
3482 *
3483 * This has the ability to break the telephony implementation by disabling notification of
3484 * changes in device connectivity. DO NOT USE THIS!
3485 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 @Override
3487 public void disableLocationUpdates() {
3488 mApp.enforceCallingOrSelfPermission(
3489 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 }
3491
3492 @Override
3493 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003494 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3495 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003496 try {
3497 mApp.getSystemService(AppOpsManager.class)
3498 .checkPackage(Binder.getCallingUid(), callingPackage);
3499 } catch (SecurityException e) {
3500 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3501 throw e;
3502 }
3503
Nathan Haroldf096d982020-11-18 17:18:06 -08003504 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003505 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3506 throw new SecurityException(
3507 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3508 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003509
Jordan Liu1617b712019-07-10 15:06:26 -07003510 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3512 return null;
3513 }
Svetoslav64fad262015-04-14 14:35:21 -07003514
joonhunshin4ac60942023-11-15 15:23:39 +00003515 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3516 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3517
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003518 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003520 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003521 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522
Nathan Haroldf180aac2018-06-01 18:43:55 -07003523 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3524 for (CellInfo ci : info) {
3525 if (ci instanceof CellInfoGsm) {
3526 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3527 } else if (ci instanceof CellInfoWcdma) {
3528 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003530 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003531 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003534 private List<CellInfo> getCachedCellInfo() {
3535 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3536 for (Phone phone : PhoneFactory.getPhones()) {
3537 List<CellInfo> info = phone.getAllCellInfo();
3538 if (info != null) cellInfos.addAll(info);
3539 }
3540 return cellInfos;
3541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003542
3543 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003544 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003545 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003546 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003547
3548 LocationAccessPolicy.LocationPermissionResult locationResult =
3549 LocationAccessPolicy.checkLocationPermission(mApp,
3550 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3551 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003552 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003553 .setCallingPid(Binder.getCallingPid())
3554 .setCallingUid(Binder.getCallingUid())
3555 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003556 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003557 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3558 .build());
3559 switch (locationResult) {
3560 case DENIED_HARD:
3561 throw new SecurityException("Not allowed to access cell info");
3562 case DENIED_SOFT:
3563 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
Nathan Haroldf096d982020-11-18 17:18:06 -08003566 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003567 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3568 return getCachedCellInfo();
3569 }
3570
joonhunshin4ac60942023-11-15 15:23:39 +00003571 enforceTelephonyFeatureWithException(callingPackage,
3572 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3573
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003574 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3579 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003580 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003581 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582 if (info != null) cellInfos.addAll(info);
3583 }
3584 return cellInfos;
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588 }
3589
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003590 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003591 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3592 String callingFeatureId) {
3593 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3594 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003595 }
3596
3597 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003598 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3599 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003600 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003601 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003602 }
3603
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003604 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3605 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003607 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003608
3609 LocationAccessPolicy.LocationPermissionResult locationResult =
3610 LocationAccessPolicy.checkLocationPermission(mApp,
3611 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3612 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003613 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003614 .setCallingPid(Binder.getCallingPid())
3615 .setCallingUid(Binder.getCallingUid())
3616 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003617 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3618 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003619 .build());
3620 switch (locationResult) {
3621 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003622 if (TelephonyPermissions
3623 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003624 // Safetynet logging for b/154934934
3625 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3626 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003627 throw new SecurityException("Not allowed to access cell info");
3628 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003629 if (TelephonyPermissions
3630 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003631 // Safetynet logging for b/154934934
3632 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3633 }
Nathan Harold5320c422019-05-09 10:26:08 -07003634 try {
3635 cb.onCellInfo(new ArrayList<CellInfo>());
3636 } catch (RemoteException re) {
3637 // Drop without consequences
3638 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003639 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003640 }
3641
joonhunshin4ac60942023-11-15 15:23:39 +00003642 enforceTelephonyFeatureWithException(callingPackage,
3643 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003644
3645 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003646 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3647
3648 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3649 }
3650
3651 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003652 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003653 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003658 Phone phone = getPhone(subId);
3659 if (phone == null) {
3660 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3661 } else {
3662 phone.setCellInfoListRate(rateInMillis, workSource);
3663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003667 }
3668
Shishir Agrawala9f32182016-04-12 12:00:16 -07003669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003670 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003671 Phone phone = PhoneFactory.getPhone(slotIndex);
3672 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003673 return null;
3674 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003675 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003676 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003677 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003678 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003679 return null;
3680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681
joonhunshin4ac60942023-11-15 15:23:39 +00003682 enforceTelephonyFeatureWithException(callingPackage,
3683 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 return phone.getImei();
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003691 }
3692
3693 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003694 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3695 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3696 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3697 callingFeatureId, "getPrimaryImei")) {
3698 throw new SecurityException("Caller does not have permission");
3699 }
joonhunshin4ac60942023-11-15 15:23:39 +00003700
3701 enforceTelephonyFeatureWithException(callingPackage,
3702 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3703
arunvoddud5c6ce02022-12-11 06:03:12 +00003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 for (Phone phone : PhoneFactory.getPhones()) {
3707 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3708 return phone.getImei();
3709 }
3710 }
3711 throw new UnsupportedOperationException("Operation not supported");
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003718 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003719 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3720 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3721
David Kelly5e06a7f2018-03-12 14:10:59 +00003722 Phone phone = PhoneFactory.getPhone(slotIndex);
3723 String tac = null;
3724 if (phone != null) {
3725 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003726 try {
3727 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3728 } catch (IndexOutOfBoundsException e) {
3729 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3730 return null;
3731 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003732 }
3733 return tac;
3734 }
3735
3736 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003737 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003738 try {
3739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3740 } catch (SecurityException se) {
3741 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3742 throw new SecurityException("Package " + callingPackage + " does not belong to "
3743 + Binder.getCallingUid());
3744 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003745 Phone phone = PhoneFactory.getPhone(slotIndex);
3746 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003747 return null;
3748 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749
Jeff Davidson913390f2018-02-23 17:11:49 -08003750 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003751 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003752 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003753 return null;
3754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755
joonhunshin4ac60942023-11-15 15:23:39 +00003756 enforceTelephonyFeatureWithException(callingPackage,
3757 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return phone.getMeid();
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Jack Yu2af8d712017-03-15 17:14:14 -07003765 }
3766
3767 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003768 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003769 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3770 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3771
David Kelly5e06a7f2018-03-12 14:10:59 +00003772 Phone phone = PhoneFactory.getPhone(slotIndex);
3773 String manufacturerCode = null;
3774 if (phone != null) {
3775 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003776 try {
3777 manufacturerCode =
3778 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3779 } catch (IndexOutOfBoundsException e) {
3780 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3781 return null;
3782 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003783 }
3784 return manufacturerCode;
3785 }
3786
3787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003788 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3789 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003790 Phone phone = PhoneFactory.getPhone(slotIndex);
3791 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003792 return null;
3793 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003794 int subId = phone.getSubId();
3795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003796 mApp, subId, callingPackage, callingFeatureId,
3797 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003798 return null;
3799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800
joonhunshin4ac60942023-11-15 15:23:39 +00003801 enforceTelephonyFeatureWithException(callingPackage,
3802 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 return phone.getDeviceSvn();
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
3809 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003810 }
3811
fionaxu43304da2017-11-27 22:51:16 -08003812 @Override
3813 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003814 if (!mApp.getResources().getBoolean(
3815 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3817 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3818 }
joonhunshin4ac60942023-11-15 15:23:39 +00003819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
fionaxu43304da2017-11-27 22:51:16 -08003827 }
3828
3829 @Override
3830 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3832 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 final Phone phone = getPhone(subId);
3837 return phone == null ? null : phone.getCarrierName();
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
3840 }
fionaxu43304da2017-11-27 22:51:16 -08003841 }
3842
calvinpanffe225e2018-11-01 19:43:06 +08003843 @Override
chen xu0026ca62019-03-06 15:28:50 -08003844 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3847
chen xu25637222018-11-04 17:17:00 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 final Phone phone = getPhone(subId);
3851 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003852 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
3856 }
3857
3858 @Override
chen xu0026ca62019-03-06 15:28:50 -08003859 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3861 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3862 "getSubscriptionSpecificCarrierName");
3863
chen xu25637222018-11-04 17:17:00 -08003864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003867 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003868 } finally {
3869 Binder.restoreCallingIdentity(identity);
3870 }
3871 }
3872
chen xu651eec72018-11-11 19:03:44 -08003873 @Override
chen xu864e11c2018-12-06 22:10:03 -08003874 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3875 if (!isSubscriptionMccMnc) {
3876 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3877 }
chen xu651eec72018-11-11 19:03:44 -08003878 final Phone phone = PhoneFactory.getPhone(slotIndex);
3879 if (phone == null) {
3880 return TelephonyManager.UNKNOWN_CARRIER_ID;
3881 }
joonhunshin4ac60942023-11-15 15:23:39 +00003882
3883 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3884 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3885
chen xu651eec72018-11-11 19:03:44 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
3891 }
3892 }
3893
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003894 //
3895 // Internal helper methods.
3896 //
3897
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003898 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003899 * Make sure the caller is the calling package itself
3900 *
3901 * @throws SecurityException if the caller is not the calling package
3902 */
3903 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3904 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003905 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3906 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003907 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003908 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003909 } catch (PackageManager.NameNotFoundException e) {
3910 // packageUid is -1
3911 }
3912 if (packageUid != callingUid) {
3913 throw new SecurityException(message + ": Package " + callingPackage
3914 + " does not belong to " + callingUid);
3915 }
3916 }
3917
3918 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003919 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3920 *
3921 * @throws SecurityException if the caller does not have the required permission
3922 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003923 @VisibleForTesting
3924 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3926 }
3927
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003928 /**
arunvoddud7401012022-12-15 16:08:12 +00003929 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003930 *
3931 * @throws SecurityException if the caller does not have the required permission
3932 */
3933 @VisibleForTesting
3934 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003935 enforceReadPermission(null);
3936 }
3937
3938 /**
3939 * Make sure the caller has the READ_PHONE_STATE permissions.
3940 *
3941 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3942 */
3943 @VisibleForTesting
3944 public void enforceReadPermission(String msg) {
3945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003946 }
3947
Shuo Qian3b6ee772019-11-13 17:43:31 -08003948 private void enforceActiveEmergencySessionPermission() {
3949 mApp.enforceCallingOrSelfPermission(
3950 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3951 }
3952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003953 /**
3954 * Make sure the caller has the CALL_PHONE permission.
3955 *
3956 * @throws SecurityException if the caller does not have the required permission
3957 */
3958 private void enforceCallPermission() {
3959 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3960 }
3961
paulhu5a773602019-08-23 19:17:33 +08003962 private void enforceSettingsPermission() {
3963 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003964 }
3965
Michele Berionne5e411512020-11-13 02:36:59 +00003966 private void enforceRebootPermission() {
3967 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3968 }
3969
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003970 /**
3971 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3972 * @param message - log message to print.
3973 * @throws SecurityException if the caller does not have the required permission
3974 */
3975 private void enforceSatelliteCommunicationPermission(String message) {
3976 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3977 }
3978
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003979 /**
3980 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3981 * @param message - log message to print.
3982 * @throws SecurityException if the caller does not have the required permission
3983 */
3984 private void enforcePackageUsageStatsPermission(String message) {
3985 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3986 }
3987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003988 private String createTelUrl(String number) {
3989 if (TextUtils.isEmpty(number)) {
3990 return null;
3991 }
3992
Jake Hambye994d462014-02-03 13:10:13 -08003993 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003994 }
3995
Ihab Awadf9e92732013-12-05 18:02:52 -08003996 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003997 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003998 }
3999
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004000 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004001 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004002 }
4003
Ihab Awadf9e92732013-12-05 18:02:52 -08004004 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004005 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004006 }
4007
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004008 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004010 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004011 }
4012
Sanket Padawe356d7632015-06-22 14:03:32 -07004013 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004014 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004015 if (!mApp.getResources().getBoolean(
4016 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4017 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4018 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4019 }
joonhunshin4ac60942023-11-15 15:23:39 +00004020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 final Phone phone = PhoneFactory.getPhone(slotIndex);
4024 if (phone == null) {
4025 return PhoneConstants.PHONE_TYPE_NONE;
4026 } else {
4027 return phone.getPhoneType();
4028 }
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004032 }
4033
4034 /**
4035 * Returns the CDMA ERI icon index to display
4036 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004038 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4039 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4040 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004041 }
4042
Sanket Padawe356d7632015-06-22 14:03:32 -07004043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004044 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4045 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004047 mApp, subId, callingPackage, callingFeatureId,
4048 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004049 return -1;
4050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
joonhunshin4ac60942023-11-15 15:23:39 +00004052 enforceTelephonyFeatureWithException(callingPackage,
4053 PackageManager.FEATURE_TELEPHONY_CDMA,
4054 "getCdmaEriIconIndexForSubscriber");
4055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 final Phone phone = getPhone(subId);
4059 if (phone != null) {
4060 return phone.getCdmaEriIconIndex();
4061 } else {
4062 return -1;
4063 }
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004067 }
4068
4069 /**
4070 * Returns the CDMA ERI icon mode,
4071 * 0 - ON
4072 * 1 - FLASHING
4073 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004075 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4076 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4077 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004078 }
4079
Sanket Padawe356d7632015-06-22 14:03:32 -07004080 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004081 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4082 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004084 mApp, subId, callingPackage, callingFeatureId,
4085 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004086 return -1;
4087 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 final Phone phone = getPhone(subId);
4092 if (phone != null) {
4093 return phone.getCdmaEriIconMode();
4094 } else {
4095 return -1;
4096 }
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004100 }
4101
4102 /**
4103 * Returns the CDMA ERI text,
4104 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004106 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4107 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4108 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004109 }
4110
Sanket Padawe356d7632015-06-22 14:03:32 -07004111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004112 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4113 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004115 mApp, subId, callingPackage, callingFeatureId,
4116 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004117 return null;
4118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 final Phone phone = getPhone(subId);
4123 if (phone != null) {
4124 return phone.getCdmaEriText();
4125 } else {
4126 return null;
4127 }
4128 } finally {
4129 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004131 }
4132
4133 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004134 * Returns the CDMA MDN.
4135 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004136 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004137 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4139 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140
joonhunshin4ac60942023-11-15 15:23:39 +00004141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4142 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004147 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 return phone.getLine1Number();
4149 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151 return null;
4152 }
4153 } finally {
4154 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004155 }
4156 }
4157
4158 /**
4159 * Returns the CDMA MIN.
4160 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004161 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004162 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4164 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165
joonhunshin4ac60942023-11-15 15:23:39 +00004166 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4167 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 final Phone phone = getPhone(subId);
4172 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4173 return phone.getCdmaMin();
4174 } else {
4175 return null;
4176 }
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004179 }
4180 }
4181
Hall Liud892bec2018-11-30 14:51:45 -08004182 @Override
4183 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4184 INumberVerificationCallback callback, String callingPackage) {
4185 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4186 != PERMISSION_GRANTED) {
4187 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4188 }
4189 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4190
4191 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4192 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004193 throw new SecurityException("Calling package must be configured in the device config: "
4194 + "calling package: " + callingPackage
4195 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004196 }
4197
joonhunshin4ac60942023-11-15 15:23:39 +00004198 enforceTelephonyFeatureWithException(callingPackage,
4199 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4200
Hall Liud892bec2018-11-30 14:51:45 -08004201 if (range == null) {
4202 throw new NullPointerException("Range must be non-null");
4203 }
4204
4205 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004206 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004207
4208 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4209 }
4210
Junda Liuca05d5d2014-08-14 22:36:34 -07004211 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004212 * Returns true if CDMA provisioning needs to run.
4213 */
4214 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4216 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004220 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004224 }
4225
4226 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004227 * Sets the voice mail number of a given subId.
4228 */
4229 @Override
4230 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004231 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4232 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233
joonhunshin4ac60942023-11-15 15:23:39 +00004234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4235 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 final long identity = Binder.clearCallingIdentity();
4238 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004239 Boolean success = (Boolean) sendRequest(
4240 CMD_SET_VOICEMAIL_NUMBER,
4241 new Pair<String, String>(alphaTag, number),
4242 new Integer(subId),
4243 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4244 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 return success;
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004249 }
4250
Ta-wei Yen87c49842016-05-13 21:19:52 -07004251 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004252 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4253 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004254 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4255 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004256 if (!TextUtils.equals(callingPackage, systemDialer)) {
4257 throw new SecurityException("caller must be system dialer");
4258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259
joonhunshin4ac60942023-11-15 15:23:39 +00004260 enforceTelephonyFeatureWithException(callingPackage,
4261 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4266 if (phoneAccountHandle == null) {
4267 return null;
4268 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004272 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004273 }
4274
4275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4277 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004280 mApp, subId, callingPackage, callingFeatureId,
4281 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004282 return null;
4283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284
joonhunshin4ac60942023-11-15 15:23:39 +00004285 enforceTelephonyFeatureWithException(callingPackage,
4286 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4287
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004288 final long identity = Binder.clearCallingIdentity();
4289 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004290 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004294 }
4295
4296 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004297 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4298 VisualVoicemailSmsFilterSettings settings) {
4299 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004300 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004301 enforceTelephonyFeatureWithException(callingPackage,
4302 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004306 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004310 }
4311
4312 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004313 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004315 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004316 enforceTelephonyFeatureWithException(callingPackage,
4317 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004322 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004326 }
4327
4328 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004329 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4330 String callingPackage, int subId) {
4331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
4335 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004336 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004340 }
4341
4342 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004343 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004344 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345
4346 final long identity = Binder.clearCallingIdentity();
4347 try {
4348 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004349 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004353 }
4354
4355 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004356 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4357 String callingAttributionTag, int subId, String number, int port, String text,
4358 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004360 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004361 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004362
4363 enforceTelephonyFeatureWithException(callingPackage,
4364 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4365
Amit Mahajandccb3f12019-05-13 13:48:32 -07004366 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004367 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4368 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4369 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004370 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004371
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004372 /**
fionaxu0152e512016-11-14 13:36:14 -08004373 * Sets the voice activation state of a given subId.
4374 */
4375 @Override
4376 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4378 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379
joonhunshin4ac60942023-11-15 15:23:39 +00004380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4381 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 final Phone phone = getPhone(subId);
4386 if (phone != null) {
4387 phone.setVoiceActivationState(activationState);
4388 } else {
4389 loge("setVoiceActivationState fails with invalid subId: " + subId);
4390 }
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004393 }
4394 }
4395
4396 /**
4397 * Sets the data activation state of a given subId.
4398 */
4399 @Override
4400 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4402 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403
joonhunshin4ac60942023-11-15 15:23:39 +00004404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4405 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 final Phone phone = getPhone(subId);
4410 if (phone != null) {
4411 phone.setDataActivationState(activationState);
4412 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004413 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 }
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004417 }
4418 }
4419
4420 /**
4421 * Returns the voice activation state of a given subId.
4422 */
4423 @Override
4424 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004425 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426
joonhunshin4ac60942023-11-15 15:23:39 +00004427 enforceTelephonyFeatureWithException(callingPackage,
4428 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4429
fionaxu0152e512016-11-14 13:36:14 -08004430 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 if (phone != null) {
4434 return phone.getVoiceActivationState();
4435 } else {
4436 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4437 }
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004440 }
4441 }
4442
4443 /**
4444 * Returns the data activation state of a given subId.
4445 */
4446 @Override
4447 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449
joonhunshin4ac60942023-11-15 15:23:39 +00004450 enforceTelephonyFeatureWithException(callingPackage,
4451 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4452
fionaxu0152e512016-11-14 13:36:14 -08004453 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 final long identity = Binder.clearCallingIdentity();
4455 try {
4456 if (phone != null) {
4457 return phone.getDataActivationState();
4458 } else {
4459 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4460 }
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004463 }
4464 }
4465
4466 /**
Wink Saville36469e72014-06-11 15:17:00 -07004467 * Returns the unread count of voicemails for a subId
4468 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004470 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4471 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 mApp, subId, callingPackage, callingFeatureId,
4474 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004475 return 0;
4476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 final Phone phone = getPhone(subId);
4480 if (phone != null) {
4481 return phone.getVoiceMessageCount();
4482 } else {
4483 return 0;
4484 }
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004488 }
4489
4490 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004491 * returns true, if the device is in a state where both voice and data
4492 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004493 */
4494 @Override
4495 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004496 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4497 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
Ling Mac28f0212023-03-24 16:07:15 -07004501 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004505 }
4506
4507 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004508 * Send the dialer code if called from the current default dialer or the caller has
4509 * carrier privilege.
4510 * @param inputCode The dialer code to send
4511 */
4512 @Override
4513 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004514 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004516 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4517 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004518 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004519 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004520 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522
joonhunshin4ac60942023-11-15 15:23:39 +00004523 enforceTelephonyFeatureWithException(callingPackage,
4524 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004528 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
fionaxu235cc5e2017-03-06 22:25:57 -08004532 }
4533
Pengquan Menga1bb6272018-09-06 09:59:22 -07004534 @Override
4535 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004536 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004537 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4538 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004539
4540 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4541 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4542
shilufc958392020-01-20 11:36:01 -08004543 final long identity = Binder.clearCallingIdentity();
4544 try {
4545 if (!isActiveSubscription(subId)) {
4546 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4547 }
4548 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004552 }
4553
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004555 public boolean isInEmergencySmsMode() {
4556 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004557
4558 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4559 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4560
Brad Ebingerb2b65522019-03-15 13:48:47 -07004561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 for (Phone phone : PhoneFactory.getPhones()) {
4564 if (phone.isInEmergencySmsMode()) {
4565 return true;
4566 }
4567 }
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
4570 }
4571 return false;
4572 }
4573
shilu366312e2019-12-17 09:28:10 -08004574 /**
4575 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4576 * @param subId The subscription to use to check the configuration.
4577 * @param c The callback that will be used to send the result.
4578 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004579 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004580 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4581 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004582 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004583 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004584
4585 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4586 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4587 "IMS not available on device.");
4588 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004589 final long token = Binder.clearCallingIdentity();
4590 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004591 int slotId = getSlotIndexOrException(subId);
4592 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004593
4594 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4595 if (controller != null) {
4596 ImsManager imsManager = controller.getImsManager(subId);
4597 if (imsManager != null) {
4598 imsManager.addRegistrationCallbackForSubscription(c, subId);
4599 } else {
4600 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4601 }
4602 } else {
4603 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4604 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004605 } catch (ImsException e) {
4606 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 } finally {
4608 Binder.restoreCallingIdentity(token);
4609 }
4610 }
4611
shilu366312e2019-12-17 09:28:10 -08004612 /**
4613 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4614 * @param subId The subscription to use to check the configuration.
4615 * @param c The callback that will be used to send the result.
4616 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004617 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004618 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004619 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004620 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4622 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4623 }
Meng Wangafbc5852019-09-19 17:37:13 -07004624 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004625
Meng Wangafbc5852019-09-19 17:37:13 -07004626 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004627 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4628 if (controller != null) {
4629 ImsManager imsManager = controller.getImsManager(subId);
4630 if (imsManager != null) {
4631 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4632 } else {
4633 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4634 + "is inactive, ignoring unregister.");
4635 // If the ImsManager is not valid, just return, since the callback
4636 // will already have been removed internally.
4637 }
4638 }
Meng Wangafbc5852019-09-19 17:37:13 -07004639 } finally {
4640 Binder.restoreCallingIdentity(token);
4641 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004642 }
4643
Brad Ebingera34a6c22019-10-22 17:36:18 -07004644 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4646 * @param subId The subscription to use to check the configuration.
4647 * @param c The callback that will be used to send the result.
4648 */
4649 @Override
4650 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4651 throws RemoteException {
4652 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4653 mApp, subId, "registerImsEmergencyRegistrationCallback");
4654
4655 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4656 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4657 "IMS not available on device.");
4658 }
4659 final long token = Binder.clearCallingIdentity();
4660 try {
4661 int slotId = getSlotIndexOrException(subId);
4662 verifyImsMmTelConfiguredOrThrow(slotId);
4663
4664 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4665 if (controller != null) {
4666 ImsManager imsManager = controller.getImsManager(subId);
4667 if (imsManager != null) {
4668 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4669 } else {
4670 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4671 }
4672 } else {
4673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4674 }
4675 } catch (ImsException e) {
4676 throw new ServiceSpecificException(e.getCode());
4677 } finally {
4678 Binder.restoreCallingIdentity(token);
4679 }
4680 }
4681
4682 /**
4683 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4684 * @param subId The subscription to use to check the configuration.
4685 * @param c The callback that will be used to send the result.
4686 */
4687 @Override
4688 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4689 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4690 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4692 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4693 }
4694 final long token = Binder.clearCallingIdentity();
4695
4696 try {
4697 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4698 if (controller != null) {
4699 ImsManager imsManager = controller.getImsManager(subId);
4700 if (imsManager != null) {
4701 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4702 } else {
4703 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4704 + "is inactive, ignoring unregister.");
4705 // If the ImsManager is not valid, just return, since the callback
4706 // will already have been removed internally.
4707 }
4708 }
4709 } finally {
4710 Binder.restoreCallingIdentity(token);
4711 }
4712 }
4713
4714 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004715 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4716 */
4717 @Override
4718 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4719 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4720 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4721 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4722 "IMS not available on device.");
4723 }
4724 final long token = Binder.clearCallingIdentity();
4725 try {
4726 Phone phone = getPhone(subId);
4727 if (phone == null) {
4728 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4729 + subId + "'");
4730 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4731 }
4732 phone.getImsRegistrationState(regState -> {
4733 try {
4734 consumer.accept((regState == null)
4735 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4736 } catch (RemoteException e) {
4737 // Ignore if the remote process is no longer available to call back.
4738 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4739 }
4740 });
4741 } finally {
4742 Binder.restoreCallingIdentity(token);
4743 }
4744 }
4745
4746 /**
4747 * Get the transport type for the IMS service registration state.
4748 */
4749 @Override
4750 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004751 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004752 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004753 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4755 "IMS not available on device.");
4756 }
4757 final long token = Binder.clearCallingIdentity();
4758 try {
4759 Phone phone = getPhone(subId);
4760 if (phone == null) {
4761 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4762 + subId + "'");
4763 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4764 }
4765 phone.getImsRegistrationTech(regTech -> {
4766 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4767 int regTechConverted = (regTech == null)
4768 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4769 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4770 regTechConverted);
4771 try {
4772 consumer.accept(regTechConverted);
4773 } catch (RemoteException e) {
4774 // Ignore if the remote process is no longer available to call back.
4775 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4776 }
4777 });
4778 } finally {
4779 Binder.restoreCallingIdentity(token);
4780 }
4781 }
4782
shilu366312e2019-12-17 09:28:10 -08004783 /**
4784 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4785 * @param subId The subscription to use to check the configuration.
4786 * @param c The callback that will be used to send the result.
4787 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004789 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4790 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004791 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004792 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004793 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4795 "IMS not available on device.");
4796 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004797 final long token = Binder.clearCallingIdentity();
4798 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004799 int slotId = getSlotIndexOrException(subId);
4800 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004801
4802 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4803 if (controller != null) {
4804 ImsManager imsManager = controller.getImsManager(subId);
4805 if (imsManager != null) {
4806 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4807 } else {
4808 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4809 }
4810 } else {
4811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4812 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004813 } catch (ImsException e) {
4814 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004815 } finally {
4816 Binder.restoreCallingIdentity(token);
4817 }
4818 }
4819
shilu366312e2019-12-17 09:28:10 -08004820 /**
4821 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4822 * @param subId The subscription to use to check the configuration.
4823 * @param c The callback that will be used to send the result.
4824 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004826 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004827 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004828 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004829 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4830 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4831 }
Meng Wangafbc5852019-09-19 17:37:13 -07004832
4833 final long token = Binder.clearCallingIdentity();
4834 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004835 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4836 if (controller != null) {
4837 ImsManager imsManager = controller.getImsManager(subId);
4838 if (imsManager != null) {
4839 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4840 } else {
4841 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4842 + " is inactive, ignoring unregister.");
4843 // If the ImsManager is not valid, just return, since the callback
4844 // will already have been removed internally.
4845 }
4846 }
Meng Wangafbc5852019-09-19 17:37:13 -07004847 } finally {
4848 Binder.restoreCallingIdentity(token);
4849 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004850 }
4851
4852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004853 public boolean isCapable(int subId, int capability, int regTech) {
4854 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004855
4856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4857 FEATURE_TELEPHONY_IMS, "isCapable");
4858
Brad Ebinger35c841c2018-10-01 10:40:55 -07004859 final long token = Binder.clearCallingIdentity();
4860 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004861 int slotId = getSlotIndexOrException(subId);
4862 verifyImsMmTelConfiguredOrThrow(slotId);
4863 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4864 } catch (com.android.ims.ImsException e) {
4865 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4866 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004867 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004868 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4869 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004870 } finally {
4871 Binder.restoreCallingIdentity(token);
4872 }
4873 }
4874
4875 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004876 public boolean isAvailable(int subId, int capability, int regTech) {
4877 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004878
4879 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4880 FEATURE_TELEPHONY_IMS, "isAvailable");
4881
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 final long token = Binder.clearCallingIdentity();
4883 try {
4884 Phone phone = getPhone(subId);
4885 if (phone == null) return false;
4886 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004887 } catch (com.android.ims.ImsException e) {
4888 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4889 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004890 } finally {
4891 Binder.restoreCallingIdentity(token);
4892 }
4893 }
4894
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004895 /**
4896 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4897 * subscription.
4898 * @param subId The subscription to use to check the configuration.
4899 * @param callback The callback that will be used to send the result.
4900 * @param capability The MmTelFeature capability that will be used to send the result.
4901 * @param transportType The transport type of the MmTelFeature capability.
4902 */
4903 @Override
4904 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4905 int transportType) {
4906 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004907 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4908 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4909 "IMS not available on device.");
4910 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004911 final long token = Binder.clearCallingIdentity();
4912 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004913 int slotId = getSlotIndex(subId);
4914 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4915 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4916 + subId + "'");
4917 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4918 }
4919 verifyImsMmTelConfiguredOrThrow(slotId);
4920 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4921 transportType, aBoolean -> {
4922 try {
4923 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4924 } catch (RemoteException e) {
4925 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4926 + "running. Ignore");
4927 }
4928 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 } catch (ImsException e) {
4930 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004931 } finally {
4932 Binder.restoreCallingIdentity(token);
4933 }
4934 }
4935
shilu366312e2019-12-17 09:28:10 -08004936 /**
4937 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4938 * @param subId The subscription to use to check the configuration.
4939 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 @Override
4941 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004942 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004943 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004944
joonhunshin4ac60942023-11-15 15:23:39 +00004945 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4946 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4947
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 final long token = Binder.clearCallingIdentity();
4949 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004950 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004951 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004952 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004953 } catch (ImsException e) {
4954 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 } finally {
4956 Binder.restoreCallingIdentity(token);
4957 }
4958 }
4959
4960 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004961 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004963 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004964
4965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4966 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4967
Brad Ebinger35c841c2018-10-01 10:40:55 -07004968 final long identity = Binder.clearCallingIdentity();
4969 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004970 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004971 // This setting doesn't require an active ImsService connection, so do not verify. The
4972 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004973 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004974 } catch (ImsException e) {
4975 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
4979 }
4980
shilu366312e2019-12-17 09:28:10 -08004981 /**
4982 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4983 * @param subId The subscription to use to check the configuration.
4984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004986 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004987 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004988 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004989
4990 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4991 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4992
Brad Ebinger35c841c2018-10-01 10:40:55 -07004993 final long identity = Binder.clearCallingIdentity();
4994 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004995 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004996 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004997 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (ImsException e) {
4999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
5003 }
5004
5005 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005006 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005008 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005009
5010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5011 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5012
Brad Ebinger35c841c2018-10-01 10:40:55 -07005013 final long identity = Binder.clearCallingIdentity();
5014 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005015 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005016 // This setting doesn't require an active ImsService connection, so do not verify. The
5017 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005018 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005019 } catch (ImsException e) {
5020 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
5024 }
5025
shilu366312e2019-12-17 09:28:10 -08005026 /**
5027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5028 * @param subId The subscription to use to check the configuration.
5029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005030 @Override
5031 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005033 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005034
5035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5036 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5037
Brad Ebinger35c841c2018-10-01 10:40:55 -07005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005040 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005041 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005043 } catch (ImsException e) {
5044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
5048 }
5049
5050 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005051 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005053 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005054
5055 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5056 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5057
Brad Ebinger35c841c2018-10-01 10:40:55 -07005058 final long identity = Binder.clearCallingIdentity();
5059 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005060 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005061 // This setting doesn't require an active ImsService connection, so do not verify. The
5062 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005063 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005064 } catch (ImsException e) {
5065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
5069 }
5070
shilu366312e2019-12-17 09:28:10 -08005071 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005072 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5073 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5074 * @param subId The subscription to use to check the configuration.
5075 */
5076 @Override
5077 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005078 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005079 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005080
5081 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5082 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5083
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005086 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005087 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005088 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005089 } catch (ImsException e) {
5090 throw new ServiceSpecificException(e.getCode());
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
5093 }
5094 }
5095
5096 /**
5097 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5098 * Requires MODIFY_PHONE_STATE permission.
5099 * @param subId The subscription to use to check the configuration.
5100 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5101 * false otherwise
5102 */
5103 @Override
5104 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5106 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005107
5108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5109 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5110
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005113 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005114 // This setting doesn't require an active ImsService connection, so do not verify. The
5115 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005116 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005117 } catch (ImsException e) {
5118 throw new ServiceSpecificException(e.getCode());
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
5122 }
5123
5124 /**
shilu366312e2019-12-17 09:28:10 -08005125 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5126 * @param subId The subscription to use to check the configuration.
5127 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005128 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005129
Brad Ebinger35c841c2018-10-01 10:40:55 -07005130 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005131 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005132 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005133
5134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5135 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5136
Brad Ebinger35c841c2018-10-01 10:40:55 -07005137 final long identity = Binder.clearCallingIdentity();
5138 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005139 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005140 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005141 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005142 } catch (ImsException e) {
5143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
5147 }
5148
5149 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005150 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005152 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005153
5154 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5155 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5156
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005159 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005160 // This setting doesn't require an active ImsService connection, so do not verify. The
5161 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005162 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005163 } catch (ImsException e) {
5164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
5168 }
5169
5170 @Override
5171 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5173 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005174
5175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5176 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5177
Brad Ebinger35c841c2018-10-01 10:40:55 -07005178 final long identity = Binder.clearCallingIdentity();
5179 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005180 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005181 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005182 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005183 } catch (ImsException e) {
5184 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005185 } finally {
5186 Binder.restoreCallingIdentity(identity);
5187 }
5188 }
5189
shilu366312e2019-12-17 09:28:10 -08005190 /**
5191 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5192 * @param subId The subscription to use to check the configuration.
5193 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005194 @Override
5195 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005196 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005197 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005198
5199 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5200 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5201
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005204 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005205 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005206 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (ImsException e) {
5208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
5214 @Override
5215 public void setVoWiFiModeSetting(int subId, int mode) {
5216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5217 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005218
5219 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5220 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5221
Brad Ebinger35c841c2018-10-01 10:40:55 -07005222 final long identity = Binder.clearCallingIdentity();
5223 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005224 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005225 // This setting doesn't require an active ImsService connection, so do not verify. The
5226 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005227 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005228 } catch (ImsException e) {
5229 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
5233 }
5234
5235 @Override
5236 public int getVoWiFiRoamingModeSetting(int subId) {
5237 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005238
5239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5240 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5241
Brad Ebinger35c841c2018-10-01 10:40:55 -07005242 final long identity = Binder.clearCallingIdentity();
5243 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005244 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005245 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005246 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005247 } catch (ImsException e) {
5248 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 @Override
5255 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5257 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005258
5259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5260 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5261
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 final long identity = Binder.clearCallingIdentity();
5263 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005264 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005265 // This setting doesn't require an active ImsService connection, so do not verify. The
5266 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005267 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005268 } catch (ImsException e) {
5269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
5273 }
5274
5275 @Override
5276 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5278 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005279
5280 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5281 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5282
Brad Ebinger35c841c2018-10-01 10:40:55 -07005283 final long identity = Binder.clearCallingIdentity();
5284 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005285 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005286 // This setting doesn't require an active ImsService connection, so do not verify. The
5287 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005288 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005289 } catch (ImsException e) {
5290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
5294 }
5295
shilu366312e2019-12-17 09:28:10 -08005296 /**
5297 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5298 * @param subId The subscription to use to check the configuration.
5299 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005300 @Override
5301 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005302 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005303 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005304
5305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5306 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5307
Brad Ebinger35c841c2018-10-01 10:40:55 -07005308 final long identity = Binder.clearCallingIdentity();
5309 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005310 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005311 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005312 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005313 } catch (ImsException e) {
5314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005320 @Override
5321 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5322 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005323
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005326 if (!isImsAvailableOnDevice()) {
5327 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5328 "IMS not available on device.");
5329 }
5330 int slotId = getSlotIndexOrException(subId);
5331 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005332
5333 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5334 if (controller != null) {
5335 ImsManager imsManager = controller.getImsManager(subId);
5336 if (imsManager != null) {
5337 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5338 } else {
5339 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5340 }
5341 } else {
5342 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5343 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005344 } catch (ImsException e) {
5345 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005346 } finally {
5347 Binder.restoreCallingIdentity(identity);
5348 }
5349 }
5350
5351 @Override
5352 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5353 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005354
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005355 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005356 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5357 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5358 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005359 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005360 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5361 if (controller != null) {
5362 ImsManager imsManager = controller.getImsManager(subId);
5363 if (imsManager != null) {
5364 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5365 } else {
5366 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5367 + " is inactive, ignoring unregister.");
5368 // If the ImsManager is not valid, just return, since the callback will already
5369 // have been removed internally.
5370 }
5371 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
5375 }
5376
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 @Override
5378 public void registerFeatureProvisioningChangedCallback(int subId,
5379 IFeatureProvisioningCallback callback) {
5380 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5381 mApp, subId, "registerFeatureProvisioningChangedCallback");
5382
5383 final long identity = Binder.clearCallingIdentity();
5384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5386 }
5387
joonhunshin91bc1952022-04-29 08:47:15 +00005388 try {
5389 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5390 if (controller == null) {
5391 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5392 "Device does not support IMS");
5393 }
5394 controller.addFeatureProvisioningChangedCallback(subId, callback);
5395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005398 }
5399
5400 @Override
5401 public void unregisterFeatureProvisioningChangedCallback(int subId,
5402 IFeatureProvisioningCallback callback) {
5403 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5404 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5405
5406 final long identity = Binder.clearCallingIdentity();
5407 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5408 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5409 }
5410
joonhunshin91bc1952022-04-29 08:47:15 +00005411 try {
5412 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5413 if (controller == null) {
5414 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5415 return;
5416 }
5417 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005421 }
allenwtsu99c623b2020-01-03 18:24:23 +08005422
5423 private void checkModifyPhoneStatePermission(int subId, String message) {
5424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5425 message);
5426 }
5427
allenwtsu99c623b2020-01-03 18:24:23 +08005428 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005429 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005430 boolean isProvisioned) {
5431 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5432
joonhunshin4ac60942023-11-15 15:23:39 +00005433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5434 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5435
allenwtsu99c623b2020-01-03 18:24:23 +08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005438 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5439 if (controller == null) {
5440 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5441 return;
5442 }
5443 controller.setRcsProvisioningStatusForCapability(
5444 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
allenwtsu99c623b2020-01-03 18:24:23 +08005448 }
5449
5450
5451 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005452 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5453 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5454 mApp, subId, "getRcsProvisioningStatusForCapability");
5455
joonhunshin4ac60942023-11-15 15:23:39 +00005456 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5457 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5458
allenwtsu99c623b2020-01-03 18:24:23 +08005459 final long identity = Binder.clearCallingIdentity();
5460 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005461 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5462 if (controller == null) {
5463 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5464
5465 // device does not support IMS, this method will return true always.
5466 return true;
5467 }
5468 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
5472 }
5473
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005474 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005475 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5476 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005477 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005478
joonhunshin4ac60942023-11-15 15:23:39 +00005479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5480 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5481
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005482 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005485 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5486 if (controller == null) {
5487 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5488 return;
5489 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005490 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005491 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
5495 }
5496
5497 @Override
5498 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005499 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5500 mApp, subId, "getProvisioningStatusForCapability");
5501
joonhunshin4ac60942023-11-15 15:23:39 +00005502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5503 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5504
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005505 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005506 final long identity = Binder.clearCallingIdentity();
5507 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005508 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5509 if (controller == null) {
5510 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005511
joonhunshin91bc1952022-04-29 08:47:15 +00005512 // device does not support IMS, this method will return true always.
5513 return true;
5514 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005515 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5516 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005517 } finally {
5518 Binder.restoreCallingIdentity(identity);
5519 }
5520 }
5521
5522 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005523 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5525 mApp, subId, "isProvisioningRequiredForCapability");
5526
joonhunshin4ac60942023-11-15 15:23:39 +00005527 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5528 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5529
joonhunshincffb7fc2021-11-28 07:32:01 +00005530 final long identity = Binder.clearCallingIdentity();
5531 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005532 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5533 if (controller == null) {
5534 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5535
5536 // device does not support IMS, this method will return false
5537 return false;
5538 }
5539 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005540 } finally {
5541 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005542 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005543 }
5544
5545 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005546 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5547 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5548 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005549
joonhunshin4ac60942023-11-15 15:23:39 +00005550 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5551 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5552
joonhunshincffb7fc2021-11-28 07:32:01 +00005553 final long identity = Binder.clearCallingIdentity();
5554 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005555 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5556 if (controller == null) {
5557 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5558
5559 // device does not support IMS, this method will return false
5560 return false;
5561 }
5562 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 }
5567
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005568 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005569 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005570 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5571 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5572 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5574 mApp, subId, "getImsProvisioningInt");
5575
joonhunshin4ac60942023-11-15 15:23:39 +00005576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5577 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5578
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005579 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005583 int slotId = getSlotIndex(subId);
5584 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5585 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5586 + subId + "' for key:" + key);
5587 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5588 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005589
joonhunshin91bc1952022-04-29 08:47:15 +00005590 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5591 if (controller == null) {
5592 loge("getImsProvisioningInt: Device does not support IMS");
5593
5594 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5595 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5596 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005597 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5598 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005599 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5600 return retVal;
5601 }
5602
calvinpanb5a34062021-02-08 19:59:36 +08005603 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005604 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005605 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5606 + subId + "' for key:" + key);
5607 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
5611 }
5612
5613 @Override
5614 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5616 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5617 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005618 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5619 mApp, subId, "getImsProvisioningString");
5620
joonhunshin4ac60942023-11-15 15:23:39 +00005621 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5622 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5623
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005627 int slotId = getSlotIndex(subId);
5628 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5629 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5630 + subId + "' for key:" + key);
5631 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5632 }
calvinpanb5a34062021-02-08 19:59:36 +08005633 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005634 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005635 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5636 + subId + "' for key:" + key);
5637 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
5641 }
5642
5643 @Override
5644 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5646 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5647 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5649 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005650
joonhunshin4ac60942023-11-15 15:23:39 +00005651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5652 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5653
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005654 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005658 int slotId = getSlotIndex(subId);
5659 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5660 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5661 + subId + "' for key:" + key);
5662 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5663 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005664
joonhunshin91bc1952022-04-29 08:47:15 +00005665 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5666 if (controller == null) {
5667 loge("setImsProvisioningInt: Device does not support IMS");
5668
5669 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5670 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5671 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005672 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5673 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005674 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5675 return retVal;
5676 }
5677
calvinpanb5a34062021-02-08 19:59:36 +08005678 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5679 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005680 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005681 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 @Override
5689 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005690 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5691 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5692 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5694 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005695
5696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5697 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5698
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005702 int slotId = getSlotIndex(subId);
5703 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5704 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5705 + subId + "' for key:" + key);
5706 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5707 }
calvinpanb5a34062021-02-08 19:59:36 +08005708 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5709 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005710 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005711 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005712 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
5716 }
5717
Brad Ebinger919631e2021-06-02 17:46:35 -07005718 /**
5719 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5720 * for the given slot ID or no ImsResolver instance has been created.
5721 * @param slotId The slot ID that the IMS service is created for.
5722 * @throws ImsException If there is no ImsService configured for this slot.
5723 */
5724 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5725 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5726 ImsFeature.FEATURE_MMTEL)) {
5727 throw new ImsException("This subscription does not support MMTEL over IMS",
5728 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5729 }
5730 }
5731
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005732 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005733 int slotId = SubscriptionManager.getSlotIndex(subId);
5734 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005735 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5736 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005737 }
5738 return slotId;
5739 }
5740
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005741 private int getSlotIndex(int subId) {
5742 int slotId = SubscriptionManager.getSlotIndex(subId);
5743 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5744 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5745 }
5746 return slotId;
5747 }
5748
Wink Saville36469e72014-06-11 15:17:00 -07005749 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005750 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005751 */
5752 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005753 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5754 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005755 try {
5756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5757 } catch (SecurityException se) {
5758 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5759 throw new SecurityException("Package " + callingPackage + " does not belong to "
5760 + Binder.getCallingUid());
5761 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005762 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005763 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005764 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005765 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005766 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005767 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005768 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005769 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5770 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005771
joonhunshin4ac60942023-11-15 15:23:39 +00005772 enforceTelephonyFeatureWithException(callingPackage,
5773 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 final Phone phone = getPhone(subId);
5778 if (phone != null) {
5779 return phone.getServiceState().getDataNetworkType();
5780 } else {
5781 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5782 }
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005786 }
5787
5788 /**
5789 * Returns the data network type
5790 */
5791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005792 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005793 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005794 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005795 }
5796
5797 /**
5798 * Returns the data network type for a subId
5799 */
5800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005801 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5802 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005803 String functionName = "getDataNetworkTypeForSubscriber";
5804 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5805 mApp, functionName)) {
5806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5807 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5808 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5809 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005810 }
5811
joonhunshin4ac60942023-11-15 15:23:39 +00005812 enforceTelephonyFeatureWithException(callingPackage,
5813 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 final Phone phone = getPhone(subId);
5818 if (phone != null) {
5819 return phone.getServiceState().getDataNetworkType();
5820 } else {
5821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5822 }
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005826 }
5827
5828 /**
Wink Saville36469e72014-06-11 15:17:00 -07005829 * Returns the Voice network type for a subId
5830 */
5831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005832 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5833 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005834 String functionName = "getVoiceNetworkTypeForSubscriber";
5835 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5836 mApp, functionName)) {
5837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5838 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5839 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5840 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005841 }
5842
joonhunshin4ac60942023-11-15 15:23:39 +00005843 enforceTelephonyFeatureWithException(callingPackage,
5844 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 final Phone phone = getPhone(subId);
5849 if (phone != null) {
5850 return phone.getServiceState().getVoiceNetworkType();
5851 } else {
5852 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5853 }
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005857 }
5858
5859 /**
5860 * @return true if a ICC card is present
5861 */
5862 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005863 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005864 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005865 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005866 }
5867
5868 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005869 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005870 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005871 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005872 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005873 if (!mApp.getResources().getBoolean(
5874 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5875 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5876 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5877 }
joonhunshin4ac60942023-11-15 15:23:39 +00005878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 final Phone phone = PhoneFactory.getPhone(slotIndex);
5882 if (phone != null) {
5883 return phone.getIccCard().hasIccCard();
5884 } else {
5885 return false;
5886 }
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005890 }
5891
5892 /**
5893 * Return if the current radio is LTE on CDMA. This
5894 * is a tri-state return value as for a period of time
5895 * the mode may be unknown.
5896 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005897 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005898 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005899 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005900 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005901 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005902 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5903 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5904 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005905 }
5906
Sanket Padawe356d7632015-06-22 14:03:32 -07005907 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005908 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5909 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005910 try {
5911 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5912 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005913 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5914 }
5915
joonhunshin4ac60942023-11-15 15:23:39 +00005916 enforceTelephonyFeatureWithException(callingPackage,
5917 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 final long identity = Binder.clearCallingIdentity();
5920 try {
5921 final Phone phone = getPhone(subId);
5922 if (phone == null) {
5923 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5924 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005925 return TelephonyProperties.lte_on_cdma_device()
5926 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 }
5928 } finally {
5929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005930 }
Wink Saville36469e72014-06-11 15:17:00 -07005931 }
5932
Wink Saville36469e72014-06-11 15:17:00 -07005933 /**
5934 * {@hide}
5935 * Returns Default subId, 0 in the case of single standby.
5936 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005937 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005938 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005939 }
5940
Shishir Agrawala9f32182016-04-12 12:00:16 -07005941 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005942 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005943 }
5944
Wink Savilleb564aae2014-10-23 10:18:09 -07005945 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005946 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005947 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005948
Pengquan Menge92a50d2018-09-21 15:54:48 -07005949 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005950 return getSubscriptionManagerService().isActiveSubId(subId,
5951 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005952 }
5953
Ihab Awadf2177b72013-11-25 13:33:23 -08005954 /**
5955 * @see android.telephony.TelephonyManager.WifiCallingChoices
5956 */
5957 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 final long identity = Binder.clearCallingIdentity();
5959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5962 getWhenToMakeWifiCallsDefaultPreference());
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005966 }
5967
5968 /**
5969 * @see android.telephony.TelephonyManager.WifiCallingChoices
5970 */
5971 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 final long identity = Binder.clearCallingIdentity();
5973 try {
5974 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005975 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005980 }
5981
Sailesh Nepald1e68152013-12-12 19:08:02 -08005982 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005983 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005984 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005985 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005986
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005987 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5988 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5989 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005990 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005991 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005992 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005993 }
5994 return PhoneFactory.getPhone(phoneId);
5995 }
5996
Shishir Agrawal566b7612013-10-28 14:41:00 -07005997 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005998 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005999 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006000
Rambo Wanga1782702021-11-10 20:15:19 -08006001 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6002 /*message=*/ "iccOpenLogicalChannel");
6003
6004 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6005 // Verify that the callingPackage in the request belongs to the calling UID
6006 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6007
joonhunshin4ac60942023-11-15 15:23:39 +00006008 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6009 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6010
Rambo Wanga1782702021-11-10 20:15:19 -08006011 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006012 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006013
Rambo Wanga1782702021-11-10 20:15:19 -08006014 private Phone getPhoneFromValidIccLogicalChannelRequest(
6015 @NonNull IccLogicalChannelRequest request, String message) {
6016 Phone phone;
6017 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6019 mApp, request.subId, message);
6020 phone = getPhoneFromSubId(request.subId);
6021 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6022 enforceModifyPermission();
6023 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6024 } else {
6025 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006026 }
Rambo Wanga1782702021-11-10 20:15:19 -08006027 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006028 }
6029
6030 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006031 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 final long identity = Binder.clearCallingIdentity();
6033 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006034 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006036 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6037 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006038 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6039 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 loge("The calling package is not allowed to access ISD-R.");
6041 throw new SecurityException(
6042 "The calling package is not allowed to access ISD-R.");
6043 }
Derek Tan740e1672017-06-27 14:56:27 -07006044 }
Derek Tan740e1672017-06-27 14:56:27 -07006045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006047 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6048 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 return response;
6050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006053 }
6054
6055 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006056 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006057 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6058 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6059
Rambo Wanga1782702021-11-10 20:15:19 -08006060 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6061 /*message=*/"iccCloseLogicalChannel");
6062
6063 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6064
6065 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006066 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006067
Rambo Wanga1782702021-11-10 20:15:19 -08006068 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6069 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006070 // before this feature is enabled, this API should only return false if
6071 // the operation fails instead of throwing runtime exception for
6072 // backward-compatibility.
6073 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6074 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 final long identity = Binder.clearCallingIdentity();
6076 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006077 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006078 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 }
Chen Xue9d737e2022-01-01 23:41:31 -08006080 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006081 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006082 Boolean success = false;
6083 if (result instanceof RuntimeException) {
6084 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006085 if (shouldThrowExceptionOnFailure) {
6086 throw (RuntimeException) result;
6087 } else {
6088 return false;
6089 }
Chen Xue9d737e2022-01-01 23:41:31 -08006090 } else if (result instanceof Boolean) {
6091 success = (Boolean) result;
6092 } else {
6093 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6094 }
Rambo Wanga1782702021-11-10 20:15:19 -08006095 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 return success;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006100 }
6101
6102 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006103 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006104 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6106 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006107
6108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6109 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6110
Jordan Liu4c733742019-02-28 12:03:40 -08006111 if (DBG) {
6112 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6113 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6114 + p3 + " data=" + data);
6115 }
6116 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6117 command, p1, p2, p3, data);
6118 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006119
Jordan Liu4c733742019-02-28 12:03:40 -08006120 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006121 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006122 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006123 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006124
6125 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6126 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6127 "iccTransmitApduLogicalChannelBySlot");
6128
Jordan Liu4c733742019-02-28 12:03:40 -08006129 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006130 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006131 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6132 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006133 }
6134 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006135 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6136 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006137 }
6138
6139 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6140 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 final long identity = Binder.clearCallingIdentity();
6142 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006143 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 return "";
6145 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006148 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6149 null /* workSource */);
6150 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 // Append the returned status code to the end of the response payload.
6153 String s = Integer.toHexString(
6154 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6155 if (response.payload != null) {
6156 s = IccUtils.bytesToHexString(response.payload) + s;
6157 }
6158 return s;
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006161 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006162 }
Jake Hambye994d462014-02-03 13:10:13 -08006163
Evan Charltonc66da362014-05-16 14:06:40 -07006164 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006165 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6166 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6168 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006170
6171 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6172 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6173
Jordan Liu4c733742019-02-28 12:03:40 -08006174 if (DBG) {
6175 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6176 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6177 }
6178 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6179 cla, command, p1, p2, p3, data);
6180 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181
Jordan Liu4c733742019-02-28 12:03:40 -08006182 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006183 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006184 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006185 enforceModifyPermission();
6186 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006187
6188 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6189 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6190
Jordan Liu4c733742019-02-28 12:03:40 -08006191 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006192 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006193 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6194 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006195 }
6196
6197 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006198 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6199 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006200 }
6201
6202 // open APDU basic channel assuming the caller has sufficient permissions
6203 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6204 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6208 && TextUtils.equals(ISDR_AID, data)) {
6209 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006210 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6211 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 if (bestComponent == null
6213 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6214 loge("The calling package is not allowed to select ISD-R.");
6215 throw new SecurityException(
6216 "The calling package is not allowed to select ISD-R.");
6217 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006218 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006221 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6222 null /* workSource */);
6223 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 // Append the returned status code to the end of the response payload.
6226 String s = Integer.toHexString(
6227 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6228 if (response.payload != null) {
6229 s = IccUtils.bytesToHexString(response.payload) + s;
6230 }
6231 return s;
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006234 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006235 }
6236
6237 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006238 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006239 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6241 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006242
joonhunshin4ac60942023-11-15 15:23:39 +00006243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6244 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 final long identity = Binder.clearCallingIdentity();
6247 try {
6248 if (DBG) {
6249 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6250 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6251 }
6252
6253 IccIoResult response =
6254 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6255 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6256 subId);
6257
6258 if (DBG) {
6259 log("Exchange SIM_IO [R]" + response);
6260 }
6261
6262 byte[] result = null;
6263 int length = 2;
6264 if (response.payload != null) {
6265 length = 2 + response.payload.length;
6266 result = new byte[length];
6267 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6268 } else {
6269 result = new byte[length];
6270 }
6271
6272 result[length - 1] = (byte) response.sw2;
6273 result[length - 2] = (byte) response.sw1;
6274 return result;
6275 } finally {
6276 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006277 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006278 }
6279
Nathan Haroldb3014052017-01-25 15:57:32 -08006280 /**
6281 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6282 * on a particular subscription
6283 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006284 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6285 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006287 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006288 return null;
6289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
joonhunshin4ac60942023-11-15 15:23:39 +00006291 enforceTelephonyFeatureWithException(callingPackage,
6292 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 final long identity = Binder.clearCallingIdentity();
6295 try {
6296 if (appType != TelephonyManager.APPTYPE_USIM
6297 && appType != TelephonyManager.APPTYPE_SIM) {
6298 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6299 return null;
6300 }
6301 Object response = sendRequest(
6302 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6303 if (response instanceof String[]) {
6304 return (String[]) response;
6305 }
yincheng zhao2737e882019-09-06 17:06:54 -07006306 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006308 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 } finally {
6310 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006311 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006312 }
6313
yincheng zhao2737e882019-09-06 17:06:54 -07006314 /**
6315 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6316 * subscription.
6317 *
6318 * @param subId the id of the subscription.
6319 * @param appType the uicc app type, must be USIM or SIM.
6320 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6321 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006322 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006323 * @return number of fplmns that is successfully written to the SIM.
6324 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006325 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6326 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6328 mApp, subId, "setForbiddenPlmns");
6329
joonhunshin4ac60942023-11-15 15:23:39 +00006330 enforceTelephonyFeatureWithException(callingPackage,
6331 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6332
yincheng zhao2737e882019-09-06 17:06:54 -07006333 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6334 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6335 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6336 }
6337 if (fplmns == null) {
6338 throw new IllegalArgumentException("Fplmn List provided is null");
6339 }
6340 for (String fplmn : fplmns) {
6341 if (!CellIdentity.isValidPlmn(fplmn)) {
6342 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6343 }
6344 }
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 Object response = sendRequest(
6348 CMD_SET_FORBIDDEN_PLMNS,
6349 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6350 subId);
6351 return (int) response;
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
6355 }
6356
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006357 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006358 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6360 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006361
joonhunshin4ac60942023-11-15 15:23:39 +00006362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6363 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6368 if (response.payload == null) {
6369 return "";
6370 }
Evan Charltonc66da362014-05-16 14:06:40 -07006371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 // Append the returned status code to the end of the response payload.
6373 String s = Integer.toHexString(
6374 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6375 s = IccUtils.bytesToHexString(response.payload) + s;
6376 return s;
6377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
Evan Charltonc66da362014-05-16 14:06:40 -07006380 }
6381
Jake Hambye994d462014-02-03 13:10:13 -08006382 /**
6383 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6384 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6385 *
6386 * @param itemID the ID of the item to read
6387 * @return the NV item as a String, or null on error.
6388 */
6389 @Override
6390 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006391 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6393 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
6397 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006398 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6400 return value;
6401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
Jake Hambye994d462014-02-03 13:10:13 -08006404 }
6405
6406 /**
6407 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6408 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6409 *
6410 * @param itemID the ID of the item to read
6411 * @param itemValue the value to write, as a String
6412 * @return true on success; false on any failure
6413 */
6414 @Override
6415 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006416 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6418 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419
6420 final long identity = Binder.clearCallingIdentity();
6421 try {
6422 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6423 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006424 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6426 return success;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
Jake Hambye994d462014-02-03 13:10:13 -08006430 }
6431
6432 /**
6433 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6434 * Used for device configuration by some CDMA operators.
6435 *
6436 * @param preferredRoamingList byte array containing the new PRL
6437 * @return true on success; false on any failure
6438 */
6439 @Override
6440 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6442 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443
6444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6447 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6448 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6449 return success;
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
Jake Hambye994d462014-02-03 13:10:13 -08006453 }
6454
6455 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006456 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006457 * Used for device configuration by some CDMA operators.
6458 *
chen xu6dac5ab2018-10-26 17:39:23 -07006459 * @param slotIndex - device slot.
6460 *
Jake Hambye994d462014-02-03 13:10:13 -08006461 * @return true on success; false on any failure
6462 */
6463 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006464 public boolean resetModemConfig(int slotIndex) {
6465 Phone phone = PhoneFactory.getPhone(slotIndex);
6466 if (phone != null) {
6467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6468 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469
joonhunshin4ac60942023-11-15 15:23:39 +00006470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6471 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6472
chen xu6dac5ab2018-10-26 17:39:23 -07006473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6476 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6477 return success;
6478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 }
chen xu6dac5ab2018-10-26 17:39:23 -07006482 return false;
6483 }
6484
6485 /**
6486 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6487 *
6488 * @param slotIndex - device slot.
6489 *
6490 * @return true on success; false on any failure
6491 */
6492 @Override
6493 public boolean rebootModem(int slotIndex) {
6494 Phone phone = PhoneFactory.getPhone(slotIndex);
6495 if (phone != null) {
6496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6497 mApp, phone.getSubId(), "rebootModem");
6498
joonhunshin4ac60942023-11-15 15:23:39 +00006499 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6500 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6501
chen xu6dac5ab2018-10-26 17:39:23 -07006502 final long identity = Binder.clearCallingIdentity();
6503 try {
6504 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6505 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6506 return success;
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
6510 }
6511 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006512 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006513
Brad Ebinger51f743a2017-01-23 13:50:20 -08006514 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006515 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6516 * {@link #disableIms(int)}.
6517 * @param slotIndex device slot.
6518 */
6519 public void resetIms(int slotIndex) {
6520 enforceModifyPermission();
6521
joonhunshin4ac60942023-11-15 15:23:39 +00006522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6523 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6524
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006525 final long identity = Binder.clearCallingIdentity();
6526 try {
6527 if (mImsResolver == null) {
6528 // may happen if the does not support IMS.
6529 return;
6530 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006531 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
6537 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006538 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6539 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006540 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006541 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006546 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006547 // may happen if the device does not support IMS.
6548 return;
6549 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006550 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006554 }
6555
6556 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006557 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6558 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006559 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006560 public void disableIms(int slotId) {
6561 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006565 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006566 // may happen if the device does not support IMS.
6567 return;
6568 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006569 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006573 }
6574
6575 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006576 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6577 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006578 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006579 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006580 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582
6583 final long identity = Binder.clearCallingIdentity();
6584 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006585 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006586 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6587 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006588 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006589 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
6592 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006593 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006594 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006595 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6596 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006597 @Override
6598 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006599 enforceModifyPermission();
6600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006604 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
6608 }
6609
6610 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006611 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006612 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006613 */
6614 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006619 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006620 // may happen if the device does not support IMS.
6621 return null;
6622 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006623 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006627 }
6628
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006629 /**
6630 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006631 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006632 */
6633 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006638 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006639 // may happen if the device does not support IMS.
6640 return null;
6641 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006642 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006646 }
6647
Brad Ebinger884c07b2018-02-15 16:17:40 -08006648 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006649 * Sets the ImsService Package Name that Telephony will bind to.
6650 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 * @param slotIndex the slot ID that the ImsService should bind for.
6652 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006653 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 * @param featureTypes An integer array of feature types associated with a packageName.
6655 * @param packageName The name of the package that the current configuration will be replaced
6656 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006657 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006658 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006659 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6660 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006663 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 final long identity = Binder.clearCallingIdentity();
6666 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006667 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006668 // may happen if the device does not support IMS.
6669 return false;
6670 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006671 Map<Integer, String> featureConfig = new HashMap<>();
6672 for (int featureType : featureTypes) {
6673 featureConfig.put(featureType, packageName);
6674 }
6675 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6676 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006680 }
6681
6682 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006683 * Clears any carrier ImsService overrides for the slot index specified that were previously
6684 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6685 *
6686 * This should only be used for testing.
6687 *
6688 * @param slotIndex the slot ID that the ImsService should bind for.
6689 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6690 */
6691 @Override
6692 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6694 "clearCarrierImsServiceOverride");
6695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006696 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006697
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 if (mImsResolver == null) {
6701 // may happen if the device does not support IMS.
6702 return false;
6703 }
6704 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
6708 }
6709
6710 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006711 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006712 *
6713 * @param slotId The slot that the ImsService is associated with.
6714 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6715 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006716 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006717 * @return the package name of the ImsService configuration.
6718 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006719 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6720 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006721 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006722 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6723 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 final long identity = Binder.clearCallingIdentity();
6726 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006727 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006728 // may happen if the device does not support IMS.
6729 return "";
6730 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006731 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006732 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6733 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006737 }
6738
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006739 /**
6740 * Get the MmTelFeature state associated with the requested subscription id.
6741 * @param subId The subscription that the MmTelFeature is associated with.
6742 * @param callback A callback with an integer containing the
6743 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6744 */
6745 @Override
6746 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6747 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006748 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6749 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6750 "IMS not available on device.");
6751 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006752 final long token = Binder.clearCallingIdentity();
6753 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006754 int slotId = getSlotIndex(subId);
6755 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6756 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6757 + subId + "'");
6758 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6759 }
6760 verifyImsMmTelConfiguredOrThrow(slotId);
6761 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6762 try {
6763 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6764 } catch (RemoteException e) {
6765 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6766 + "Ignore");
6767 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006768 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006769 } catch (ImsException e) {
6770 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006771 } finally {
6772 Binder.restoreCallingIdentity(token);
6773 }
6774 }
6775
Daniel Brightbb5840b2021-01-12 15:48:18 -08006776 /**
6777 * Sets the ims registration state on all valid {@link Phone}s.
6778 */
6779 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781
6782 final long identity = Binder.clearCallingIdentity();
6783 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006784 // NOTE: Before S, this method only set the default phone.
6785 for (final Phone phone : PhoneFactory.getPhones()) {
6786 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6787 phone.setImsRegistrationState(registered);
6788 }
6789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
Wink Saville36469e72014-06-11 15:17:00 -07006793 }
6794
6795 /**
Stuart Scott54788802015-03-30 13:18:01 -07006796 * Set the network selection mode to automatic.
6797 *
6798 */
6799 @Override
6800 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6802 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803
joonhunshin4ac60942023-11-15 15:23:39 +00006804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6805 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807 final long identity = Binder.clearCallingIdentity();
6808 try {
shilufc958392020-01-20 11:36:01 -08006809 if (!isActiveSubscription(subId)) {
6810 return;
6811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006813 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006814 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
Stuart Scott54788802015-03-30 13:18:01 -07006818 }
6819
Jack Yud10cdd42020-09-28 20:28:01 -07006820 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006821 * Ask the radio to connect to the input network and change selection mode to manual.
6822 *
6823 * @param subId the id of the subscription.
6824 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6825 * the operator to attach to.
6826 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6827 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6828 * normal network selection next time.
6829 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006830 */
6831 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006832 public boolean setNetworkSelectionModeManual(
6833 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6835 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006836
joonhunshin4ac60942023-11-15 15:23:39 +00006837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6838 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6839
Jack Yu285100e2022-12-02 22:48:35 -08006840 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006841 if (!isActiveSubscription(subId)) {
6842 return false;
6843 }
6844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006846 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006848 if (DBG) {
6849 log("setNetworkSelectionModeManual: subId: " + subId
6850 + " operator: " + operatorInfo);
6851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006856 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006857 /**
shilu84f6e8b2019-12-19 13:58:01 -08006858 * Get the manual network selection
6859 *
6860 * @param subId the id of the subscription.
6861 *
6862 * @return the previously saved user selected PLMN
6863 */
6864 @Override
6865 public String getManualNetworkSelectionPlmn(int subId) {
6866 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006867 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6868 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006869
joonhunshin4ac60942023-11-15 15:23:39 +00006870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6871 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6872
shilu84f6e8b2019-12-19 13:58:01 -08006873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006876 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006877 }
6878
6879 final Phone phone = getPhone(subId);
6880 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006881 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006882 }
6883 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6884 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006885 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
6889 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006890
6891 /**
6892 * Scans for available networks.
6893 */
6894 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006895 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6896 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6898 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006899 LocationAccessPolicy.LocationPermissionResult locationResult =
6900 LocationAccessPolicy.checkLocationPermission(mApp,
6901 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6902 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006903 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006904 .setCallingPid(Binder.getCallingPid())
6905 .setCallingUid(Binder.getCallingUid())
6906 .setMethod("getCellNetworkScanResults")
6907 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006908 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006910 .build());
6911 switch (locationResult) {
6912 case DENIED_HARD:
6913 throw new SecurityException("Not allowed to access scan results -- location");
6914 case DENIED_SOFT:
6915 return null;
6916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917
Pengquan Menga1bb6272018-09-06 09:59:22 -07006918 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 try {
6920 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006921 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006926 }
6927
6928 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006929 * Get the call forwarding info, given the call forwarding reason.
6930 */
6931 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006932 public void getCallForwarding(int subId, int callForwardingReason,
6933 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006934 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006935
6936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6937 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6938
Shuo Qian4a594052020-01-23 11:59:30 -08006939 long identity = Binder.clearCallingIdentity();
6940 try {
6941 if (DBG) {
6942 log("getCallForwarding: subId " + subId
6943 + " callForwardingReason" + callForwardingReason);
6944 }
Hall Liu27d24262020-09-18 19:04:59 -07006945
6946 Phone phone = getPhone(subId);
6947 if (phone == null) {
6948 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006949 callback.onError(
6950 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006951 } catch (RemoteException e) {
6952 // ignore
6953 }
6954 return;
6955 }
6956
6957 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6958 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6959 @Override
6960 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6961 try {
6962 callback.onCallForwardingInfoAvailable(info);
6963 } catch (RemoteException e) {
6964 // ignore
6965 }
6966 }
6967
6968 @Override
6969 public void onError(int error) {
6970 try {
6971 callback.onError(error);
6972 } catch (RemoteException e) {
6973 // ignore
6974 }
6975 }
6976 });
6977 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006978 } finally {
6979 Binder.restoreCallingIdentity(identity);
6980 }
6981 }
6982
6983 /**
6984 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6985 * reason, the number to forward, and the timeout before the forwarding is attempted.
6986 */
6987 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006988 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6989 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006990 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006991
6992 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6993 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6994
Shuo Qian4a594052020-01-23 11:59:30 -08006995 long identity = Binder.clearCallingIdentity();
6996 try {
6997 if (DBG) {
6998 log("setCallForwarding: subId " + subId
6999 + " callForwardingInfo" + callForwardingInfo);
7000 }
Hall Liu27d24262020-09-18 19:04:59 -07007001
7002 Phone phone = getPhone(subId);
7003 if (phone == null) {
7004 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007005 callback.accept(
7006 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007007 } catch (RemoteException e) {
7008 // ignore
7009 }
7010 return;
7011 }
7012
7013 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7014 FunctionalUtils.ignoreRemoteException(callback::accept));
7015
7016 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
7020 }
7021
7022 /**
Hall Liu27d24262020-09-18 19:04:59 -07007023 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007024 */
7025 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007026 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007027 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007028
7029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7030 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7031
Shuo Qian4a594052020-01-23 11:59:30 -08007032 long identity = Binder.clearCallingIdentity();
7033 try {
Hall Liu27d24262020-09-18 19:04:59 -07007034 Phone phone = getPhone(subId);
7035 if (phone == null) {
7036 try {
7037 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7038 } catch (RemoteException e) {
7039 // ignore
7040 }
7041 return;
7042 }
SongFerngWang0e767992021-03-31 22:08:45 +08007043 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7044 PersistableBundle c = configManager.getConfigForSubId(subId);
7045 boolean requireUssd = c.getBoolean(
7046 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007047
Shuo Qian4a594052020-01-23 11:59:30 -08007048 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007049 if (requireUssd) {
7050 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7051 getSubscriptionCarrierId(subId));
7052 String newUssdCommand = "";
7053 try {
7054 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007055 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007056 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7057 } catch (NullPointerException e) {
7058 loge("Failed to generate USSD number" + e);
7059 }
7060 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7061 mMainThreadHandler, callback, carrierXmlParser,
7062 CarrierXmlParser.SsEntry.SSAction.QUERY);
7063 final String ussdCommand = newUssdCommand;
7064 Executors.newSingleThreadExecutor().execute(() -> {
7065 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7066 });
7067 } else {
7068 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7069 callback::accept);
7070 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7071 }
Shuo Qian4a594052020-01-23 11:59:30 -08007072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
7075 }
7076
7077 /**
Hall Liu27d24262020-09-18 19:04:59 -07007078 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007079 */
7080 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007081 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007082 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007083
7084 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7085 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7086
Shuo Qian4a594052020-01-23 11:59:30 -08007087 long identity = Binder.clearCallingIdentity();
7088 try {
Hall Liu27d24262020-09-18 19:04:59 -07007089 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7090
7091 Phone phone = getPhone(subId);
7092 if (phone == null) {
7093 try {
7094 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7095 } catch (RemoteException e) {
7096 // ignore
7097 }
7098 return;
7099 }
7100
SongFerngWang0e767992021-03-31 22:08:45 +08007101 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7102 PersistableBundle c = configManager.getConfigForSubId(subId);
7103 boolean requireUssd = c.getBoolean(
7104 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007105
SongFerngWang0e767992021-03-31 22:08:45 +08007106 if (DBG) log("getCallWaitingStatus: subId " + subId);
7107 if (requireUssd) {
7108 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7109 getSubscriptionCarrierId(subId));
7110 CarrierXmlParser.SsEntry.SSAction ssAction =
7111 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7112 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7113 String newUssdCommand = "";
7114 try {
7115 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007116 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007117 .makeCommand(ssAction, null);
7118 } catch (NullPointerException e) {
7119 loge("Failed to generate USSD number" + e);
7120 }
7121 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7122 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7123 final String ussdCommand = newUssdCommand;
7124 Executors.newSingleThreadExecutor().execute(() -> {
7125 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7126 });
7127 } else {
7128 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7129 FunctionalUtils.ignoreRemoteException(callback::accept));
7130
7131 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7132 }
Shuo Qian4a594052020-01-23 11:59:30 -08007133 } finally {
7134 Binder.restoreCallingIdentity(identity);
7135 }
7136 }
7137
7138 /**
yinxub1bed742017-04-17 11:45:04 -07007139 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007140 *
yinxub1bed742017-04-17 11:45:04 -07007141 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007142 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7143 * location related information which will be sent if the caller already possess
7144 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007145 * @param request contains the radio access networks with bands/channels to scan
7146 * @param messenger callback messenger for scan results or errors
7147 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007148 * @return the id of the requested scan which can be used to stop the scan.
7149 */
7150 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007151 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7152 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007153 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7155 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007156 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007157 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7158 if (!renounceFineLocationAccess) {
7159 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007160 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7161 .setCallingPackage(callingPackage)
7162 .setCallingFeatureId(callingFeatureId)
7163 .setCallingPid(Binder.getCallingPid())
7164 .setCallingUid(Binder.getCallingUid())
7165 .setMethod("requestNetworkScan")
7166 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7167 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7168 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7169 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007170 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007171 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007172 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7173 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007174 if (e != null) {
7175 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7176 throw e;
7177 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007178 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007179 return TelephonyScanManager.INVALID_SCAN_ID;
7180 }
7181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 }
joonhunshin4ac60942023-11-15 15:23:39 +00007183
7184 enforceTelephonyFeatureWithException(callingPackage,
7185 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7186
Hall Liu912dfd32019-04-25 14:02:26 -07007187 int callingUid = Binder.getCallingUid();
7188 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007189 final long identity = Binder.clearCallingIdentity();
7190 try {
7191 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007192 renounceFineLocationAccess, request, messenger, binder,
7193 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007194 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007195 } finally {
7196 Binder.restoreCallingIdentity(identity);
7197 }
yinxu504e1392017-04-12 16:03:22 -07007198 }
7199
Hall Liub2ac8ef2019-02-28 15:56:23 -08007200 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007201 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007202 boolean hasCarrierPriv;
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7206 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
Hall Liu558027f2019-05-15 19:14:05 -07007210 boolean hasNetworkScanPermission =
7211 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007212 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007213
7214 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7215 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7216 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007217 }
7218
7219 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7220 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007221 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7222 return new SecurityException("Specific channels must not be"
7223 + " scanned without location access.");
7224 }
7225 }
7226 }
7227
Hall Liub2ac8ef2019-02-28 15:56:23 -08007228 return null;
7229 }
7230
yinxu504e1392017-04-12 16:03:22 -07007231 /**
7232 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007233 *
7234 * @param subId id of the subscription
7235 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007236 */
7237 @Override
7238 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7240 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241
Hall Liu912dfd32019-04-25 14:02:26 -07007242 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 final long identity = Binder.clearCallingIdentity();
7244 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007245 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
yinxu504e1392017-04-12 16:03:22 -07007249 }
7250
7251 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007252 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007253 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007254 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007255 */
7256 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007257 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007258 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007259 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007260 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261
joonhunshin4ac60942023-11-15 15:23:39 +00007262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7263 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007265 final long identity = Binder.clearCallingIdentity();
7266 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007267 if (DBG) log("getAllowedNetworkTypesBitmask");
7268 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7269 int networkTypesBitmask = (result != null ? result[0] : -1);
7270 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7271 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 } finally {
7273 Binder.restoreCallingIdentity(identity);
7274 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007275 }
7276
7277 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007278 * Get the allowed network types for certain reason.
7279 *
7280 * @param subId the id of the subscription.
7281 * @param reason the reason the allowed network type change is taking place
7282 * @return the allowed network types.
7283 */
7284 @Override
7285 public long getAllowedNetworkTypesForReason(int subId,
7286 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007287 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007288 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007289
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007290 if (!mApp.getResources().getBoolean(
7291 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7293 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7294 "getAllowedNetworkTypesForReason");
7295 }
joonhunshin4ac60942023-11-15 15:23:39 +00007296
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007297 final long identity = Binder.clearCallingIdentity();
7298 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007299 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
7303 }
7304
7305 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007306 * Enable/Disable E-UTRA-NR Dual Connectivity
7307 * @param subId subscription id of the sim card
7308 * @param nrDualConnectivityState expected NR dual connectivity state
7309 * This can be passed following states
7310 * <ol>
7311 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7312 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7313 * <li>Disable NR dual connectivity and force secondary cell to be released
7314 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7315 * </ol>
7316 * @return operation result.
7317 */
7318 @Override
7319 public int setNrDualConnectivityState(int subId,
7320 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7322 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007323 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007324 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7325 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7326 }
7327
Sooraj Sasindran37444802020-08-11 10:40:43 -07007328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7332 nrDualConnectivityState, subId,
7333 workSource);
7334 if (DBG) log("enableNRDualConnectivity result: " + result);
7335 return result;
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
7339 }
7340
7341 /**
7342 * Is E-UTRA-NR Dual Connectivity enabled
7343 * @return true if dual connectivity is enabled else false
7344 */
7345 @Override
7346 public boolean isNrDualConnectivityEnabled(int subId) {
7347 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007348 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007349 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007350 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007351 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7352 return false;
7353 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7355 final long identity = Binder.clearCallingIdentity();
7356 try {
7357 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7358 null, subId, workSource);
7359 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7360 return isEnabled;
7361 } finally {
7362 Binder.restoreCallingIdentity(identity);
7363 }
7364 }
7365
7366 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007367 * Set the allowed network types of the device and
7368 * provide the reason triggering the allowed network change.
7369 *
7370 * @param subId the id of the subscription.
7371 * @param reason the reason the allowed network type change is taking place
7372 * @param allowedNetworkTypes the allowed network types.
7373 * @return true on success; false on any failure.
7374 */
7375 @Override
7376 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007377 @TelephonyManager.AllowedNetworkTypesReason int reason,
7378 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7380 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007381 // If the caller only has carrier privileges, then they should not be able to override
7382 // any network types which were set for security reasons.
7383 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7384 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007385 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007386 throw new SecurityException(
7387 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007388 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007389 }
joonhunshin4ac60942023-11-15 15:23:39 +00007390
7391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7392 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7393
SongFerngWang3ef3e072020-12-21 16:41:52 +08007394 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007395 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007396 return false;
7397 }
7398 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7399 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007400 return false;
7401 }
7402
Jack Yu5b494332023-01-23 18:18:04 +00007403 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7404 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007405
Jack Yue37dd262022-12-16 11:53:37 -08007406 Phone phone = getPhone(subId);
7407 if (phone == null) {
7408 return false;
7409 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007410
Jack Yue37dd262022-12-16 11:53:37 -08007411 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007412 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007413 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007414 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007415
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007416 final long identity = Binder.clearCallingIdentity();
7417 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007418 Boolean success = (Boolean) sendRequest(
7419 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7420 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7421
7422 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7423 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007424 } finally {
7425 Binder.restoreCallingIdentity(identity);
7426 }
7427 }
7428
7429 /**
Miaoa84611c2019-03-15 09:21:10 +08007430 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007431 *
Miaoa84611c2019-03-15 09:21:10 +08007432 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007433 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007434 * @hide
7435 */
7436 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007437 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007438 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007439
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007440 if (!mApp.getResources().getBoolean(
7441 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7443 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7444 }
joonhunshin4ac60942023-11-15 15:23:39 +00007445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 try {
Miaoa84611c2019-03-15 09:21:10 +08007449 if (phone != null) {
7450 return phone.hasMatchedTetherApnSetting();
7451 } else {
7452 return false;
7453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 } finally {
7455 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007456 }
Junda Liu475951f2014-11-07 16:45:03 -08007457 }
7458
7459 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007460 * Get the user enabled state of Mobile Data.
7461 *
7462 * TODO: remove and use isUserDataEnabled.
7463 * This can't be removed now because some vendor codes
7464 * calls through ITelephony directly while they should
7465 * use TelephonyManager.
7466 *
7467 * @return true on enabled
7468 */
7469 @Override
7470 public boolean getDataEnabled(int subId) {
7471 return isUserDataEnabled(subId);
7472 }
7473
7474 /**
7475 * Get whether mobile data is enabled per user setting.
7476 *
7477 * There are other factors deciding whether mobile data is actually enabled, but they are
7478 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007479 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007480 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7481 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007482 *
7483 * @return {@code true} if data is enabled else {@code false}
7484 */
7485 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007486 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007487 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007488 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007489 try {
7490 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7491 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007492 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007493 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7494 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007495 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007497 mApp, subId, functionName);
7498
Robert Greenwalt646120a2014-05-23 11:54:03 -07007499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
Jack Yu285100e2022-12-02 22:48:35 -08007503 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7505 Phone phone = PhoneFactory.getPhone(phoneId);
7506 if (phone != null) {
7507 boolean retVal = phone.isUserDataEnabled();
7508 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7509 return retVal;
7510 } else {
7511 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7512 return false;
7513 }
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007516 }
7517 }
7518
7519 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007520 * Checks if the device is capable of mobile data by considering whether whether the
7521 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7522 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007523 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007524 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007525 */
7526 @Override
7527 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007528 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007529 try {
7530 try {
7531 mApp.enforceCallingOrSelfPermission(
7532 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007533 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007534 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007535 try {
7536 mApp.enforceCallingOrSelfPermission(
7537 android.Manifest.permission.READ_PHONE_STATE,
7538 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007539 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007540 mApp.enforceCallingOrSelfPermission(
7541 permission.READ_BASIC_PHONE_STATE, functionName);
7542 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007543 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007544 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007545 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547
joonhunshin4ac60942023-11-15 15:23:39 +00007548 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7549 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
Jack Yu285100e2022-12-02 22:48:35 -08007553 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007555 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007556 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007557 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 return retVal;
7559 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007560 if (DBG) {
7561 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7562 + subId + " retVal=false");
7563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 return false;
7565 }
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007568 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007569 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007570
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007571 /**
7572 * Check if data is enabled for a specific reason
7573 * @param subId Subscription index
7574 * @param reason the reason the data enable change is taking place
7575 * @return {@code true} if the overall data is enabled; {@code false} if not.
7576 */
7577 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007578 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007579 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007580 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007581 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007582 try {
7583 mApp.enforceCallingOrSelfPermission(
7584 android.Manifest.permission.ACCESS_NETWORK_STATE,
7585 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007586 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007587 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7588 functionName);
7589 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007590 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007591 try {
7592 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007593 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007594 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007596 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007597 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007598 }
7599
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007600 if (!mApp.getResources().getBoolean(
7601 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7602 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7603 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7604 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
Jack Yu285100e2022-12-02 22:48:35 -08007608 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007609 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007610 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007611 + " reason=" + reason);
7612 }
7613 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007614 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007615 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007616 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007617 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007618 return retVal;
7619 } else {
7620 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007621 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007622 + subId + " retVal=false");
7623 }
7624 return false;
7625 }
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
7629 }
7630
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007631 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007632 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007633 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7634 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7635
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007636 // No permission needed; this only lets the caller inspect their own status.
7637 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007638 }
Junda Liu29340342014-07-10 15:23:27 -07007639
7640 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007641 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007642 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007643
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007644 if (!mApp.getResources().getBoolean(
7645 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7646 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7647 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7648 "getCarrierPrivilegeStatusForUid");
7649 }
joonhunshin4ac60942023-11-15 15:23:39 +00007650
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007651 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7652 }
7653
7654 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7655 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007656 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007657 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007658 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7659 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007660 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7661 if (cpt == null) {
7662 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007663 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7664 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007665 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007666 }
7667
7668 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007669 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007670 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007671
7672 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7673 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7674
chen xuf7e9fe82019-05-09 19:31:02 -07007675 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007676 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007677 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007678 Phone phone = getPhone(subId);
7679 if (phone == null) {
7680 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7681 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7682 }
7683 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7684 if (cpt == null) {
7685 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007686 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7687 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007688 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007689 }
7690
7691 @Override
7692 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007693 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007694
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007695 if (!mApp.getResources().getBoolean(
7696 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7697 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7698 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7699 "checkCarrierPrivilegesForPackageAnyPhone");
7700 }
joonhunshin4ac60942023-11-15 15:23:39 +00007701
Rambo Wange7209ce2022-02-23 13:41:02 -08007702 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7703 }
7704
7705 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007706 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007707 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007709 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007710 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7711 Phone phone = PhoneFactory.getPhone(phoneId);
7712 if (phone == null) {
7713 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007714 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007715 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7716 if (cpt == null) {
7717 continue;
7718 }
7719 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007720 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7721 break;
7722 }
7723 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007724 return result;
Junda Liu29340342014-07-10 15:23:27 -07007725 }
Derek Tan89e89d42014-07-08 17:00:10 -07007726
7727 @Override
Junda Liue64de782015-04-16 17:19:16 -07007728 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007729 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007730
7731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7732 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7733 "getCarrierPackageNamesForIntentAndPhone");
7734
Rambo Wang8a247eb2022-02-08 21:11:18 +00007735 Phone phone = PhoneFactory.getPhone(phoneId);
7736 if (phone == null) {
7737 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007738 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007739 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7740 if (cpt == null) {
7741 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007742 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007743 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007744 }
7745
Amith Yamasani6e118872016-02-19 12:53:51 -08007746 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007747 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007748 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007749 Phone phone = PhoneFactory.getPhone(phoneId);
7750 if (phone == null) {
7751 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007752 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007753 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7754 if (cpt == null) {
7755 return Collections.emptyList();
7756 }
7757 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007758 }
7759
chen xuf7e9fe82019-05-09 19:31:02 -07007760 @Override
7761 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007762 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007763
7764 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7765 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7766 "getPackagesWithCarrierPrivilegesForAllPhones");
7767
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007768 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007769 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007770 try {
7771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7772 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7773 }
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007776 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007777 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007778 }
7779
Rambo Wang6812ffb2022-03-15 16:54:17 -07007780 @Override
7781 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7782 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7783
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007784 if (!mApp.getResources().getBoolean(
7785 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7786 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7787 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7788 "getCarrierServicePackageNameForLogicalSlot");
7789 }
joonhunshin4ac60942023-11-15 15:23:39 +00007790
Rambo Wang6812ffb2022-03-15 16:54:17 -07007791 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7792 if (phone == null) {
7793 return null;
7794 }
7795 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7796 if (cpt == null) {
7797 return null;
7798 }
7799 return cpt.getCarrierServicePackageName();
7800 }
7801
Wink Savilleb564aae2014-10-23 10:18:09 -07007802 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007803 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007804 UiccPort port = phone == null ? null : phone.getUiccPort();
7805 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007806 return null;
7807 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007808 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007809 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007810 return null;
7811 }
7812 return iccId;
7813 }
7814
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007815 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007816 public void setCallComposerStatus(int subId, int status) {
7817 enforceModifyPermission();
7818
joonhunshin4ac60942023-11-15 15:23:39 +00007819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7820 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7821
Shuo Qiane4e11672020-12-15 22:15:33 -08007822 final long identity = Binder.clearCallingIdentity();
7823 try {
7824 Phone phone = getPhone(subId);
7825 if (phone != null) {
7826 Phone defaultPhone = phone.getImsPhone();
7827 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7828 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7829 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007830 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7831 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007832 }
7833 }
Shuo Qian284ae752020-12-22 19:10:14 -08007834 } catch (ImsException e) {
7835 throw new ServiceSpecificException(e.getCode());
7836 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007837 Binder.restoreCallingIdentity(identity);
7838 }
7839 }
7840
7841 @Override
7842 public int getCallComposerStatus(int subId) {
7843 enforceReadPrivilegedPermission("getCallComposerStatus");
7844
joonhunshin4ac60942023-11-15 15:23:39 +00007845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7846 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7847
Shuo Qiane4e11672020-12-15 22:15:33 -08007848 final long identity = Binder.clearCallingIdentity();
7849 try {
7850 Phone phone = getPhone(subId);
7851 if (phone != null) {
7852 Phone defaultPhone = phone.getImsPhone();
7853 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7854 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7855 return imsPhone.getCallComposerStatus();
7856 }
7857 }
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
7861 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7862 }
7863
7864 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007865 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7866 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007868 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007869
joonhunshin4ac60942023-11-15 15:23:39 +00007870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7871 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7872 "setLine1NumberForDisplayForSubscriber");
7873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 final String iccId = getIccId(subId);
7877 final Phone phone = getPhone(subId);
7878 if (phone == null) {
7879 return false;
7880 }
arunvoddub1365e62024-07-31 09:42:31 +00007881 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7882 Rlog.e(LOG_TAG, "Number is too long");
7883 return false;
7884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 final String subscriberId = phone.getSubscriberId();
7886
7887 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007888 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 + subscriberId + " to " + number);
7890 }
7891
7892 if (TextUtils.isEmpty(iccId)) {
7893 return false;
7894 }
7895
7896 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7897
7898 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7899 if (alphaTag == null) {
7900 editor.remove(alphaTagPrefKey);
7901 } else {
7902 editor.putString(alphaTagPrefKey, alphaTag);
7903 }
7904
7905 // Record both the line number and IMSI for this ICCID, since we need to
7906 // track all merged IMSIs based on line number
7907 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7908 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7909 if (number == null) {
7910 editor.remove(numberPrefKey);
7911 editor.remove(subscriberPrefKey);
7912 } else {
7913 editor.putString(numberPrefKey, number);
7914 editor.putString(subscriberPrefKey, subscriberId);
7915 }
7916
7917 editor.commit();
7918 return true;
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007921 }
Derek Tan7226c842014-07-02 17:42:23 -07007922 }
7923
7924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 public String getLine1NumberForDisplay(int subId, String callingPackage,
7926 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007927 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007929 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007930 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007931 return null;
7932 }
Derek Tan97ebb422014-09-05 16:55:38 -07007933
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007934 if (!mApp.getResources().getBoolean(
7935 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7936 enforceTelephonyFeatureWithException(callingPackage,
7937 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7938 }
joonhunshin4ac60942023-11-15 15:23:39 +00007939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 String iccId = getIccId(subId);
7943 if (iccId != null) {
7944 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7945 if (DBG_MERGE) {
7946 log("getLine1NumberForDisplay returning "
7947 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7948 }
7949 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7952 return null;
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007955 }
Derek Tan7226c842014-07-02 17:42:23 -07007956 }
7957
7958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007959 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7960 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007962 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007963 return null;
7964 }
Derek Tan97ebb422014-09-05 16:55:38 -07007965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 String iccId = getIccId(subId);
7969 if (iccId != null) {
7970 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7971 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7972 }
7973 return null;
7974 } finally {
7975 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007976 }
Derek Tan7226c842014-07-02 17:42:23 -07007977 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007978
7979 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007980 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7981 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007982 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7983 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007985 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007986 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007987 return null;
7988 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007989
Jordan Liub49b04b2019-05-06 14:45:15 -07007990 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7991 // the process, where TelephonyManager was instantiated.
7992 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007993 final long identity = Binder.clearCallingIdentity();
7994 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007995 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 final TelephonyManager tele = TelephonyManager.from(context);
7997 final SubscriptionManager sub = SubscriptionManager.from(context);
7998
7999 // Figure out what subscribers are currently active
8000 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001
Jordan Liub49b04b2019-05-06 14:45:15 -07008002 // Only consider subs which match the current subId
8003 // This logic can be simplified. See b/131189269 for progress.
8004 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008005 activeSubscriberIds.add(tele.getSubscriberId(subId));
8006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007
8008 // First pass, find a number override for an active subscriber
8009 String mergeNumber = null;
8010 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8011 for (String key : prefs.keySet()) {
8012 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8013 final String subscriberId = (String) prefs.get(key);
8014 if (activeSubscriberIds.contains(subscriberId)) {
8015 final String iccId = key.substring(
8016 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8017 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8018 mergeNumber = (String) prefs.get(numberKey);
8019 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008020 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 + " for active subscriber " + subscriberId);
8022 }
8023 if (!TextUtils.isEmpty(mergeNumber)) {
8024 break;
8025 }
8026 }
8027 }
8028 }
8029
8030 // Shortcut when no active merged subscribers
8031 if (TextUtils.isEmpty(mergeNumber)) {
8032 return null;
8033 }
8034
8035 // Second pass, find all subscribers under that line override
8036 final ArraySet<String> result = new ArraySet<>();
8037 for (String key : prefs.keySet()) {
8038 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8039 final String number = (String) prefs.get(key);
8040 if (mergeNumber.equals(number)) {
8041 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8042 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8043 final String subscriberId = (String) prefs.get(subscriberKey);
8044 if (!TextUtils.isEmpty(subscriberId)) {
8045 result.add(subscriberId);
8046 }
8047 }
8048 }
8049 }
8050
8051 final String[] resultArray = result.toArray(new String[result.size()]);
8052 Arrays.sort(resultArray);
8053 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008054 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8056 }
8057 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008058 } finally {
8059 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008060 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008061 }
8062
8063 @Override
zoey chen38003472019-12-13 17:16:31 +08008064 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8065 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008066
joonhunshin4ac60942023-11-15 15:23:39 +00008067 enforceTelephonyFeatureWithException(callingPackage,
8068 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8069
Malcolm Chen6ca97372019-07-01 16:28:21 -07008070 final long identity = Binder.clearCallingIdentity();
8071 try {
8072 final TelephonyManager telephonyManager = mApp.getSystemService(
8073 TelephonyManager.class);
8074 String subscriberId = telephonyManager.getSubscriberId(subId);
8075 if (subscriberId == null) {
8076 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008077 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008078 + subId);
8079 }
8080 return null;
8081 }
8082
Jack Yu3beaf9d2023-04-14 09:17:27 -07008083 final SubscriptionInfo info = getSubscriptionManagerService()
8084 .getSubscriptionInfo(subId);
8085 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008086 // If it doesn't belong to any group, return just subscriberId of itself.
8087 if (groupUuid == null) {
8088 return new String[]{subscriberId};
8089 }
8090
8091 // Get all subscriberIds from the group.
8092 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008093 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8094 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8095 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008096 for (SubscriptionInfo subInfo : groupInfos) {
8097 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8098 if (subscriberId != null) {
8099 mergedSubscriberIds.add(subscriberId);
8100 }
8101 }
8102
8103 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106
8107 }
8108 }
8109
8110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008111 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008112 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008113 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114
joonhunshin4ac60942023-11-15 15:23:39 +00008115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 final Phone phone = getPhone(subId);
8121 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
8124 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008125 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008126
8127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008128 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008129 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8130 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008131 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8132 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 final Phone phone = getPhone(subId);
8137 if (phone == null) {
8138 return false;
8139 }
8140 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8141 cdmaNonRoamingList);
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008144 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008145 }
8146
8147 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008148 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008149 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008150 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008151 if (phone == null) {
8152 return raf;
8153 }
8154
Shuo Qiandee53402020-05-29 14:08:15 -07008155 try {
8156 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008157 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008158 mApp, phone.getSubId(), "getRadioAccessFamily");
8159 } catch (SecurityException e) {
8160 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8161 throw e;
8162 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008163
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008164 if (!mApp.getResources().getBoolean(
8165 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8166 enforceTelephonyFeatureWithException(callingPackage,
8167 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8168 }
joonhunshin4ac60942023-11-15 15:23:39 +00008169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 final long identity = Binder.clearCallingIdentity();
8171 try {
chen xub97461a2018-10-26 14:17:57 -07008172 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
chen xub97461a2018-10-26 14:17:57 -07008176 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008177 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008178
8179 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008180 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008181 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008182 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8183 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008184 enforceTelephonyFeatureWithException(callingPackage,
8185 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8186
Hall Liu82694d52020-12-11 18:22:04 -08008187 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008188 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008189 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8190 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008191 if (!dialerRoleHolders.contains(callingPackage)) {
8192 throw new SecurityException("App must be the dialer role holder to"
8193 + " upload a call composer pic");
8194 }
8195
8196 Executors.newSingleThreadExecutor().execute(() -> {
8197 ByteArrayOutputStream output = new ByteArrayOutputStream(
8198 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8199 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8200 boolean readUntilEnd = false;
8201 int totalBytesRead = 0;
8202 byte[] buffer = new byte[16 * 1024];
8203 while (true) {
8204 int numRead;
8205 try {
8206 numRead = input.read(buffer);
8207 } catch (IOException e) {
8208 try {
8209 fd.checkError();
8210 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8211 null);
8212 } catch (IOException e1) {
8213 // This means that the other side closed explicitly with an error. If this
8214 // happens, log and ignore.
8215 loge("Remote end of call composer picture pipe closed: " + e1);
8216 }
8217 break;
8218 }
8219 if (numRead == -1) {
8220 readUntilEnd = true;
8221 break;
8222 }
8223 totalBytesRead += numRead;
8224 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8225 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8226 try {
8227 input.close();
8228 } catch (IOException e) {
8229 // ignore
8230 }
8231 break;
8232 }
8233 output.write(buffer, 0, numRead);
8234 }
8235 // Generally, the remote end will close the file descriptors. The only case where we
8236 // close is above, where the picture size is too big.
8237
8238 try {
8239 fd.checkError();
8240 } catch (IOException e) {
8241 loge("Remote end for call composer closed with an error: " + e);
8242 return;
8243 }
8244
Hall Liuaa4211e2021-01-20 15:43:39 -08008245 if (!readUntilEnd) {
8246 loge("Did not finish reading entire image; aborting");
8247 return;
8248 }
Hall Liu82694d52020-12-11 18:22:04 -08008249
Hall Liuaa4211e2021-01-20 15:43:39 -08008250 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8251 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8252 new CallComposerPictureTransfer.Factory() {},
8253 imageData,
8254 (result) -> {
8255 if (result.first != null) {
8256 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8257 Bundle outputResult = new Bundle();
8258 outputResult.putParcelable(
8259 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8260 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8261 outputResult);
8262 } else {
8263 callback.send(result.second, null);
8264 }
8265 }
8266 );
Hall Liu82694d52020-12-11 18:22:04 -08008267 });
8268 }
8269
8270 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008271 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008272 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274
joonhunshin4ac60942023-11-15 15:23:39 +00008275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8276 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 final long identity = Binder.clearCallingIdentity();
8279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008280 ImsManager.getInstance(defaultPhone.getContext(),
8281 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008285 }
8286
8287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008288 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008289 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8291 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008292 return false;
8293 }
Svet Ganovb320e182015-04-16 12:30:10 -07008294
joonhunshin4ac60942023-11-15 15:23:39 +00008295 enforceTelephonyFeatureWithException(callingPackage,
8296 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 // Check the user preference and the system-level IMS setting. Even if the user has
8301 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8302 // In the long run, we may instead need to check if there exists a connection service
8303 // which can support video calling.
8304 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008305 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 return imsManager.isVtEnabledByPlatform()
8307 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8308 && imsManager.isVtEnabledByUser();
8309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008312 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008313
Andrew Leea1239f22015-03-02 17:44:07 -08008314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008315 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8316 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008318 mApp, subId, callingPackage, callingFeatureId,
8319 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 return false;
8321 }
8322
joonhunshin4ac60942023-11-15 15:23:39 +00008323 enforceTelephonyFeatureWithException(callingPackage,
8324 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 final long identity = Binder.clearCallingIdentity();
8327 try {
8328 CarrierConfigManager configManager =
8329 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008330 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
Andrew Leea1239f22015-03-02 17:44:07 -08008335 }
8336
8337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008338 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008340 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 return false;
8342 }
8343
joonhunshin4ac60942023-11-15 15:23:39 +00008344 enforceTelephonyFeatureWithException(callingPackage,
8345 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 final long identity = Binder.clearCallingIdentity();
8348 try {
8349 CarrierConfigManager configManager =
8350 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008351 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
Andrew Leea1239f22015-03-02 17:44:07 -08008356 }
8357
Andrew Lee9431b832015-03-09 18:46:45 -07008358 @Override
8359 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008360 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008361 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008362 }
8363
8364 @Override
8365 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008366 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8367 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 final long identity = Binder.clearCallingIdentity();
8370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
Andrew Lee9431b832015-03-09 18:46:45 -07008375 }
8376
Hall Liuf6668912018-10-31 17:05:23 -07008377 /**
8378 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8379 * support for the feature and device firmware support.
8380 *
8381 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8382 */
8383 @Override
8384 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008385 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8386 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008389 final Phone phone = getPhone(subscriptionId);
8390 if (phone == null) {
8391 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8392 return false;
8393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008395 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008397 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8398 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8399 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400 return isCarrierSupported && isDeviceSupported;
8401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
Hall Liu98187582018-01-22 19:15:32 -08008404 }
8405
Hall Liuf6668912018-10-31 17:05:23 -07008406 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008407 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8408 * RTT setting, will return true if the device and carrier both support RTT.
8409 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008410 */
8411 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 final long identity = Binder.clearCallingIdentity();
8413 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008414 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8415 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8416 return false;
8417 }
8418 }
8419
Hall Liu5bab75c2019-12-11 23:58:20 +00008420 boolean isRttSupported = isRttSupported(subscriptionId);
8421 boolean isUserRttSettingOn = Settings.Secure.getInt(
8422 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8423 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8424 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8425 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008429 }
8430
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008431 @Deprecated
8432 @Override
8433 public String getDeviceId(String callingPackage) {
8434 return getDeviceIdWithFeature(callingPackage, null);
8435 }
8436
Sanket Padawe7310cc72015-01-14 09:53:20 -08008437 /**
8438 * Returns the unique device ID of phone, for example, the IMEI for
8439 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8440 *
8441 * <p>Requires Permission:
8442 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8443 */
8444 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008445 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008446 try {
8447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8448 } catch (SecurityException se) {
8449 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8450 throw new SecurityException("Package " + callingPackage + " does not belong to "
8451 + Binder.getCallingUid());
8452 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008453 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008454 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008455 return null;
8456 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008457 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008458 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008459 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008460 return null;
8461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 return phone.getDeviceId();
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008469 }
8470
Ping Sunc67b7c22016-03-02 19:16:45 +08008471 /**
8472 * {@hide}
8473 * Returns the IMS Registration Status on a particular subid
8474 *
8475 * @param subId
8476 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008477 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008478 Phone phone = getPhone(subId);
8479 if (phone != null) {
8480 return phone.isImsRegistered();
8481 } else {
8482 return false;
8483 }
8484 }
8485
Santos Cordon7a1885b2015-02-03 11:15:19 -08008486 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008487 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008488 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008490 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008491 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8492 }
8493 final long identity = Binder.clearCallingIdentity();
8494 try {
8495 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8496 } finally {
8497 Binder.restoreCallingIdentity(identity);
8498 }
8499 }
8500
8501 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008502 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008503 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008504 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008505 mApp,
8506 subscriptionId,
8507 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8508 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008509
8510 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8511 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8512
Tyler Gunnf70ed162019-04-03 15:28:53 -07008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 Phone phone = getPhone(subscriptionId);
8516 if (phone == null) {
8517 return null;
8518 }
8519 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
8523 }
8524
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008525 /**
8526 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008527 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008528 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 Phone phone = getPhone(subId);
8532 if (phone != null) {
8533 return phone.isWifiCallingEnabled();
8534 } else {
8535 return false;
8536 }
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008540 }
8541
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008542 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008543 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008544 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008545 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 Phone phone = getPhone(subId);
8549 if (phone != null) {
8550 return phone.isVideoEnabled();
8551 } else {
8552 return false;
8553 }
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008556 }
8557 }
8558
8559 /**
8560 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8561 * defined in {@link ImsRegistrationImplBase}.
8562 */
8563 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 Phone phone = getPhone(subId);
8567 if (phone != null) {
8568 return phone.getImsRegistrationTech();
8569 } else {
8570 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008574 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008575 }
8576
Stuart Scott8eef64f2015-04-08 15:13:54 -07008577 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008578 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008579 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008580
8581 enforceTelephonyFeatureWithException(callingPackage,
8582 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8583
Stuart Scott981d8582015-04-21 14:09:50 -07008584 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8585 return;
8586 }
Kai Shif70f46f2021-03-03 13:59:46 -08008587 Phone defaultPhone = getDefaultPhone();
8588 if (defaultPhone != null) {
8589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8590 mApp, getDefaultPhone().getSubId(), "factoryReset");
8591 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008592 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008593
Svet Ganovcc087f82015-05-12 20:35:54 -07008594 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008595 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8596 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008597 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008598 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008599 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008600 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008601 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008602 setDataRoamingEnabled(subId, phone == null ? false
8603 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008604 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008605 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008606 // There has been issues when Sms raw table somehow stores orphan
8607 // fragments. They lead to garbled message when new fragments come
8608 // in and combined with those stale ones. In case this happens again,
8609 // user can reset all network settings which will clean up this table.
8610 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008611 // Clean up IMS settings as well here.
8612 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008613 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008614 ImsManager.getInstance(mApp, slotId).factoryReset();
8615 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008616
Kai Shif70f46f2021-03-03 13:59:46 -08008617 if (defaultPhone == null) {
8618 return;
8619 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008620 // Erase modem config if erase modem on network setting is enabled.
8621 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8622 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8623 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008624 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008625 }
Kai Shif70f46f2021-03-03 13:59:46 -08008626
8627 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008628 } finally {
8629 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008630 }
8631 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008632
SongFerngWangfd89b102021-05-27 22:44:54 +08008633 @VisibleForTesting
8634 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8635 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8636 return;
8637 }
8638 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8639 RILConstants.PREFERRED_NETWORK_MODE);
8640 SubscriptionManager.setSubscriptionProperty(subId,
8641 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8642 "user=" + defaultNetworkType);
8643 phone.loadAllowedNetworksFromSubscriptionDatabase();
8644 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8645 defaultNetworkType, null);
8646 }
8647
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008648 private void cleanUpSmsRawTable(Context context) {
8649 ContentResolver resolver = context.getContentResolver();
8650 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8651 resolver.delete(uri, null, null);
8652 }
8653
Narayan Kamath1c496c22015-04-16 14:40:19 +01008654 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008655 public String getSimLocaleForSubscriber(int subId) {
8656 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008657
8658 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8659 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8660
chen xu5d3637b2019-01-21 23:31:38 -08008661 final Phone phone = getPhone(subId);
8662 if (phone == null) {
8663 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008664 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666 final long identity = Binder.clearCallingIdentity();
8667 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008668 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8669 phone.getContext().getOpPackageName(),
8670 phone.getContext().getAttributionTag());
8671 if (info == null) {
8672 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8673 return null;
chen xu6291c472019-02-04 12:55:53 -08008674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675 // Try and fetch the locale from the carrier properties or from the SIM language
8676 // preferences (EF-PL and EF-LI)...
8677 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008678 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008679 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8680 if (localeFromDefaultSim != null) {
8681 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8682 if (DBG) log("Using locale from subId: " + subId + " locale: "
8683 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008684 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008685 } else {
8686 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 }
8688 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690 // The SIM language preferences only store a language (e.g. fr = French), not an
8691 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8692 // the SIM and carrier preferences does not include a country we add the country
8693 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008694 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008696 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008697 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008698 }
8699
8700 if (DBG) log("No locale found - returning null");
8701 return null;
8702 } finally {
8703 Binder.restoreCallingIdentity(identity);
8704 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008705 }
8706
tom hsu0b59d292022-09-29 23:49:21 +08008707 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008708 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008709 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008710 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008711 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008712 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8713 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008714 Locale.forLanguageTag(localeTag).getCountry())) {
8715 return localeTag;
8716 }
8717 }
8718 return inputLocale.toLanguageTag();
8719 }
8720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008721 /**
8722 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8723 */
8724 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008725 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008726 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008727 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008728
Gary Jian3aa9a762022-01-24 16:41:19 +08008729 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8730 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008731
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008732 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008733 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8734 * representing the state of the modem.
8735 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008736 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8737 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008738 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008739 */
8740 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008741 public void requestModemActivityInfo(ResultReceiver result) {
8742 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008743
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008744 if (!mApp.getResources().getBoolean(
8745 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8746 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8747 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8748 }
joonhunshin4ac60942023-11-15 15:23:39 +00008749
vagdeviaf9a5b92018-08-15 16:01:53 -07008750 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008754 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008755 } finally {
8756 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008757 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008758 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008759
Gary Jian76280a42022-12-07 16:18:33 +08008760 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008761 // less than total activity duration.
8762 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8763 if (info == null) {
8764 return false;
8765 }
8766 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008767 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008768 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8769
Hall Liu49656c02020-10-09 19:00:11 -07008770 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8771
Siddharth Rayb8114062018-06-17 15:02:38 -07008772 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008773 && (info.getSleepTimeMillis() <= activityDurationMs)
8774 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008775 }
8776
Gary Jian3aa9a762022-01-24 16:41:19 +08008777 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8778 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8779 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8780 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8781
8782 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8783 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8784 }
8785
8786 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8787 mLastModemActivityInfo.setReceiveTimeMillis(
8788 rat,
8789 freq,
8790 info.getReceiveTimeMillis(rat, freq)
8791 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8792 }
8793
8794 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8795 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8796 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8797 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8798
8799 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8800 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8801 }
8802 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8803 mLastModemActivityInfo.setReceiveTimeMillis(
8804 rat,
8805 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8806 }
8807
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008808 /**
8809 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8810 * @param info recent ModemActivityInfo
8811 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008812 private void mergeModemActivityInfo(ModemActivityInfo info) {
8813 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008814 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008815 boolean matched;
8816 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8817 matched = false;
8818 int rat = info.getSpecificInfoRat(i);
8819 int freq = info.getSpecificInfoFrequencyRange(i);
8820 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8821 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8822 //if it already exists
8823 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8824 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8825 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8826 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8827 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8828 updateLastModemActivityInfo(info, rat, freq);
8829 matched = true;
8830 }
8831 } else {
8832 updateLastModemActivityInfo(info, rat);
8833 matched = true;
8834 }
8835 }
8836 }
8837
8838 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008839 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008840 new ActivityStatsTechSpecificInfo(
8841 rat,
8842 freq,
8843 info.getTransmitTimeMillis(rat, freq),
8844 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008845 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008846 }
8847 }
8848 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8849 mLastModemActivitySpecificInfo =
8850 new ActivityStatsTechSpecificInfo[merged.size()];
8851 merged.toArray(mLastModemActivitySpecificInfo);
8852
8853 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8854 mLastModemActivityInfo.setSleepTimeMillis(
8855 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008856 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008857 mLastModemActivityInfo.setIdleTimeMillis(
8858 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008859 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008860
8861 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008862 new ModemActivityInfo(
8863 mLastModemActivityInfo.getTimestampMillis(),
8864 mLastModemActivityInfo.getSleepTimeMillis(),
8865 mLastModemActivityInfo.getIdleTimeMillis(),
8866 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008867 }
8868
8869 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8870 ActivityStatsTechSpecificInfo[] info) {
8871 int infoSize = info.length;
8872 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8873 for (int i = 0; i < infoSize; i++) {
8874 ret[i] = new ActivityStatsTechSpecificInfo(
8875 info[i].getRat(), info[i].getFrequencyRange(),
8876 info[i].getTransmitTimeMillis(),
8877 (int) info[i].getReceiveTimeMillis());
8878 }
8879 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008880 }
8881
Jack Yu85bd38a2015-11-09 11:34:32 -08008882 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008883 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008884 */
8885 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008886 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8887 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8888 Phone phone = PhoneFactory.getPhone(slotIndex);
8889 if (phone == null) {
8890 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8891 return null;
8892 }
8893
8894 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008896 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008897 return null;
8898 }
8899
joonhunshin4ac60942023-11-15 15:23:39 +00008900 enforceTelephonyFeatureWithException(callingPackage,
8901 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8902
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008903 boolean hasFinePermission = false;
8904 boolean hasCoarsePermission = false;
8905 if (!renounceFineLocationAccess) {
8906 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8907 LocationAccessPolicy.checkLocationPermission(mApp,
8908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8909 .setCallingPackage(callingPackage)
8910 .setCallingFeatureId(callingFeatureId)
8911 .setCallingPid(Binder.getCallingPid())
8912 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008913 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008914 .setLogAsInfo(true)
8915 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8916 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8917 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8918 .build());
8919 hasFinePermission =
8920 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8921 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008922
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008923 if (!renounceCoarseLocationAccess) {
8924 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8925 LocationAccessPolicy.checkLocationPermission(mApp,
8926 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8927 .setCallingPackage(callingPackage)
8928 .setCallingFeatureId(callingFeatureId)
8929 .setCallingPid(Binder.getCallingPid())
8930 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008931 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008932 .setLogAsInfo(true)
8933 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8934 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8935 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8936 .build());
8937 hasCoarsePermission =
8938 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8939 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008940
Jordan Liu0f2bc442020-11-18 16:47:37 -08008941 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008943 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8944 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008945 if (subInfo != null && !subInfo.isActive()) {
8946 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008947 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008948 }
8949
Hall Liuf19c44f2018-11-27 14:38:17 -08008950 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008951 boolean isCallingPackageDataService = phone.getDataServicePackages()
8952 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008953
8954 // Scrub out the location info in ServiceState depending on what level of access
8955 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008956 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008957 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8958 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008963
8964 /**
8965 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8966 *
8967 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8968 * voicemail ringtone.
8969 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8970 * PhoneAccount.
8971 */
8972 @Override
8973 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8975 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8980 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008981 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008988 }
8989
8990 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008991 * Sets the per-account voicemail ringtone.
8992 *
8993 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8994 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8995 *
8996 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8997 * voicemail ringtone.
8998 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8999 * PhoneAccount.
9000 */
9001 @Override
9002 public void setVoicemailRingtoneUri(String callingPackage,
9003 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009004 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009006 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9007 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9009 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9010 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012
joonhunshin4ac60942023-11-15 15:23:39 +00009013 enforceTelephonyFeatureWithException(callingPackage,
9014 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9019 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009020 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021 }
9022 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009025 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009026 }
9027
9028 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009029 * Returns whether vibration is set for voicemail notification in Phone settings.
9030 *
9031 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9032 * voicemail vibration setting.
9033 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9034 */
9035 @Override
9036 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009037 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9038 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040 final long identity = Binder.clearCallingIdentity();
9041 try {
9042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9043 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009044 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009051 }
9052
Youhan Wange64578a2016-05-02 15:32:42 -07009053 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009054 * Sets the per-account voicemail vibration.
9055 *
9056 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9057 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9058 *
9059 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9060 * voicemail vibration setting.
9061 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9062 * specific PhoneAccount.
9063 */
9064 @Override
9065 public void setVoicemailVibrationEnabled(String callingPackage,
9066 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009067 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009069 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9070 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9072 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9073 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009074 }
9075
joonhunshin4ac60942023-11-15 15:23:39 +00009076 enforceTelephonyFeatureWithException(callingPackage,
9077 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9082 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009083 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009084 }
9085 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9086 } finally {
9087 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009088 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009089 }
9090
9091 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009092 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9093 *
9094 * @throws SecurityException if the caller does not have the required permission
9095 */
arunvoddud7401012022-12-15 16:08:12 +00009096 @VisibleForTesting
9097 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009099 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009100 }
9101
9102 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009103 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9104 * permission.
9105 *
9106 * @throws SecurityException if the caller does not have the required permission
9107 */
9108 private void enforceSendSmsPermission() {
9109 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9110 }
9111
9112 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009113 * Make sure either called from same process as self (phone) or IPC caller has interact across
9114 * users permission.
9115 *
9116 * @throws SecurityException if the caller does not have the required permission
9117 */
9118 private void enforceInteractAcrossUsersPermission(String message) {
9119 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9120 }
9121
9122 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009123 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009124 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009125 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009126 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009127 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009128 final long identity = Binder.clearCallingIdentity();
9129 try {
9130 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009131 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132 if (componentName == null) {
9133 throw new SecurityException(
9134 "Caller not current active visual voicemail package[null]");
9135 }
9136 String vvmPackage = componentName.getPackageName();
9137 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009138 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139 }
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009142 }
9143 }
9144
9145 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009146 * Return the application ID for the app type.
9147 *
9148 * @param subId the subscription ID that this request applies to.
9149 * @param appType the uicc app type.
9150 * @return Application ID for specificied app type, or null if no uicc.
9151 */
9152 @Override
9153 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009154 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009155
9156 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9157 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9158
Youhan Wange64578a2016-05-02 15:32:42 -07009159 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009160
9161 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009162 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163 if (phone == null) {
9164 return null;
9165 }
9166 String aid = null;
9167 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009168 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009169 .getApplicationByType(appType).getAid();
9170 } catch (Exception e) {
9171 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9172 }
9173 return aid;
9174 } finally {
9175 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009176 }
Youhan Wange64578a2016-05-02 15:32:42 -07009177 }
9178
Youhan Wang4001d252016-05-11 10:29:41 -07009179 /**
9180 * Return the Electronic Serial Number.
9181 *
9182 * @param subId the subscription ID that this request applies to.
9183 * @return ESN or null if error.
9184 */
9185 @Override
9186 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009187 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009188 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009189
9190 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009191 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192 if (phone == null) {
9193 return null;
9194 }
9195 String esn = null;
9196 try {
9197 esn = phone.getEsn();
9198 } catch (Exception e) {
9199 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9200 }
9201 return esn;
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009204 }
Youhan Wang4001d252016-05-11 10:29:41 -07009205 }
9206
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009207 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009208 * Return the Preferred Roaming List Version.
9209 *
9210 * @param subId the subscription ID that this request applies to.
9211 * @return PRLVersion or null if error.
9212 */
9213 @Override
9214 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009215 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009216
9217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9218 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9219
Youhan Wang66ad5d72016-07-18 17:56:58 -07009220 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221
9222 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009223 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009224 if (phone == null) {
9225 return null;
9226 }
9227 String cdmaPrlVersion = null;
9228 try {
9229 cdmaPrlVersion = phone.getCdmaPrlVersion();
9230 } catch (Exception e) {
9231 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9232 }
9233 return cdmaPrlVersion;
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009236 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009237 }
9238
9239 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009240 * Get snapshot of Telephony histograms
9241 * @return List of Telephony histograms
9242 * @hide
9243 */
9244 @Override
9245 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9247 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 return RIL.getTelephonyRILTimingHistograms();
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009255 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009256
9257 /**
9258 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009259 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9260 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009261 * Require system privileges. In the future we may add this to carrier APIs.
9262 *
Michele Berionne482f8202018-11-27 18:57:59 -08009263 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009264 */
9265 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009266 @TelephonyManager.SetCarrierRestrictionResult
9267 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009268 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009269
9270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9271 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9272
vagdeviaf9a5b92018-08-15 16:01:53 -07009273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009274
Michele Berionne482f8202018-11-27 18:57:59 -08009275 if (carrierRestrictionRules == null) {
9276 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009277 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279 final long identity = Binder.clearCallingIdentity();
9280 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009281 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009282 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009286 }
9287
9288 /**
9289 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009290 * Get the allowed carrier list and the excluded carrier list, including the priority between
9291 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009292 * Require system privileges. In the future we may add this to carrier APIs.
9293 *
Michele Berionne482f8202018-11-27 18:57:59 -08009294 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009295 */
9296 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009297 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009298 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009299
9300 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9301 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9302
vagdeviaf9a5b92018-08-15 16:01:53 -07009303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009304
9305 final long identity = Binder.clearCallingIdentity();
9306 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009307 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9308 if (response instanceof CarrierRestrictionRules) {
9309 return (CarrierRestrictionRules) response;
9310 }
9311 // Response is an Exception of some kind,
9312 // which is signalled to the user as a NULL retval
9313 return null;
9314 } catch (Exception e) {
9315 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9316 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009320 }
9321
fionaxu59545b42016-05-25 15:53:37 -07009322 /**
arunvoddud7401012022-12-15 16:08:12 +00009323 * Fetches the carrier restriction status of the device and sends the status to the caller
9324 * through the callback.
9325 *
9326 * @param callback The callback that will be used to send the result.
9327 * @throws SecurityException if the caller does not have the required permission/privileges or
9328 * the caller is not allowlisted.
9329 */
9330 @Override
9331 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009332 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009333 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009334 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9335 try {
9336 mApp.enforceCallingOrSelfPermission(
9337 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9338 functionName);
9339 } catch (SecurityException e) {
9340 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9341 functionName);
9342 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009343 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9344 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009345 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9346 throw new SecurityException("Not an authorized caller");
9347 }
9348 final long identity = Binder.clearCallingIdentity();
9349 try {
9350 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009351 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009352 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
9357
arunvoddu567f2b42023-04-25 17:22:00 +00009358 @Override
9359 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9360 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9361 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9362 return allowListInfo.getShaIdList(pkgName, carrierId);
9363 }
9364
arunvoddud7401012022-12-15 16:08:12 +00009365 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009366 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009367 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009368 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009369 }
9370
9371 /**
fionaxu59545b42016-05-25 15:53:37 -07009372 * Action set from carrier signalling broadcast receivers to enable/disable radio
9373 * @param subId the subscription ID that this action applies to.
9374 * @param enabled control enable or disable radio.
9375 * {@hide}
9376 */
9377 @Override
9378 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9379 enforceModifyPermission();
9380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009381
9382 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009383 if (phone == null) {
9384 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9385 return;
9386 }
9387 try {
9388 phone.carrierActionSetRadioEnabled(enabled);
9389 } catch (Exception e) {
9390 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009391 } finally {
9392 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009393 }
9394 }
9395
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009396 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009397 * Enable or disable Voice over NR (VoNR)
9398 * @param subId the subscription ID that this action applies to.
9399 * @param enabled enable or disable VoNR.
9400 * @return operation result.
9401 */
9402 @Override
9403 public int setVoNrEnabled(int subId, boolean enabled) {
9404 enforceModifyPermission();
9405 final Phone phone = getPhone(subId);
9406
9407 final long identity = Binder.clearCallingIdentity();
9408 if (phone == null) {
9409 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9410 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9411 }
9412
9413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9414 try {
9415 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9416 workSource);
9417 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009418
9419 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9420 if (DBG) {
9421 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9422 }
9423 SubscriptionManager.setSubscriptionProperty(
9424 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9425 (enabled ? "1" : "0"));
9426 }
9427
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009428 return result;
9429 } finally {
9430 Binder.restoreCallingIdentity(identity);
9431 }
9432 }
9433
9434 /**
9435 * Is voice over NR enabled
9436 * @return true if VoNR is enabled else false
9437 */
9438 @Override
9439 public boolean isVoNrEnabled(int subId) {
9440 enforceReadPrivilegedPermission("isVoNrEnabled");
9441 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9445 null, subId, workSource);
9446 if (DBG) log("isVoNrEnabled: " + isEnabled);
9447 return isEnabled;
9448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
9451 }
9452
9453 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009454 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9455 * network status based on which carrier apps could apply actions accordingly,
9456 * enable/disable default url handler for example.
9457 *
9458 * @param subId the subscription ID that this action applies to.
9459 * @param report control start/stop reporting the default network status.
9460 * {@hide}
9461 */
9462 @Override
9463 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9464 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009465
9466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9467 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9468 "carrierActionReportDefaultNetworkStatus");
9469
fionaxu8da9cb12017-05-23 15:02:46 -07009470 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009471
9472 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009473 if (phone == null) {
9474 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9475 return;
9476 }
9477 try {
9478 phone.carrierActionReportDefaultNetworkStatus(report);
9479 } catch (Exception e) {
9480 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009481 } finally {
9482 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009483 }
9484 }
9485
9486 /**
fionaxud9622282017-07-17 17:51:30 -07009487 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9488 * @param subId the subscription ID that this action applies to.
9489 * {@hide}
9490 */
9491 @Override
9492 public void carrierActionResetAll(int subId) {
9493 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009494
9495 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9496 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9497
fionaxud9622282017-07-17 17:51:30 -07009498 final Phone phone = getPhone(subId);
9499 if (phone == null) {
9500 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9501 return;
9502 }
9503 try {
9504 phone.carrierActionResetAll();
9505 } catch (Exception e) {
9506 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9507 }
9508 }
9509
9510 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009511 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9512 * bug report is being generated.
9513 */
9514 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009515 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009516 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9517 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009518 writer.println("Permission Denial: can't dump Phone from pid="
9519 + Binder.getCallingPid()
9520 + ", uid=" + Binder.getCallingUid()
9521 + "without permission "
9522 + android.Manifest.permission.DUMP);
9523 return;
9524 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009525 try {
9526 DumpsysHandler.dump(mApp, fd, writer, args);
9527 } catch (Exception e) {
9528 writer.println("Failed to dump phone information: " + e);
9529 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009530 }
Jack Yueb89b242016-06-22 13:27:47 -07009531
Brad Ebingerdac2f002018-04-03 15:17:52 -07009532 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009533 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9534 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9535 @NonNull String[] args) {
9536 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9537 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009538 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009539 }
9540
Jack Yueb89b242016-06-22 13:27:47 -07009541 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009542 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009543 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009544 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009545 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009546 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009547 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009548 */
9549 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009550 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009551 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009552 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9553 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9554 try {
9555 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009556 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009557 } catch (SecurityException se) {
9558 enforceModifyPermission();
9559 }
9560 } else {
9561 enforceModifyPermission();
9562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009563
joonhunshin4ac60942023-11-15 15:23:39 +00009564 enforceTelephonyFeatureWithException(callingPackage,
9565 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9566
Nate Myren116695d2024-02-09 09:36:01 -08009567 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009568 final long identity = Binder.clearCallingIdentity();
9569 try {
Nate Myren116695d2024-02-09 09:36:01 -08009570 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9571 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009572 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009573 callingUid, callingPackage, null, null);
9574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009575 Phone phone = getPhone(subId);
9576 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009577 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9578 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009579 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009580 phone.getDataSettingsManager().setDataEnabled(
9581 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009583 }
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009586 }
9587 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009588
9589 /**
9590 * Get Client request stats
9591 * @return List of Client Request Stats
9592 * @hide
9593 */
9594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009595 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9596 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009598 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009599 return null;
9600 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009601 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009603 final long identity = Binder.clearCallingIdentity();
9604 try {
9605 if (phone != null) {
9606 return phone.getClientRequestStats();
9607 }
9608
9609 return null;
9610 } finally {
9611 Binder.restoreCallingIdentity(identity);
9612 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009613 }
9614
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009615 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009616 PackageManager pm;
9617 if (mFeatureFlags.hsumPackageManager()) {
9618 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9619 .getPackageManager();
9620 } else {
9621 pm = mApp.getPackageManager();
9622 }
9623
9624 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009625 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009626 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9627 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9628 // exception. ROOT_UID seems not to have a valid package name returned by
9629 // PackageManager, so just fake it here to avoid issues when running telephony shell
9630 // commands that plumb through the RIL as root, like so:
9631 // $ adb root
9632 // $ adb shell cmd phone ...
9633 packageName = "root";
9634 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009635 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009636 }
Jack Yueb4124c2017-02-16 15:32:43 -08009637
9638 /**
Grace Chen70990072017-03-24 17:21:30 -07009639 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009640 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009641 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009642 * @param state State of SIM (power down, power up, pass through)
9643 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9644 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9645 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009646 *
9647 **/
9648 @Override
Grace Chen70990072017-03-24 17:21:30 -07009649 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009650 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009651
9652 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9653 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9654
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009655 Phone phone = PhoneFactory.getPhone(slotIndex);
9656
vagdeviaf9a5b92018-08-15 16:01:53 -07009657 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009662 phone.setSimPowerState(state, null, workSource);
9663 }
9664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
9668
9669 /**
9670 * Set SIM card power state.
9671 *
9672 * @param slotIndex SIM slot id.
9673 * @param state State of SIM (power down, power up, pass through)
9674 * @param callback callback to trigger after success or failure
9675 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9676 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9677 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9678 *
9679 **/
9680 @Override
9681 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9682 IIntegerConsumer callback) {
9683 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009684
9685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9686 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9687 "setSimPowerStateForSlotWithCallback");
9688
Jordan Liu109698e2020-11-24 14:50:34 -08009689 Phone phone = PhoneFactory.getPhone(slotIndex);
9690
9691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9692
9693 final long identity = Binder.clearCallingIdentity();
9694 try {
9695 if (phone != null) {
9696 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9697 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009698 }
9699 } finally {
9700 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009701 }
9702 }
Shuo Qiandd210312017-04-12 22:11:33 +00009703
Tyler Gunn65d45c22017-06-05 11:22:26 -07009704 private boolean isUssdApiAllowed(int subId) {
9705 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009706 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009707 if (configManager == null) {
9708 return false;
9709 }
9710 PersistableBundle pb = configManager.getConfigForSubId(subId);
9711 if (pb == null) {
9712 return false;
9713 }
9714 return pb.getBoolean(
9715 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9716 }
9717
Shuo Qiandd210312017-04-12 22:11:33 +00009718 /**
Ling Mac28f0212023-03-24 16:07:15 -07009719 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009720 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009721 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009722 */
goneil9c5f4872017-12-05 14:07:56 -08009723 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009724 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009725 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009726
9727 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9728 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009730 final long identity = Binder.clearCallingIdentity();
9731 try {
Ling Mac28f0212023-03-24 16:07:15 -07009732 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009733 } finally {
9734 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009735 }
9736 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009737
9738 /**
9739 * Get the current signal strength information for the given subscription.
9740 * Because this information is not updated when the device is in a low power state
9741 * it should not be relied-upon to be current.
9742 * @param subId Subscription index
9743 * @return the most recent cached signal strength info from the modem
9744 */
9745 @Override
9746 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009747 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9748 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009750 final long identity = Binder.clearCallingIdentity();
9751 try {
9752 Phone p = getPhone(subId);
9753 if (p == null) {
9754 return null;
9755 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009757 return p.getSignalStrength();
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
9760 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009761 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009762
Pengquan Meng77b7f132018-08-22 14:49:57 -07009763 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009764 * Get the current modem radio state for the given slot.
9765 * @param slotIndex slot index.
9766 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009767 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009768 * @return the current radio power state from the modem
9769 */
9770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009771 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009772 Phone phone = PhoneFactory.getPhone(slotIndex);
9773 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9775 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009776 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9777 }
9778
joonhunshin4ac60942023-11-15 15:23:39 +00009779 enforceTelephonyFeatureWithException(callingPackage,
9780 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9781
Chen Xuf792fd62018-10-17 17:54:36 +00009782 final long identity = Binder.clearCallingIdentity();
9783 try {
9784 return phone.getRadioPowerState();
9785 } finally {
9786 Binder.restoreCallingIdentity(identity);
9787 }
9788 }
9789 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9790 }
9791
9792 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009793 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9794 *
9795 * <p>Requires one of the following permissions:
9796 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009797 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009798 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9799 * privileges.
9800 *
9801 * @param subId subscription id
9802 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9803 * {@code false}.
9804 */
9805 @Override
9806 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009807 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009808 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009809 try {
9810 mApp.enforceCallingOrSelfPermission(
9811 android.Manifest.permission.ACCESS_NETWORK_STATE,
9812 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009813 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009814 mApp.enforceCallingOrSelfPermission(
9815 permission.READ_BASIC_PHONE_STATE, functionName);
9816 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009817 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009818 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009819 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009820 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009821
joonhunshin4ac60942023-11-15 15:23:39 +00009822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9823 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9824
Pengquan Menga1bb6272018-09-06 09:59:22 -07009825 boolean isEnabled = false;
9826 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009827 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009828 Phone phone = getPhone(subId);
9829 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009830 } finally {
9831 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009832 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009833 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009834 }
9835
9836
9837 /**
9838 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9839 *
9840 * <p> Requires permission:
9841 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9842 * privileges.
9843 *
9844 * @param subId subscription id
9845 * @param isEnabled {@code true} means enable, {@code false} means disable.
9846 */
9847 @Override
9848 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9850 mApp, subId, "setDataRoamingEnabled");
9851
joonhunshin4ac60942023-11-15 15:23:39 +00009852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9853 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9854
Pengquan Menga1bb6272018-09-06 09:59:22 -07009855 final long identity = Binder.clearCallingIdentity();
9856 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009857 Phone phone = getPhone(subId);
9858 if (phone != null) {
9859 phone.setDataRoamingEnabled(isEnabled);
9860 }
9861 } finally {
9862 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009863 }
9864 }
9865
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009866 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009867 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009868 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009869 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009870 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009871
joonhunshin4ac60942023-11-15 15:23:39 +00009872 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9873 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9874
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009875 boolean isAllowed = true;
9876 final long identity = Binder.clearCallingIdentity();
9877 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009878 Phone phone = getPhone(subId);
9879 if (phone != null) {
9880 isAllowed = phone.isCspPlmnEnabled();
9881 }
9882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 return isAllowed;
9886 }
9887
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009888 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9889 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009890 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009891 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009892 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009893 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9894 if (phone == null) {
9895 return false;
9896 }
9897 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9898 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9899 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009900 }
9901
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009902 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009903 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009904 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009905 mApp.getSystemService(AppOpsManager.class)
9906 .checkPackage(Binder.getCallingUid(), callingPackage);
9907
Jordan Liu1e142fc2019-04-22 15:10:43 -07009908 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009909 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009910 try {
9911 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009912 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009913 } catch (SecurityException e) {
9914 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9915 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009916 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009917 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009918 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009919 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009920 }
joonhunshin4ac60942023-11-15 15:23:39 +00009921
9922 enforceTelephonyFeatureWithException(callingPackage,
9923 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9924
sandeepjsb6c87872021-09-27 15:34:44 +00009925 // checking compatibility, if calling app's target SDK is T and beyond.
9926 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9927 Binder.getCallingUid())) {
9928 isIccIdAccessRestricted = true;
9929 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009930 final long identity = Binder.clearCallingIdentity();
9931 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009932 UiccController uiccController = UiccController.getInstance();
9933 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009934 if (hasReadPermission) {
9935 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009936 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009937
9938 // Remove private info if the caller doesn't have access
9939 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9940 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009941 //setting the value after compatibility check
9942 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009943 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9944 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009945 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009946 if (card == null) {
9947 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009948 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009949 continue;
9950 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009951 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9952 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009953 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009954 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009955 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009956 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9957 for (UiccPortInfo portInfo : portInfos) {
9958 UiccPort port = uiccController.getUiccPortForSlot(
9959 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9960 if (port == null) {
9961 // assume no access if port is null
9962 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9963 continue;
9964 }
9965 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9966 uiccPortInfos.add(portInfo);
9967 } else {
9968 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9969 }
9970 }
9971 filteredInfos.add(new UiccCardInfo(
9972 cardInfo.isEuicc(),
9973 cardInfo.getCardId(),
9974 null,
9975 cardInfo.getPhysicalSlotIndex(),
9976 cardInfo.isRemovable(),
9977 cardInfo.isMultipleEnabledProfilesSupported(),
9978 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009979 }
9980 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
sandeepjsb6c87872021-09-27 15:34:44 +00009986 /**
9987 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9988 * generally private and require carrier privileges to view.
9989 *
9990 * @hide
9991 */
9992 @NonNull
9993 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9994 List<UiccPortInfo> portinfo = new ArrayList<>();
9995 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9996 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9997 }
9998 return new UiccCardInfo(
9999 cardInfo.isEuicc(),
10000 cardInfo.getCardId(),
10001 null,
10002 cardInfo.getPhysicalSlotIndex(),
10003 cardInfo.isRemovable(),
10004 cardInfo.isMultipleEnabledProfilesSupported(),
10005 portinfo
10006 );
10007 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010008
sandeepjsb6c87872021-09-27 15:34:44 +000010009 /**
10010 * @hide
10011 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10012 * These values are generally private and require carrier privileges to view.
10013 */
10014 @NonNull
10015 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10016 return new UiccPortInfo(
10017 UiccPortInfo.ICCID_REDACTED,
10018 portInfo.getPortIndex(),
10019 portInfo.getLogicalSlotIndex(),
10020 portInfo.isActive()
10021 );
10022 }
10023 @Override
10024 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010025 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010026 mApp.getSystemService(AppOpsManager.class)
10027 .checkPackage(Binder.getCallingUid(), callingPackage);
10028
sandeepjsb6c87872021-09-27 15:34:44 +000010029 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010030
Aman Guptaf3c90b32022-03-17 04:54:16 +000010031 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10032 // we are reading iccId which is PII data.
10033 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010034
joonhunshin4ac60942023-11-15 15:23:39 +000010035 enforceTelephonyFeatureWithException(callingPackage,
10036 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10037
sandeepjsb6c87872021-09-27 15:34:44 +000010038 // checking compatibility, if calling app's target SDK is T and beyond.
10039 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10040 Binder.getCallingUid())) {
10041 isLogicalSlotAccessRestricted = true;
10042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010043 final long identity = Binder.clearCallingIdentity();
10044 try {
10045 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010046 if (slots == null || slots.length == 0) {
10047 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010048 return null;
10049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010050 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10051 for (int i = 0; i < slots.length; i++) {
10052 UiccSlot slot = slots[i];
10053 if (slot == null) {
10054 continue;
10055 }
10056
Jordan Liu7be7e652019-05-06 18:55:02 +000010057 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010058 UiccCard card = slot.getUiccCard();
10059 if (card != null) {
10060 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010061 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010062 cardId = slot.getEid();
10063 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010064 // If cardId is null, use iccId of default port as cardId.
10065 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010067 }
10068
Jordan Liu857451f2019-05-09 16:35:35 -070010069 if (cardId != null) {
10070 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10071 // if cardId is an EID, it's all digits so this is fine
10072 cardId = IccUtils.stripTrailingFs(cardId);
10073 }
10074
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010075 int cardState = 0;
10076 switch (slot.getCardState()) {
10077 case CARDSTATE_ABSENT:
10078 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10079 break;
10080 case CARDSTATE_PRESENT:
10081 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10082 break;
10083 case CARDSTATE_ERROR:
10084 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10085 break;
10086 case CARDSTATE_RESTRICTED:
10087 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10088 break;
10089 default:
10090 break;
10091
10092 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010093 List<UiccPortInfo> portInfos = new ArrayList<>();
10094 int[] portIndexes = slot.getPortList();
10095 for (int portIdx : portIndexes) {
10096 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010097 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010098 portInfos.add(new UiccPortInfo(iccId, portIdx,
10099 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010101 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010102 slot.isEuicc(),
10103 cardId,
10104 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010105 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010106 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010107 //setting the value after compatibility check
10108 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010109 }
10110 return infos;
10111 } finally {
10112 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010113 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010114 }
10115
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010116 /* Returns null if doesn't have read permission or carrier privilege access. */
10117 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10118 boolean hasReadPermission) {
10119 String iccId = slot.getIccId(portIndex);
10120 if (hasReadPermission) { // if has read permission
10121 return iccId;
10122 } else {
10123 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10124 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10125 // if no read permission, checking carrier privilege access
10126 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10127 return iccId;
10128 }
10129 }
10130 }
10131 // No read permission or carrier privilege access.
10132 return UiccPortInfo.ICCID_REDACTED;
10133 }
10134
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010135 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010136 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010137 public boolean switchSlots(int[] physicalSlots) {
10138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010139
joonhunshin4ac60942023-11-15 15:23:39 +000010140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10141 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10142
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010143 final long identity = Binder.clearCallingIdentity();
10144 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010145 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10146 for (int i = 0; i < physicalSlots.length; i++) {
10147 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10148 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10149 physicalSlots[i], i));
10150 }
10151 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010152 } finally {
10153 Binder.restoreCallingIdentity(identity);
10154 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010155 }
Jack Yu4c988042018-02-27 15:30:01 -080010156
10157 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010158 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10159 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10160 enforceModifyPermission();
10161
joonhunshin4ac60942023-11-15 15:23:39 +000010162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10163 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10164
sandeepjsb6c87872021-09-27 15:34:44 +000010165 final long identity = Binder.clearCallingIdentity();
10166 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010167 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010168 } finally {
10169 Binder.restoreCallingIdentity(identity);
10170 }
10171 }
10172
10173 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010174 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010175 enforceTelephonyFeatureWithException(callingPackage,
10176 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10177
Jordan Liu7de49fa2018-12-06 14:48:49 -080010178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 return UiccController.getInstance().getCardIdForDefaultEuicc();
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
Pengquan Meng85728fb2018-03-12 16:31:21 -070010186 /**
goneil47ffb6e2018-04-06 15:40:58 -070010187 * A test API to reload the UICC profile.
10188 *
10189 * <p>Requires that the calling app has permission
10190 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10191 * @hide
10192 */
10193 @Override
10194 public void refreshUiccProfile(int subId) {
10195 enforceModifyPermission();
10196
10197 final long identity = Binder.clearCallingIdentity();
10198 try {
10199 Phone phone = getPhone(subId);
10200 if (phone == null) {
10201 return;
10202 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010203 UiccPort uiccPort = phone.getUiccPort();
10204 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010205 return;
10206 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010207 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010208 if (uiccProfile == null) {
10209 return;
10210 }
10211 uiccProfile.refresh();
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010218 * Returns false if the mobile data is disabled by default, otherwise return true.
10219 */
10220 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010221 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010222 }
10223
10224 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010225 * Returns the default network type for the given {@code subId}, if the default network type is
10226 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10227 */
10228 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010229 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010230 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010231 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10232 return list.get(phoneId);
10233 }
10234 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010235 }
fionaxua13278b2018-03-21 00:08:13 -070010236
10237 @Override
10238 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010239 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010241
10242 final long identity = Binder.clearCallingIdentity();
10243 try {
10244 final Phone phone = getPhone(subId);
10245 if (phone == null) {
10246 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10247 return;
10248 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010249 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10250 if (cpt != null) {
10251 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10252 }
10253 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010254 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10255 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010256 if (carrierPrivilegeRules == null) {
10257 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10258 } else {
10259 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010261 } finally {
10262 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010263 }
fionaxua13278b2018-03-21 00:08:13 -070010264 }
10265
10266 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010267 public void setCarrierServicePackageOverride(
10268 int subId, String carrierServicePackage, String callingPackage) {
10269 TelephonyPermissions.enforceShellOnly(
10270 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10271
Benedict Wong66477622023-02-03 23:30:57 +000010272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 final Phone phone = getPhone(subId);
10275 if (phone == null || phone.getSubId() != subId) {
10276 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10277 throw new IllegalArgumentException("No phone for subid");
10278 }
10279 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10280 if (cpt == null) {
10281 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10282 throw new IllegalStateException("No CPT for phone");
10283 }
10284 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
10290 @Override
fionaxua13278b2018-03-21 00:08:13 -070010291 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010292 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010293
10294 final long identity = Binder.clearCallingIdentity();
10295 try {
10296 final Phone phone = getPhone(subId);
10297 if (phone == null) {
10298 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10299 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10300 }
10301 return phone.getCarrierIdListVersion();
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010304 }
fionaxua13278b2018-03-21 00:08:13 -070010305 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010306
10307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010308 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10309 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010311 mApp, subId, callingPackage, callingFeatureId,
10312 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010313 return -1;
10314 }
10315
10316 final long identity = Binder.clearCallingIdentity();
10317 try {
10318 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10319 } finally {
10320 Binder.restoreCallingIdentity(identity);
10321 }
10322 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010323
10324 @Override
10325 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010326 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010327 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010328 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010329
joonhunshin4ac60942023-11-15 15:23:39 +000010330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10331 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10332
Pengquan Menga1bb6272018-09-06 09:59:22 -070010333 final long identity = Binder.clearCallingIdentity();
10334 try {
10335 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10336 } finally {
10337 Binder.restoreCallingIdentity(identity);
10338 }
10339 }
10340
10341 @Override
10342 public boolean setCdmaRoamingMode(int subId, int mode) {
10343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10344 mApp, subId, "setCdmaRoamingMode");
10345
joonhunshin4ac60942023-11-15 15:23:39 +000010346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10347 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10348
Pengquan Menga1bb6272018-09-06 09:59:22 -070010349 final long identity = Binder.clearCallingIdentity();
10350 try {
10351 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10352 } finally {
10353 Binder.restoreCallingIdentity(identity);
10354 }
10355 }
10356
10357 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010358 public int getCdmaSubscriptionMode(int subId) {
10359 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010360 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010361 mApp, subId, "getCdmaSubscriptionMode");
10362
joonhunshin4ac60942023-11-15 15:23:39 +000010363 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10364 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10365
Sarah Chinbaab1432020-10-28 13:46:24 -070010366 final long identity = Binder.clearCallingIdentity();
10367 try {
10368 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372 }
10373
10374 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010375 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10377 mApp, subId, "setCdmaSubscriptionMode");
10378
joonhunshin4ac60942023-11-15 15:23:39 +000010379 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10380 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10381
Pengquan Menga1bb6272018-09-06 09:59:22 -070010382 final long identity = Binder.clearCallingIdentity();
10383 try {
10384 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10385 } finally {
10386 Binder.restoreCallingIdentity(identity);
10387 }
10388 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010389
sqianc5eccab2018-10-19 18:46:41 -070010390 @Override
sqian8c685422019-02-22 15:55:18 -080010391 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010392 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010394 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10395 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010396 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10397 }
joonhunshin4ac60942023-11-15 15:23:39 +000010398
10399 enforceTelephonyFeatureWithException(callingPackage,
10400 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10401
sqian11b7a0e2018-12-05 18:48:28 -080010402 final long identity = Binder.clearCallingIdentity();
10403 try {
sqian854d44b2018-12-12 16:48:18 -080010404 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10405 for (Phone phone: PhoneFactory.getPhones()) {
10406 if (phone.getEmergencyNumberTracker() != null
10407 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10408 emergencyNumberListInternal.put(
10409 phone.getSubId(),
10410 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10411 }
sqian11b7a0e2018-12-05 18:48:28 -080010412 }
sqian854d44b2018-12-12 16:48:18 -080010413 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010414 } finally {
10415 Binder.restoreCallingIdentity(identity);
10416 }
sqianc5eccab2018-10-19 18:46:41 -070010417 }
10418
10419 @Override
sqian8c685422019-02-22 15:55:18 -080010420 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010421 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010422 if (!exactMatch) {
10423 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010424 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010425 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010426 }
joonhunshin4ac60942023-11-15 15:23:39 +000010427
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010428 if (!mApp.getResources().getBoolean(
10429 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10430 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10431 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10432 }
joonhunshin4ac60942023-11-15 15:23:39 +000010433
sqian11b7a0e2018-12-05 18:48:28 -080010434 final long identity = Binder.clearCallingIdentity();
10435 try {
sqian854d44b2018-12-12 16:48:18 -080010436 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010437 //Note: we ignore passed in param exactMatch. We can remove it once
10438 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010439 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010440 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010441 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010442 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010443 }
sqian11b7a0e2018-12-05 18:48:28 -080010444 }
10445 return false;
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
10450
sqianf4ca7ed2019-01-15 18:32:07 -080010451 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010452 * Start emergency callback mode for GsmCdmaPhone for testing.
10453 */
10454 @Override
10455 public void startEmergencyCallbackMode() {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10457 "startEmergencyCallbackMode");
10458 enforceModifyPermission();
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 for (Phone phone : PhoneFactory.getPhones()) {
10462 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10463 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10464 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10465 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10466 gsmCdmaPhone.obtainMessage(
10467 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10468 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10469 }
10470 }
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010477 * Update emergency number list for test mode.
10478 */
10479 @Override
10480 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10481 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10482 "updateEmergencyNumberListTestMode");
10483
10484 final long identity = Binder.clearCallingIdentity();
10485 try {
10486 for (Phone phone: PhoneFactory.getPhones()) {
10487 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10488 if (tracker != null) {
10489 tracker.executeEmergencyNumberTestModeCommand(action, num);
10490 }
10491 }
10492 } finally {
10493 Binder.restoreCallingIdentity(identity);
10494 }
10495 }
10496
10497 /**
10498 * Get the full emergency number list for test mode.
10499 */
10500 @Override
10501 public List<String> getEmergencyNumberListTestMode() {
10502 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10503 "getEmergencyNumberListTestMode");
10504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 Set<String> emergencyNumbers = new HashSet<>();
10508 for (Phone phone: PhoneFactory.getPhones()) {
10509 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10510 if (tracker != null) {
10511 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10512 emergencyNumbers.add(num.getNumber());
10513 }
10514 }
10515 }
10516 return new ArrayList<>(emergencyNumbers);
10517 } finally {
10518 Binder.restoreCallingIdentity(identity);
10519 }
10520 }
10521
chen xud6b45bd2018-10-30 22:27:10 -070010522 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010523 public int getEmergencyNumberDbVersion(int subId) {
10524 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10525
joonhunshin4ac60942023-11-15 15:23:39 +000010526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10527 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10528
Shuo Qian3b6ee772019-11-13 17:43:31 -080010529 final long identity = Binder.clearCallingIdentity();
10530 try {
10531 final Phone phone = getPhone(subId);
10532 if (phone == null) {
10533 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10534 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10535 }
10536 return phone.getEmergencyNumberDbVersion();
10537 } finally {
10538 Binder.restoreCallingIdentity(identity);
10539 }
10540 }
10541
10542 @Override
10543 public void notifyOtaEmergencyNumberDbInstalled() {
10544 enforceModifyPermission();
10545
joonhunshin4ac60942023-11-15 15:23:39 +000010546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10547 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10548
Shuo Qian3b6ee772019-11-13 17:43:31 -080010549 final long identity = Binder.clearCallingIdentity();
10550 try {
10551 for (Phone phone: PhoneFactory.getPhones()) {
10552 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10553 if (tracker != null) {
10554 tracker.updateOtaEmergencyNumberDatabase();
10555 }
10556 }
10557 } finally {
10558 Binder.restoreCallingIdentity(identity);
10559 }
10560 }
10561
10562 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010563 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010564 enforceActiveEmergencySessionPermission();
10565
joonhunshin4ac60942023-11-15 15:23:39 +000010566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10567 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10568
Shuo Qian3b6ee772019-11-13 17:43:31 -080010569 final long identity = Binder.clearCallingIdentity();
10570 try {
10571 for (Phone phone: PhoneFactory.getPhones()) {
10572 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10573 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010574 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10575 }
10576 }
10577 } finally {
10578 Binder.restoreCallingIdentity(identity);
10579 }
10580 }
10581
10582 @Override
10583 public void resetOtaEmergencyNumberDbFilePath() {
10584 enforceActiveEmergencySessionPermission();
10585
joonhunshin4ac60942023-11-15 15:23:39 +000010586 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10587 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10588
Shuo Qianc373f112020-03-05 17:55:34 -080010589 final long identity = Binder.clearCallingIdentity();
10590 try {
10591 for (Phone phone: PhoneFactory.getPhones()) {
10592 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10593 if (tracker != null) {
10594 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010595 }
10596 }
10597 } finally {
10598 Binder.restoreCallingIdentity(identity);
10599 }
10600 }
10601
10602 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010603 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10604 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10605 Phone phone = getPhone(subId);
10606 if (phone == null) {
10607 return null;
10608 }
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 UiccProfile profile = UiccController.getInstance()
10612 .getUiccProfileForPhone(phone.getPhoneId());
10613 if (profile != null) {
10614 return profile.getCertsFromCarrierPrivilegeAccessRules();
10615 }
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 return null;
10620 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010621
10622 /**
10623 * Enable or disable a modem stack.
10624 */
10625 @Override
10626 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10627 enforceModifyPermission();
10628
joonhunshin4ac60942023-11-15 15:23:39 +000010629 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10630 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10631
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010632 final long identity = Binder.clearCallingIdentity();
10633 try {
10634 Phone phone = PhoneFactory.getPhone(slotIndex);
10635 if (phone == null) {
10636 return false;
10637 } else {
10638 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10639 }
10640 } finally {
10641 Binder.restoreCallingIdentity(identity);
10642 }
10643 }
Michelecea4cf22018-12-21 15:00:11 -080010644
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010645 /**
10646 * Whether a modem stack is enabled or not.
10647 */
10648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010649 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10650 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010651 Phone phone = PhoneFactory.getPhone(slotIndex);
10652 if (phone == null) return false;
10653
10654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010655 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10656 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010657 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10658 }
10659
joonhunshin4ac60942023-11-15 15:23:39 +000010660 enforceTelephonyFeatureWithException(callingPackage,
10661 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10662
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010663 final long identity = Binder.clearCallingIdentity();
10664 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010665 try {
10666 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10667 } catch (NoSuchElementException ex) {
10668 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10669 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
10674
Michelecea4cf22018-12-21 15:00:11 -080010675 @Override
Michele0ea7d782019-03-19 14:58:42 -070010676 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010677 enforceModifyPermission();
10678
joonhunshin4ac60942023-11-15 15:23:39 +000010679 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10680 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10681
Michelecea4cf22018-12-21 15:00:11 -080010682 final long identity = Binder.clearCallingIdentity();
10683 try {
10684 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010685 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010686 .commit();
10687 } finally {
10688 Binder.restoreCallingIdentity(identity);
10689 }
10690 }
10691
10692 @Override
Michele0ea7d782019-03-19 14:58:42 -070010693 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010694 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010696 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10697 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010698 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010699 }
Michelecea4cf22018-12-21 15:00:11 -080010700
joonhunshin4ac60942023-11-15 15:23:39 +000010701 enforceTelephonyFeatureWithException(callingPackage,
10702 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10703
Michelecea4cf22018-12-21 15:00:11 -080010704 final long identity = Binder.clearCallingIdentity();
10705 try {
Michele0ea7d782019-03-19 14:58:42 -070010706 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010707 } finally {
10708 Binder.restoreCallingIdentity(identity);
10709 }
10710 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010711
Michele0ea7d782019-03-19 14:58:42 -070010712 @TelephonyManager.IsMultiSimSupportedResult
10713 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010714 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10715 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10716 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010717 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10718 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010719 }
10720 // Check if the hardware supports multisim functionality. If usage of multisim is not
10721 // supported by the modem, indicate that it is restricted.
10722 PhoneCapability staticCapability =
10723 mPhoneConfigurationManager.getStaticPhoneCapability();
10724 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010725 loge("isMultiSimSupportedInternal: no static configuration available");
10726 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010727 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010728 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010729 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10730 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010731 }
10732 // Check if support of multiple SIMs is restricted by carrier
10733 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010734 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010735 }
10736
Michele0ea7d782019-03-19 14:58:42 -070010737 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010738 }
10739
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010740 /**
10741 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010742 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10743 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10744 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010745 * @param numOfSims number of active sims we want to switch to
10746 */
10747 @Override
10748 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010749 if (numOfSims == 1) {
10750 enforceModifyPermission();
10751 } else {
10752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10753 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10754 }
joonhunshin4ac60942023-11-15 15:23:39 +000010755
10756 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10757 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10758
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010759 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010760
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010761 try {
Michele30b57b22019-03-01 12:01:14 -080010762 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010763 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010764 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10765 return;
10766 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010767 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
10772
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010773 @Override
10774 public boolean isApplicationOnUicc(int subId, int appType) {
10775 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010776
10777 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10778 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10779
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010780 Phone phone = getPhone(subId);
10781 if (phone == null) {
10782 return false;
10783 }
10784 final long identity = Binder.clearCallingIdentity();
10785 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010786 UiccPort uiccPort = phone.getUiccPort();
10787 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010788 return false;
10789 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010790 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010791 if (uiccProfile == null) {
10792 return false;
10793 }
10794 if (TelephonyManager.APPTYPE_SIM <= appType
10795 && appType <= TelephonyManager.APPTYPE_ISIM) {
10796 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10797 }
10798 return false;
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010804 /**
chen xub4baa772019-04-03 10:23:41 -070010805 * Get whether making changes to modem configurations will trigger reboot.
10806 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010807 */
10808 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010809 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10810 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010812 mApp, subId, callingPackage, callingFeatureId,
10813 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010814 return false;
10815 }
joonhunshin4ac60942023-11-15 15:23:39 +000010816
10817 enforceTelephonyFeatureWithException(callingPackage,
10818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10819 "doesSwitchMultiSimConfigTriggerReboot");
10820
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010821 final long identity = Binder.clearCallingIdentity();
10822 try {
10823 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827 }
10828
Nathan Harold29f5f052019-02-15 13:41:57 -080010829 private void updateModemStateMetrics() {
10830 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10831 // TODO: check the state for each modem if the api is ready.
10832 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10833 }
10834
Pengquan Meng3889a572019-01-23 11:16:29 -080010835 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010836 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010837 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010838 // Verify that the callingPackage belongs to the calling UID
10839 mApp.getSystemService(AppOpsManager.class)
10840 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010841
10842 enforceTelephonyFeatureWithException(callingPackage,
10843 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10844
Pengquan Meng3889a572019-01-23 11:16:29 -080010845 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010846 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010847 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010848 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10849 if (slotInfos != null) {
10850 for (int i = 0; i < slotInfos.length; i++) {
10851 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10852 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10853 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10854 portInfo.getLogicalSlotIndex()));
10855 }
10856 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010857 }
10858 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010859 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010860 } finally {
10861 Binder.restoreCallingIdentity(identity);
10862 }
10863 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010864
10865 /**
10866 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010867 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010868 */
jimsunf9ec1622022-09-13 21:18:43 +080010869 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010870 @Override
10871 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010872 return getHalVersion(HAL_SERVICE_RADIO);
10873 }
10874
10875 /**
10876 * Get the HAL Version of a specific service
10877 */
10878 @Override
10879 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010880 Phone phone = getDefaultPhone();
10881 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010882 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010883 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10884 return hv.major * 100 + hv.minor;
10885 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010886
10887 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010888 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010889 *
10890 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010891 */
10892 @Override
sangyun097dcf72024-01-04 10:35:49 +090010893 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010894 if (mFeatureFlags.hsumPackageManager()) {
10895 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10896 Binder.getCallingUserHandle(), 0).getPackageManager();
10897 if (pm == null) return null;
10898 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10899 return (callingUids == null) ? null : callingUids[0];
10900 }
10901 if (mPackageManager == null) return null;
10902 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10903 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010904 }
10905
10906 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010907 * @return The calling package name or "phone" if the caller is the phone process. This is done
10908 * because multiple Phone has multiple packages in it and the first element in the array is not
10909 * actually always the caller.
10910 * Note: This is for logging purposes only and should not be used for security checks.
10911 */
10912 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010913 PackageManager pm;
10914 if (mFeatureFlags.hsumPackageManager()) {
10915 pm = mApp.getBaseContext().createContextAsUser(
10916 Binder.getCallingUserHandle(), 0).getPackageManager();
10917 } else {
10918 pm = mApp.getPackageManager();
10919 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010920 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10921 if (uidName != null && !uidName.isEmpty()) return uidName;
10922 return getCurrentPackageName();
10923 }
10924
10925 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010926 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10927 * corresponding network requests on a subId.
10928 *
10929 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010930 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010931 * 2) APN is un-metered for this subscription, or
10932 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010933 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010934 *
10935 * @return whether data is allowed for a apn type.
10936 *
10937 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010938 */
10939 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010940 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010941 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10942 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010943
joonhunshin4ac60942023-11-15 15:23:39 +000010944 enforceTelephonyFeatureWithException(callingPackage,
10945 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10946
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010947 // Now that all security checks passes, perform the operation as ourselves.
10948 final long identity = Binder.clearCallingIdentity();
10949 try {
10950 Phone phone = getPhone(subId);
10951 if (phone == null) return false;
10952
Jack Yu27422a52022-03-21 10:38:05 -070010953 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010954 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010955 isMetered = phone.getDataNetworkController().getDataConfigManager()
10956 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10957 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010958 isDataEnabled = (phone.getDataSettingsManager() != null)
10959 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010960 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010961 } finally {
10962 Binder.restoreCallingIdentity(identity);
10963 }
10964 }
10965
10966 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010967 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010968 enforceReadPrivilegedPermission("isApnMetered");
10969
joonhunshin4ac60942023-11-15 15:23:39 +000010970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10971 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10972
Malcolm Chene5ad5792019-04-18 13:51:02 -070010973 // Now that all security checks passes, perform the operation as ourselves.
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
10976 Phone phone = getPhone(subId);
10977 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010978 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10979 DataUtils.apnTypeToNetworkCapability(apnType),
10980 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010985
10986 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010987 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10988 int subscriptionId, IBooleanConsumer resultCallback) {
10989 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010990
10991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10992 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10993
Hall Liu73f5d362020-01-20 13:42:00 -080010994 long token = Binder.clearCallingIdentity();
10995 try {
10996 Phone phone = getPhone(subscriptionId);
10997 if (phone == null) {
10998 try {
10999 if (resultCallback != null) {
11000 resultCallback.accept(false);
11001 }
11002 } catch (RemoteException e) {
11003 // ignore
11004 }
11005 return;
11006 }
11007 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11008 Pair.create(specifiers, (x) -> {
11009 try {
11010 if (resultCallback != null) {
11011 resultCallback.accept(x);
11012 }
11013 } catch (RemoteException e) {
11014 // ignore
11015 }
11016 });
11017 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11018 } finally {
11019 Binder.restoreCallingIdentity(token);
11020 }
11021 }
11022
11023 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011024 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11025 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011026 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011027 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011028
11029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11030 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11031
Sarah Chin679c08a2020-11-18 13:39:35 -080011032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11033 final long identity = Binder.clearCallingIdentity();
11034 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011035 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11036 if (result instanceof IllegalStateException) {
11037 throw (IllegalStateException) result;
11038 }
11039 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011040 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11041 return specifiers;
11042 } finally {
11043 Binder.restoreCallingIdentity(identity);
11044 }
11045 }
11046
11047 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011048 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011049 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011050
11051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11052 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11053
Jack Yu8b766fc2022-03-21 09:42:33 -070011054 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011055 }
11056
11057 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011058 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11059 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011060 if (callingPackage == null) {
11061 callingPackage = getCurrentPackageName();
11062 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011063 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11064 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011065 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11066 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011067 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11068 }
11069 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11070 Intent intent = new Intent();
11071 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11072 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11073 // Bring up choose default SMS subscription dialog right now
11074 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11075 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011076 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011077 }
chen xud5ca2d52019-05-28 15:20:57 -070011078
11079 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011080 public void showSwitchToManagedProfileDialog() {
11081 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011082 try {
11083 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11084 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11085 // for work telephony.
11086 Intent intent = new Intent(Intent.ACTION_SENDTO);
11087 intent.setData(Uri.parse("smsto:"));
11088 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011089 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011090 } catch (ActivityNotFoundException e) {
11091 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11092 Intent intent = new Intent();
11093 intent.setClass(mApp, ErrorDialogActivity.class);
11094 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011095 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011096 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011097 }
11098
11099 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011100 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11102 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11103
chen xud5ca2d52019-05-28 15:20:57 -070011104 //TODO investigate if this API should require proper permission check in R b/133791609
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011107 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11108 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11109 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11110 return carrierUAProfUrl;
11111 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011112 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11113 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011114 } finally {
11115 Binder.restoreCallingIdentity(identity);
11116 }
11117 }
11118
11119 @Override
11120 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11122 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11123
chen xud5ca2d52019-05-28 15:20:57 -070011124 //TODO investigate if this API should require proper permission check in R b/133791609
11125 final long identity = Binder.clearCallingIdentity();
11126 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011127 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11128 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11129 if (!TextUtils.isEmpty(carrierUserAgent)) {
11130 return carrierUserAgent;
11131 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011132 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11133 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011134 } finally {
11135 Binder.restoreCallingIdentity(identity);
11136 }
11137 }
Jack Yub07d4972019-05-28 16:12:25 -070011138
11139 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011140 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11141 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011142
joonhunshin4ac60942023-11-15 15:23:39 +000011143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11144 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11145
Jack Yub07d4972019-05-28 16:12:25 -070011146 final long identity = Binder.clearCallingIdentity();
11147 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011148 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011149 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011150
Ling Maf188d502022-09-16 15:22:36 -070011151 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011152 } finally {
11153 Binder.restoreCallingIdentity(identity);
11154 }
11155 }
11156
11157 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011158 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011159 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011160 enforceModifyPermission();
11161
joonhunshin4ac60942023-11-15 15:23:39 +000011162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11163 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11164
changbettyd5c246e2019-12-24 15:40:37 +080011165 final long identity = Binder.clearCallingIdentity();
11166 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011167 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011168 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011169
Ling Maf188d502022-09-16 15:22:36 -070011170 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011171 } finally {
11172 Binder.restoreCallingIdentity(identity);
11173 }
11174 }
11175
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011176 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011177 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011178 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11179 * otherwise.
11180 */
11181 @Override
11182 public void setCepEnabled(boolean isCepEnabled) {
11183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11184
11185 final long identity = Binder.clearCallingIdentity();
11186 try {
11187 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11188 for (Phone phone : PhoneFactory.getPhones()) {
11189 Phone defaultPhone = phone.getImsPhone();
11190 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11191 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11192 ImsPhoneCallTracker imsPhoneCallTracker =
11193 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11194 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11195 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11196 + imsPhone.getMsisdn());
11197 }
11198 }
11199 } finally {
11200 Binder.restoreCallingIdentity(identity);
11201 }
11202 }
allenwtsu46dcc572020-01-08 18:24:03 +080011203
11204 /**
11205 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11206 *
11207 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11208 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11209 * before being read.
11210 */
11211 @Override
11212 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11213 isCompressed) {
11214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11215 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11217 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11218 }
joonhunshin4ac60942023-11-15 15:23:39 +000011219
11220 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11221 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11222 Binder.getCallingUserHandle())) {
11223 if (!isImsAvailableOnDevice()) {
11224 // ProvisioningManager can not handle ServiceSpecificException.
11225 // Throw the IllegalStateException and annotate ProvisioningManager.
11226 throw new IllegalStateException("IMS not available on device.");
11227 }
11228 } else {
11229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11230 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11231 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011232 }
11233
11234 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011235 try {
Hui Wang761a6682020-10-31 05:12:53 +000011236 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011239 }
11240 }
zoey chene02881a2019-12-30 16:11:23 +080011241
11242 @Override
11243 public boolean isIccLockEnabled(int subId) {
11244 enforceReadPrivilegedPermission("isIccLockEnabled");
11245
joonhunshin4ac60942023-11-15 15:23:39 +000011246 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11247 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11248
zoey chene02881a2019-12-30 16:11:23 +080011249 // Now that all security checks passes, perform the operation as ourselves.
11250 final long identity = Binder.clearCallingIdentity();
11251 try {
11252 Phone phone = getPhone(subId);
11253 if (phone != null && phone.getIccCard() != null) {
11254 return phone.getIccCard().getIccLockEnabled();
11255 } else {
11256 return false;
11257 }
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
11262
11263 /**
11264 * Set the ICC pin lock enabled or disabled.
11265 *
11266 * @return an integer representing the status of IccLock enabled or disabled in the following
11267 * three cases:
11268 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11269 * successfully.
11270 * - Positive number and zero for remaining password attempts.
11271 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11272 *
11273 */
11274 @Override
11275 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11276 enforceModifyPermission();
11277
joonhunshin4ac60942023-11-15 15:23:39 +000011278 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11279 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11280
zoey chene02881a2019-12-30 16:11:23 +080011281 Phone phone = getPhone(subId);
11282 if (phone == null) {
11283 return 0;
11284 }
11285 // Now that all security checks passes, perform the operation as ourselves.
11286 final long identity = Binder.clearCallingIdentity();
11287 try {
11288 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11289 new Pair<Boolean, String>(enabled, password), phone, null);
11290 return attemptsRemaining;
11291
11292 } catch (Exception e) {
11293 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11294 } finally {
11295 Binder.restoreCallingIdentity(identity);
11296 }
11297 return 0;
11298 }
11299
11300 /**
11301 * Change the ICC password used in ICC pin lock.
11302 *
11303 * @return an integer representing the status of IccLock changed in the following three cases:
11304 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11305 * - Positive number and zero for remaining password attempts.
11306 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11307 *
11308 */
11309 @Override
11310 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11311 enforceModifyPermission();
11312
joonhunshin4ac60942023-11-15 15:23:39 +000011313 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11314 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11315
zoey chene02881a2019-12-30 16:11:23 +080011316 Phone phone = getPhone(subId);
11317 if (phone == null) {
11318 return 0;
11319 }
11320 // Now that all security checks passes, perform the operation as ourselves.
11321 final long identity = Binder.clearCallingIdentity();
11322 try {
11323 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11324 new Pair<String, String>(oldPassword, newPassword), phone, null);
11325 return attemptsRemaining;
11326
11327 } catch (Exception e) {
11328 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11329 } finally {
11330 Binder.restoreCallingIdentity(identity);
11331 }
11332 return 0;
11333 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011334
11335 /**
11336 * Request for receiving user activity notification
11337 */
11338 @Override
11339 public void requestUserActivityNotification() {
11340 if (!mNotifyUserActivity.get()
11341 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11342 mNotifyUserActivity.set(true);
11343 }
11344 }
11345
11346 /**
11347 * Called when userActivity is signalled in the power manager.
11348 * This is safe to call from any thread, with any window manager locks held or not.
11349 */
11350 @Override
11351 public void userActivity() {
11352 // ***************************************
11353 // * Inherited from PhoneWindowManager *
11354 // ***************************************
11355 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11356 // WITH ITS LOCKS HELD.
11357 //
11358 // This code must be VERY careful about the locks
11359 // it acquires.
11360 // In fact, the current code acquires way too many,
11361 // and probably has lurking deadlocks.
11362
Jack Yu86374492024-09-16 13:05:44 -070011363 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011364 throw new SecurityException("Only the OS may call notifyUserActivity()");
11365 }
11366
11367 if (mNotifyUserActivity.getAndSet(false)) {
11368 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11369 USER_ACTIVITY_NOTIFICATION_DELAY);
11370 }
11371 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011372
11373 @Override
11374 public boolean canConnectTo5GInDsdsMode() {
11375 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11376 }
Jack Yud10cdd42020-09-28 20:28:01 -070011377
11378 @Override
11379 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11380 String callingFeatureId) {
11381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11382 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11383 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11384 }
11385
joonhunshin4ac60942023-11-15 15:23:39 +000011386 enforceTelephonyFeatureWithException(callingPackage,
11387 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11388
Jack Yud10cdd42020-09-28 20:28:01 -070011389 Phone phone = getPhone(subId);
11390 if (phone == null) {
11391 throw new RuntimeException("phone is not available");
11392 }
11393 // Now that all security checks passes, perform the operation as ourselves.
11394 final long identity = Binder.clearCallingIdentity();
11395 try {
11396 return phone.getEquivalentHomePlmns();
11397 } finally {
11398 Binder.restoreCallingIdentity(identity);
11399 }
11400 }
Daniel Bright59e67312020-11-13 11:49:37 -080011401
11402 @Override
11403 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011404 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011405 if (!mApp.getResources().getBoolean(
11406 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11407 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11408 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11409 "isRadioInterfaceCapabilitySupported");
11410 }
joonhunshin4ac60942023-11-15 15:23:39 +000011411
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011412 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011413 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011414 if (radioInterfaceCapabilities == null) {
11415 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011416 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011417 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011418 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011419
Hui Wang641e81c2020-10-12 12:14:23 -070011420 @Override
11421 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11422 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011423 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11424 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11425 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11426 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11427 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011428
11429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11430 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11431
Hui Wang641e81c2020-10-12 12:14:23 -070011432 if (DBG) {
11433 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11434 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11435 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11436 }
11437
11438 if (!SubscriptionManager.isValidSubscriptionId(subId)
11439 || appType < TelephonyManager.APPTYPE_UNKNOWN
11440 || appType > TelephonyManager.APPTYPE_ISIM
11441 || nafUrl == null || securityProtocol == null || callback == null) {
11442 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11443 if (callback != null) {
11444 try {
11445 callback.onAuthenticationFailure(
11446 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11447 } catch (RemoteException exception) {
11448 log("Fail to notify onAuthenticationFailure due to " + exception);
11449 }
11450 return;
11451 }
11452 }
11453
11454 final long token = Binder.clearCallingIdentity();
11455 try {
11456 getGbaManager(subId).bootstrapAuthenticationRequest(
11457 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011458 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011459 } finally {
11460 Binder.restoreCallingIdentity(token);
11461 }
11462 }
11463
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011464 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011465 * Attempts to set the radio power state for all phones for thermal reason.
11466 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 * requested radio power state will actually be set. See {@link
11468 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11469 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011470 * @param enable {@code true} if trying to turn radio on.
11471 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11472 * false}.
11473 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011474 private boolean setRadioPowerForThermal(boolean enable) {
11475 boolean isPhoneAvailable = false;
11476 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11477 Phone phone = PhoneFactory.getPhone(i);
11478 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011479 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011480 isPhoneAvailable = true;
11481 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011482 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011483
11484 // return true if successfully informed the phone object about the thermal radio power
11485 // request.
11486 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011487 }
11488
11489 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011490 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011491 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11492 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11493 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11494 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11495 throw new IllegalArgumentException("modem does not support data throttling");
11496 }
11497
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11499 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011500 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011501 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11502 }
11503
Sarah Chinecc78c42022-03-31 21:16:48 -070011504 setDataEnabledForReason(
11505 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011506
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011507 if (isDataThrottlingSupported) {
11508 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011509 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011510 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11511 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11512 } else if (thermalMitigationResult
11513 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011514 log("Modem likely does not support data throttling on secondary carrier. Data " +
11515 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11516 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011517 }
11518 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011520
11521 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011522 }
11523
Jack Nudelman644b91a2021-03-12 14:09:48 -080011524 private static List<String> getThermalMitigationAllowlist(Context context) {
11525 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11526 for (String pckg : context.getResources()
11527 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11528 sThermalMitigationAllowlistedPackages.add(pckg);
11529 }
11530 }
11531
11532 return sThermalMitigationAllowlistedPackages;
11533 }
11534
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011535 private boolean isAnyPhoneInEmergencyState() {
11536 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11537 if (tm.isInEmergencyCall()) {
11538 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11539 return true;
11540 }
11541 for (Phone phone : PhoneFactory.getPhones()) {
11542 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11543 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011544 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11545 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011546 return true;
11547 }
11548 }
11549
11550 return false;
11551 }
11552
Jack Nudelman644b91a2021-03-12 14:09:48 -080011553 /**
11554 * Used by shell commands to add an authorized package name for thermal mitigation.
11555 * @param packageName name of package to be allowlisted
11556 * @param context
11557 */
11558 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11559 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11560 sThermalMitigationAllowlistedPackages.add(packageName);
11561 }
11562
11563 /**
11564 * Used by shell commands to remove an authorized package name for thermal mitigation.
11565 * @param packageName name of package to remove from allowlist
11566 * @param context
11567 */
11568 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11569 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11570 sThermalMitigationAllowlistedPackages.remove(packageName);
11571 }
11572
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011573 /**
11574 * Thermal mitigation request to control functionalities at modem.
11575 *
11576 * @param subId the id of the subscription.
11577 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011578 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011579 *
11580 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11581 */
11582 @Override
11583 @ThermalMitigationResult
11584 public int sendThermalMitigationRequest(
11585 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011586 ThermalMitigationRequest thermalMitigationRequest,
11587 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011588 enforceModifyPermission();
11589
Jack Nudelman644b91a2021-03-12 14:09:48 -080011590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011591
11592 enforceTelephonyFeatureWithException(callingPackage,
11593 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11594
Jack Nudelman644b91a2021-03-12 14:09:48 -080011595 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11596 .contains(callingPackage)) {
11597 throw new SecurityException("Calling package must be configured in the device config. "
11598 + "calling package: " + callingPackage);
11599 }
11600
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11602 final long identity = Binder.clearCallingIdentity();
11603
11604 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11605 try {
11606 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11607 switch (thermalMitigationAction) {
11608 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11609 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011610 handleDataThrottlingRequest(subId,
11611 thermalMitigationRequest.getDataThrottlingRequest(),
11612 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011613 break;
11614 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11615 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11616 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11617 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11618 }
11619
11620 // Ensure that radio is on. If not able to power on due to phone being
11621 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011622 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011623 thermalMitigationResult =
11624 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11625 break;
11626 }
11627
11628 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011629 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011630 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11631 break;
11632 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11633 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11634 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11635 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11636 }
11637
11638 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11639 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011640 Phone phone = getPhone(subId);
11641 if (phone == null) {
11642 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011643 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011644 break;
11645 }
11646
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011647 TelephonyConnectionService service =
11648 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011649 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011650 Log.e(LOG_TAG, "An emergency call is pending");
11651 thermalMitigationResult =
11652 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11653 break;
11654 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011655 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011656 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011657 break;
11658 }
11659 } else {
11660 thermalMitigationResult =
11661 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11662 break;
11663 }
11664
11665 // Turn radio off. If not able to power off due to phone being unavailable,
11666 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011667 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011668 thermalMitigationResult =
11669 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11670 break;
11671 }
11672 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011673 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011674 break;
11675 default:
11676 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11677 + "not exist. Requested action: " + thermalMitigationAction);
11678 }
11679 } catch (IllegalArgumentException e) {
11680 throw e;
11681 } catch (Exception e) {
11682 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11683 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11684 } finally {
11685 Binder.restoreCallingIdentity(identity);
11686 }
11687
11688 if (DBG) {
11689 log("thermalMitigationRequest returning with thermalMitigationResult: "
11690 + thermalMitigationResult);
11691 }
11692
11693 return thermalMitigationResult;
11694 }
Hui Wang641e81c2020-10-12 12:14:23 -070011695
11696 /**
11697 * Set the GbaService Package Name that Telephony will bind to.
11698 *
11699 * @param subId The sim that the GbaService is associated with.
11700 * @param packageName The name of the package to be replaced with.
11701 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11702 */
11703 @Override
11704 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11705 enforceModifyPermission();
11706
11707 final long identity = Binder.clearCallingIdentity();
11708 try {
11709 return getGbaManager(subId).overrideServicePackage(packageName);
11710 } finally {
11711 Binder.restoreCallingIdentity(identity);
11712 }
11713 }
11714
11715 /**
11716 * Return the package name of the currently bound GbaService.
11717 *
11718 * @param subId The sim that the GbaService is associated with.
11719 * @return the package name of the GbaService configuration, null if GBA is not supported.
11720 */
11721 @Override
11722 public String getBoundGbaService(int subId) {
11723 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11724
11725 final long identity = Binder.clearCallingIdentity();
11726 try {
11727 return getGbaManager(subId).getServicePackage();
11728 } finally {
11729 Binder.restoreCallingIdentity(identity);
11730 }
11731 }
11732
11733 /**
11734 * Set the release time for telephony to unbind GbaService.
11735 *
11736 * @param subId The sim that the GbaService is associated with.
11737 * @param interval The release time to unbind GbaService by millisecond.
11738 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11739 */
11740 @Override
11741 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11742 enforceModifyPermission();
11743
11744 final long identity = Binder.clearCallingIdentity();
11745 try {
11746 return getGbaManager(subId).overrideReleaseTime(interval);
11747 } finally {
11748 Binder.restoreCallingIdentity(identity);
11749 }
11750 }
11751
11752 /**
11753 * Return the release time for telephony to unbind GbaService.
11754 *
11755 * @param subId The sim that the GbaService is associated with.
11756 * @return The release time to unbind GbaService by millisecond.
11757 */
11758 @Override
11759 public int getGbaReleaseTime(int subId) {
11760 enforceReadPrivilegedPermission("getGbaReleaseTime");
11761
11762 final long identity = Binder.clearCallingIdentity();
11763 try {
11764 return getGbaManager(subId).getReleaseTime();
11765 } finally {
11766 Binder.restoreCallingIdentity(identity);
11767 }
11768 }
11769
11770 private GbaManager getGbaManager(int subId) {
11771 GbaManager instance = GbaManager.getInstance(subId);
11772 if (instance == null) {
11773 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11774 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11775 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11776 }
11777 return instance;
11778 }
Hui Wang761a6682020-10-31 05:12:53 +000011779
11780 /**
11781 * indicate whether the device and the carrier can support
11782 * RCS VoLTE single registration.
11783 */
11784 @Override
11785 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011786 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11787 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11788 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11789 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011790
11791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11793 }
11794
11795 final long identity = Binder.clearCallingIdentity();
11796 try {
11797 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11798 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011799 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11800 if (isCapable != null) {
11801 return isCapable;
11802 }
Hui Wang761a6682020-10-31 05:12:53 +000011803 }
Hui Wang67af90e2021-06-04 16:57:15 -070011804 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11805 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011806 } finally {
11807 Binder.restoreCallingIdentity(identity);
11808 }
11809 }
11810
11811 /**
11812 * Register RCS provisioning callback.
11813 */
11814 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011815 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011816 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011817 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011818 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011819 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11820 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011821
11822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11824 }
joonhunshin4ac60942023-11-15 15:23:39 +000011825 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11826 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11827 Binder.getCallingUserHandle())) {
11828 if (!isImsAvailableOnDevice()) {
11829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11830 "IMS not available on device.");
11831 }
11832 } else {
11833 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11834 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011835 }
11836
11837 final long identity = Binder.clearCallingIdentity();
11838 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011839 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011840 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011841 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11842 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011843 }
Hui Wang761a6682020-10-31 05:12:53 +000011844 } finally {
11845 Binder.restoreCallingIdentity(identity);
11846 }
11847 }
11848
11849 /**
11850 * Unregister RCS provisioning callback.
11851 */
11852 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011853 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011854 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011855 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011856 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011857 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11858 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011859
11860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11861 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11862 }
joonhunshin4ac60942023-11-15 15:23:39 +000011863
11864 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11865 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11866 Binder.getCallingUserHandle())) {
11867 if (!isImsAvailableOnDevice()) {
11868 // operation failed silently
11869 Rlog.w(LOG_TAG, "IMS not available on device.");
11870 return;
11871 }
11872 } else {
11873 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11874 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11875 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011876 }
11877
11878 final long identity = Binder.clearCallingIdentity();
11879 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011880 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011881 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011882 } finally {
11883 Binder.restoreCallingIdentity(identity);
11884 }
11885 }
11886
11887 /**
11888 * trigger RCS reconfiguration.
11889 */
11890 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011891 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11892 "triggerRcsReconfiguration",
11893 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011894
11895 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11896 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11897 }
joonhunshin4ac60942023-11-15 15:23:39 +000011898 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11899 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11900 Binder.getCallingUserHandle())) {
11901 if (!isImsAvailableOnDevice()) {
11902 // ProvisioningManager can not handle ServiceSpecificException.
11903 // Throw the IllegalStateException and annotate ProvisioningManager.
11904 throw new IllegalStateException("IMS not available on device.");
11905 }
11906 } else {
11907 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11908 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011909 }
11910
11911 final long identity = Binder.clearCallingIdentity();
11912 try {
11913 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11914 } finally {
11915 Binder.restoreCallingIdentity(identity);
11916 }
11917 }
11918
11919 /**
11920 * Provide the client configuration parameters of the RCS application.
11921 */
11922 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011923 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11924 "setRcsClientConfiguration",
11925 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011926
11927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11929 }
joonhunshin4ac60942023-11-15 15:23:39 +000011930 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11931 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11932 Binder.getCallingUserHandle())) {
11933 if (!isImsAvailableOnDevice()) {
11934 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11935 "IMS not available on device.");
11936 }
11937 } else {
11938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11939 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011940 }
11941
11942 final long identity = Binder.clearCallingIdentity();
11943
11944 try {
11945 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11946 if (configBinder == null) {
11947 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011948 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11949 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011950 } else {
11951 configBinder.setRcsClientConfiguration(rcc);
11952 }
joonhunshin3e154242021-09-17 06:33:39 +000011953
11954 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11955 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011956 } catch (RemoteException e) {
11957 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011958 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11959 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011960 } finally {
11961 Binder.restoreCallingIdentity(identity);
11962 }
11963 }
11964
11965 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011966 * Enables or disables the test mode for RCS VoLTE single registration.
11967 */
11968 @Override
11969 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11970 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11971 "setRcsSingleRegistrationTestModeEnabled");
11972
11973 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11974 }
11975
11976 /**
11977 * Gets the test mode for RCS VoLTE single registration.
11978 */
11979 @Override
11980 public boolean getRcsSingleRegistrationTestModeEnabled() {
11981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11982 "getRcsSingleRegistrationTestModeEnabled");
11983
11984 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11985 }
11986
11987 /**
Hui Wang761a6682020-10-31 05:12:53 +000011988 * Overrides the config of RCS VoLTE single registration enabled for the device.
11989 */
11990 @Override
11991 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11993 "setDeviceSingleRegistrationEnabledOverride");
11994 enforceModifyPermission();
11995
11996 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11997 : Boolean.parseBoolean(enabledStr);
11998 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011999 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000012000 }
12001
12002 /**
Tyler Gunn92479152021-01-20 16:30:10 -080012003 * Sends a device to device communication message. Only usable via shell.
12004 * @param message message to send.
12005 * @param value message value.
12006 */
12007 @Override
12008 public void sendDeviceToDeviceMessage(int message, int value) {
12009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012010 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012011 enforceModifyPermission();
12012
12013 final long identity = Binder.clearCallingIdentity();
12014 try {
12015 TelephonyConnectionService service =
12016 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12017 if (service == null) {
12018 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12019 return;
12020 }
12021 service.sendTestDeviceToDeviceMessage(message, value);
12022 } finally {
12023 Binder.restoreCallingIdentity(identity);
12024 }
12025 }
12026
Tyler Gunnbabbda02021-02-10 11:05:02 -080012027 /**
12028 * Sets the specified device to device transport active.
12029 * @param transport The transport to set active.
12030 */
12031 @Override
12032 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12034 "setActiveDeviceToDeviceTransport");
12035 enforceModifyPermission();
12036
12037 final long identity = Binder.clearCallingIdentity();
12038 try {
12039 TelephonyConnectionService service =
12040 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12041 if (service == null) {
12042 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12043 return;
12044 }
12045 service.setActiveDeviceToDeviceTransport(transport);
12046 } finally {
12047 Binder.restoreCallingIdentity(identity);
12048 }
12049 }
Tyler Gunn92479152021-01-20 16:30:10 -080012050
Tyler Gunnd4339262021-05-03 14:46:49 -070012051 @Override
12052 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12054 "setDeviceToDeviceForceEnabled");
12055
12056 final long identity = Binder.clearCallingIdentity();
12057 try {
12058 Arrays.stream(PhoneFactory.getPhones()).forEach(
12059 p -> {
12060 Phone thePhone = p.getImsPhone();
12061 if (thePhone != null && thePhone instanceof ImsPhone) {
12062 ImsPhone imsPhone = (ImsPhone) thePhone;
12063 CallTracker tracker = imsPhone.getCallTracker();
12064 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12065 ImsPhoneCallTracker imsPhoneCallTracker =
12066 (ImsPhoneCallTracker) tracker;
12067 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12068 }
12069 }
12070 }
12071 );
12072 } finally {
12073 Binder.restoreCallingIdentity(identity);
12074 }
12075 }
12076
Tyler Gunn92479152021-01-20 16:30:10 -080012077 /**
Hui Wang761a6682020-10-31 05:12:53 +000012078 * Gets the config of RCS VoLTE single registration enabled for the device.
12079 */
12080 @Override
12081 public boolean getDeviceSingleRegistrationEnabled() {
12082 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12083 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12084 }
12085
12086 /**
12087 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12088 */
12089 @Override
12090 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12092 "setCarrierSingleRegistrationEnabledOverride");
12093 enforceModifyPermission();
12094
12095 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12096 : Boolean.parseBoolean(enabledStr);
12097 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12098 subId, enabled);
12099 }
12100
12101 /**
12102 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12103 */
12104 @Override
12105 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12106 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12107 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12108 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012109
12110 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012111 * Overrides the ims feature validation result
12112 */
12113 @Override
12114 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12116 "setImsFeatureValidationOverride");
12117
12118 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12119 : Boolean.parseBoolean(enabledStr);
12120 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12121 subId, enabled);
12122 }
12123
12124 /**
12125 * Gets the ims feature validation override value
12126 */
12127 @Override
12128 public boolean getImsFeatureValidationOverride(int subId) {
12129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12130 "getImsFeatureValidationOverride");
12131 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12132 }
12133
12134 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012135 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12136 * their mobile plan.
12137 */
12138 @Override
12139 public String getMobileProvisioningUrl() {
12140 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12141 final long identity = Binder.clearCallingIdentity();
12142 try {
12143 return getDefaultPhone().getMobileProvisioningUrl();
12144 } finally {
12145 Binder.restoreCallingIdentity(identity);
12146 }
12147 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012148
James.cf Linbcdf8b32021-01-14 16:44:13 +080012149 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012150 * Get the EAB contact from the EAB database.
12151 */
12152 @Override
12153 public String getContactFromEab(String contact) {
12154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12155 enforceModifyPermission();
12156 final long identity = Binder.clearCallingIdentity();
12157 try {
12158 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12159 } finally {
12160 Binder.restoreCallingIdentity(identity);
12161 }
12162 }
12163
12164 /**
Calvin Pana1434322021-07-01 19:27:01 +080012165 * Get the EAB capability from the EAB database.
12166 */
12167 @Override
12168 public String getCapabilityFromEab(String contact) {
12169 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12170 enforceModifyPermission();
12171 final long identity = Binder.clearCallingIdentity();
12172 try {
12173 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
12178
12179 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012180 * Remove the EAB contacts from the EAB database.
12181 */
12182 @Override
12183 public int removeContactFromEab(int subId, String contacts) {
12184 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12185 enforceModifyPermission();
12186 final long identity = Binder.clearCallingIdentity();
12187 try {
12188 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12189 } finally {
12190 Binder.restoreCallingIdentity(identity);
12191 }
12192 }
12193
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012194 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012195 public boolean getDeviceUceEnabled() {
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12197 final long identity = Binder.clearCallingIdentity();
12198 try {
12199 return mApp.getDeviceUceEnabled();
12200 } finally {
12201 Binder.restoreCallingIdentity(identity);
12202 }
12203 }
12204
12205 @Override
12206 public void setDeviceUceEnabled(boolean isEnabled) {
12207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12208 final long identity = Binder.clearCallingIdentity();
12209 try {
12210 mApp.setDeviceUceEnabled(isEnabled);
12211 } finally {
12212 Binder.restoreCallingIdentity(identity);
12213 }
12214 }
12215
Brad Ebinger14d467f2021-02-12 06:18:28 +000012216 /**
12217 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12218 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12219 */
12220 // Used for SHELL command only right now.
12221 @Override
12222 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12223 List<String> featureTags) {
12224 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12225 "addUceRegistrationOverrideShell");
12226 final long identity = Binder.clearCallingIdentity();
12227 try {
12228 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12229 new ArraySet<>(featureTags));
12230 } catch (ImsException e) {
12231 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12232 } finally {
12233 Binder.restoreCallingIdentity(identity);
12234 }
12235 }
12236
12237 /**
12238 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12239 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12240 */
12241 // Used for SHELL command only right now.
12242 @Override
12243 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12244 List<String> featureTags) {
12245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12246 "removeUceRegistrationOverrideShell");
12247 final long identity = Binder.clearCallingIdentity();
12248 try {
12249 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12250 new ArraySet<>(featureTags));
12251 } catch (ImsException e) {
12252 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12253 } finally {
12254 Binder.restoreCallingIdentity(identity);
12255 }
12256 }
12257
12258 /**
12259 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12260 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12261 */
12262 // Used for SHELL command only right now.
12263 @Override
12264 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12265 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12266 "clearUceRegistrationOverrideShell");
12267 final long identity = Binder.clearCallingIdentity();
12268 try {
12269 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12270 } catch (ImsException e) {
12271 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12272 } finally {
12273 Binder.restoreCallingIdentity(identity);
12274 }
12275 }
12276
12277 /**
12278 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12279 */
12280 // Used for SHELL command only right now.
12281 @Override
12282 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12284 "getLatestRcsContactUceCapabilityShell");
12285 final long identity = Binder.clearCallingIdentity();
12286 try {
12287 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12288 } catch (ImsException e) {
12289 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12290 } finally {
12291 Binder.restoreCallingIdentity(identity);
12292 }
12293 }
12294
12295 /**
12296 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12297 * device does not have an active PUBLISH.
12298 */
12299 // Used for SHELL command only right now.
12300 @Override
12301 public String getLastUcePidfXmlShell(int subId) {
12302 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12303 final long identity = Binder.clearCallingIdentity();
12304 try {
12305 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12306 } catch (ImsException e) {
12307 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12308 } finally {
12309 Binder.restoreCallingIdentity(identity);
12310 }
12311 }
12312
James.cf Line8713a42021-04-29 16:04:26 +080012313 /**
12314 * Remove UCE requests cannot be sent to the network status.
12315 */
12316 // Used for SHELL command only right now.
12317 @Override
12318 public boolean removeUceRequestDisallowedStatus(int subId) {
12319 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12320 final long identity = Binder.clearCallingIdentity();
12321 try {
12322 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12323 } catch (ImsException e) {
12324 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12325 } finally {
12326 Binder.restoreCallingIdentity(identity);
12327 }
12328 }
12329
James.cf Lin18bb9002021-05-25 01:37:38 +080012330 /**
12331 * Remove UCE requests cannot be sent to the network status.
12332 */
12333 // Used for SHELL command only.
12334 @Override
12335 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12336 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12337 final long identity = Binder.clearCallingIdentity();
12338 try {
12339 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12340 } catch (ImsException e) {
12341 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12342 } finally {
12343 Binder.restoreCallingIdentity(identity);
12344 }
12345 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012346
James.cf Lin4b784aa2021-01-31 03:25:15 +080012347 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012348 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12349 String callingPackage) {
12350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12351 mApp, subId, "setSignalStrengthUpdateRequest");
12352
joonhunshin4ac60942023-11-15 15:23:39 +000012353 enforceTelephonyFeatureWithException(callingPackage,
12354 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12355
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012356 final int callingUid = Binder.getCallingUid();
12357 // Verify that tha callingPackage belongs to the calling UID
12358 mApp.getSystemService(AppOpsManager.class)
12359 .checkPackage(callingUid, callingPackage);
12360
Rambo Wang3607f502021-02-01 21:51:40 -080012361 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012362
12363 final long identity = Binder.clearCallingIdentity();
12364 try {
12365 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12366 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12367
12368 if (result instanceof IllegalStateException) {
12369 throw (IllegalStateException) result;
12370 }
12371 } finally {
12372 Binder.restoreCallingIdentity(identity);
12373 }
12374 }
12375
12376 @Override
12377 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12378 String callingPackage) {
12379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12380 mApp, subId, "clearSignalStrengthUpdateRequest");
12381
joonhunshin4ac60942023-11-15 15:23:39 +000012382 enforceTelephonyFeatureWithException(callingPackage,
12383 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12384
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012385 final int callingUid = Binder.getCallingUid();
12386 // Verify that tha callingPackage belongs to the calling UID
12387 mApp.getSystemService(AppOpsManager.class)
12388 .checkPackage(callingUid, callingPackage);
12389
12390 final long identity = Binder.clearCallingIdentity();
12391 try {
12392 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12393 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12394
12395 if (result instanceof IllegalStateException) {
12396 throw (IllegalStateException) result;
12397 }
12398 } finally {
12399 Binder.restoreCallingIdentity(identity);
12400 }
12401 }
12402
Rambo Wang3607f502021-02-01 21:51:40 -080012403 private static void validateSignalStrengthUpdateRequest(Context context,
12404 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012405 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012406 // phone/system process do not have further restriction on request
12407 return;
12408 }
12409
12410 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012411 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012412 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012413 context.enforceCallingOrSelfPermission(
12414 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12415 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012416 }
12417
12418 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012419 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012420 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012421 || info.isEnabled()) {
12422 throw new IllegalArgumentException(
12423 "Only system can set hide fields in SignalThresholdInfo");
12424 }
12425
12426 // Thresholds length for each RAN need in range. This has been validated in
12427 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12428 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12429 final int[] thresholds = info.getThresholds();
12430 Objects.requireNonNull(thresholds);
12431 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12432 || thresholds.length
12433 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12434 throw new IllegalArgumentException(
12435 "thresholds length is out of range: " + thresholds.length);
12436 }
12437 }
12438 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012439
12440 /**
12441 * Gets the current phone capability.
12442 *
12443 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12444 * @return the PhoneCapability which describes the data connection capability of modem.
12445 * It's used to evaluate possible phone config change, for example from single
12446 * SIM device to multi-SIM device.
12447 */
12448 @Override
12449 public PhoneCapability getPhoneCapability() {
12450 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012451
12452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12453 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12454
SongFerngWang8236caa2021-01-17 21:51:44 +080012455 final long identity = Binder.clearCallingIdentity();
12456 try {
12457 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12458 } finally {
12459 Binder.restoreCallingIdentity(identity);
12460 }
12461 }
Michele Berionne5e411512020-11-13 02:36:59 +000012462
12463 /**
12464 * Prepare TelephonyManager for an unattended reboot. The reboot is
12465 * required to be done shortly after the API is invoked.
12466 */
12467 @Override
12468 @TelephonyManager.PrepareUnattendedRebootResult
12469 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012470 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012471 enforceRebootPermission();
12472
joonhunshin4ac60942023-11-15 15:23:39 +000012473 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12474 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12475
Michele Berionne5e411512020-11-13 02:36:59 +000012476 final long identity = Binder.clearCallingIdentity();
12477 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012478 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012479 } finally {
12480 Binder.restoreCallingIdentity(identity);
12481 }
12482 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012483
12484 /**
12485 * Request to get the current slicing configuration including URSP rules and
12486 * NSSAIs (configured, allowed and rejected).
12487 *
12488 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12489 */
12490 @Override
12491 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012492 TelephonyPermissions
12493 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12494 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012495
joonhunshin4ac60942023-11-15 15:23:39 +000012496 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12497 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12498 "getSlicingConfig");
12499
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012500 final long identity = Binder.clearCallingIdentity();
12501 try {
12502 Phone phone = getDefaultPhone();
12503 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12504 } finally {
12505 Binder.restoreCallingIdentity(identity);
12506 }
12507 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012508
12509 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012510 * Check whether the given premium capability is available for purchase from the carrier.
12511 *
12512 * @param capability The premium capability to check.
12513 * @param subId The subId to check the premium capability for.
12514 *
12515 * @return Whether the given premium capability is available to purchase.
12516 */
12517 @Override
12518 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12519 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12520 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12521 log("Premium capability "
12522 + TelephonyManager.convertPremiumCapabilityToString(capability)
12523 + " is not available for purchase due to missing permissions.");
12524 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12525 + "permission READ_BASIC_PHONE_STATE.");
12526 }
12527
joonhunshin4ac60942023-11-15 15:23:39 +000012528 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12529 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12530
Sarah Chin2ec39f62022-08-31 17:03:26 -070012531 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012532 if (phone == null) {
12533 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12534 return false;
12535 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012536 final long identity = Binder.clearCallingIdentity();
12537 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012538 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012539 .isPremiumCapabilityAvailableForPurchase(capability);
12540 } finally {
12541 Binder.restoreCallingIdentity(identity);
12542 }
12543 }
12544
12545 /**
12546 * Purchase the given premium capability from the carrier.
12547 *
12548 * @param capability The premium capability to purchase.
12549 * @param callback The result of the purchase request.
12550 * @param subId The subId to purchase the premium capability for.
12551 */
12552 @Override
12553 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12554 log("purchasePremiumCapability: capability="
12555 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12556 + getCurrentPackageName());
12557
12558 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12559 mApp, "purchasePremiumCapability")) {
12560 log("purchasePremiumCapability "
12561 + TelephonyManager.convertPremiumCapabilityToString(capability)
12562 + " failed due to missing permissions.");
12563 throw new SecurityException("purchasePremiumCapability requires permission "
12564 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012565 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12566 mApp, "purchasePremiumCapability")) {
12567 log("purchasePremiumCapability "
12568 + TelephonyManager.convertPremiumCapabilityToString(capability)
12569 + " failed due to missing permissions.");
12570 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012571 }
12572
joonhunshin4ac60942023-11-15 15:23:39 +000012573 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12574 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12575
Sarah Chin2ec39f62022-08-31 17:03:26 -070012576 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012577 if (phone == null) {
12578 try {
12579 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12580 callback.accept(result);
12581 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12582 } catch (RemoteException e) {
12583 String logStr = "Purchase premium capability "
12584 + TelephonyManager.convertPremiumCapabilityToString(capability)
12585 + " failed due to RemoteException handling null phone: " + e;
12586 if (DBG) log(logStr);
12587 AnomalyReporter.reportAnomaly(
12588 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12589 }
12590 return;
12591 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012592
12593 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012594 try {
Jack Yube3fa442024-09-16 14:39:45 -070012595 if (mFeatureFlags.hsumPackageManager()) {
12596 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12597 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12598 } else {
12599 callingProcess = mApp.getPackageManager().getApplicationInfo(
12600 getCurrentPackageName(), 0).processName;
12601 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012602 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012603 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012604 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012605
12606 boolean isVisible = false;
12607 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12608 if (am != null) {
12609 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12610 if (processes != null) {
12611 for (ActivityManager.RunningAppProcessInfo process : processes) {
12612 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012613 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012614 if (process.processName.equals(callingProcess) && process.importance
12615 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12616 isVisible = true;
12617 break;
12618 }
12619 }
12620 }
12621 }
12622
12623 if (!isVisible) {
12624 try {
12625 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12626 callback.accept(result);
12627 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12628 } catch (RemoteException e) {
12629 String logStr = "Purchase premium capability "
12630 + TelephonyManager.convertPremiumCapabilityToString(capability)
12631 + " failed due to RemoteException handling background application: " + e;
12632 if (DBG) log(logStr);
12633 AnomalyReporter.reportAnomaly(
12634 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12635 }
12636 return;
12637 }
12638
Sarah Chin71b3a852022-09-28 15:54:19 -070012639 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012640 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012641 }
12642
12643 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012644 * Register an IMS connection state callback
12645 */
12646 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012647 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12648 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012649 if (feature == ImsFeature.FEATURE_MMTEL) {
12650 // ImsMmTelManager
12651 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12652 TelephonyPermissions
12653 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12654 mApp, subId, "registerImsStateCallback");
12655 } else if (feature == ImsFeature.FEATURE_RCS) {
12656 // ImsRcsManager or SipDelegateManager
12657 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12658 Binder.getCallingUid(), "registerImsStateCallback",
12659 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12660 Manifest.permission.READ_PRECISE_PHONE_STATE,
12661 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12662 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12663 }
12664
12665 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12667 "IMS not available on device.");
12668 }
12669
12670 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12671 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12672 }
12673
12674 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12675 if (controller == null) {
12676 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12677 "IMS not available on device.");
12678 }
12679
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012680 if (callingPackage == null) {
12681 callingPackage = getCurrentPackageName();
12682 }
12683
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012684 final long token = Binder.clearCallingIdentity();
12685 try {
12686 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012687 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012688 } catch (ImsException e) {
12689 throw new ServiceSpecificException(e.getCode());
12690 } finally {
12691 Binder.restoreCallingIdentity(token);
12692 }
12693 }
12694
12695 /**
12696 * Unregister an IMS connection state callback
12697 */
12698 @Override
12699 public void unregisterImsStateCallback(IImsStateCallback cb) {
12700 final long token = Binder.clearCallingIdentity();
12701 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12702 if (controller == null) {
12703 return;
12704 }
12705 try {
12706 controller.unregisterImsStateCallback(cb);
12707 } finally {
12708 Binder.restoreCallingIdentity(token);
12709 }
12710 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012711
12712 /**
12713 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12714 *
12715 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012716 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012717 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012718 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012719 * If there is current registered network this value will be same as the registered cell
12720 * identity. If the device goes out of service the previous cell identity is cached and
12721 * will be returned. If the cache age of the Cell identity is more than 24 hours
12722 * it will be cleared and null will be returned.
12723 *
12724 */
12725 @Override
12726 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12727 String callingFeatureId) {
12728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12729 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12730 LocationAccessPolicy.checkLocationPermission(mApp,
12731 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12732 .setCallingPackage(callingPackage)
12733 .setCallingFeatureId(callingFeatureId)
12734 .setCallingPid(Binder.getCallingPid())
12735 .setCallingUid(Binder.getCallingUid())
12736 .setMethod("getLastKnownCellIdentity")
12737 .setLogAsInfo(true)
12738 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12739 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12740 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12741 .build());
12742
12743 boolean hasFinePermission =
12744 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12745 if (!hasFinePermission
12746 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12747 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012748 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012749 }
12750
12751 final long identity = Binder.clearCallingIdentity();
12752 try {
Ling Mac28f0212023-03-24 16:07:15 -070012753 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012754 if (sst == null) return null;
12755 return sst.getLastKnownCellIdentity();
12756 } finally {
12757 Binder.restoreCallingIdentity(identity);
12758 }
12759 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012760
jimsun3b9ccac2021-10-26 15:01:23 +080012761 /**
12762 * Sets the modem service class Name that Telephony will bind to.
12763 *
12764 * @param serviceName The class name of the modem service.
12765 * @return true if the operation is succeed, otherwise false.
12766 */
12767 public boolean setModemService(String serviceName) {
12768 Log.d(LOG_TAG, "setModemService - " + serviceName);
12769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012771 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12772 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012773 return mPhoneConfigurationManager.setModemService(serviceName);
12774 }
12775
12776 /**
12777 * Return the class name of the currently bounded modem service.
12778 *
12779 * @return the class name of the modem service.
12780 */
12781 public String getModemService() {
12782 String result;
12783 Log.d(LOG_TAG, "getModemService");
12784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12785 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012786 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012787 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12788 "getModemService");
12789 result = mPhoneConfigurationManager.getModemService();
12790 Log.d(LOG_TAG, "result = " + result);
12791 return result;
12792 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012793
Hakjun Choi3ee81112023-12-19 15:40:58 +000012794 /**
12795 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12796 * including carrier config, entitlement server, and config update.
12797 *
12798 * @param subId subId The subscription ID of the carrier.
12799 *
12800 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12801 * be returned.
12802 *
12803 * @throws SecurityException if the caller doesn't have the required permission.
12804 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012805 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12806 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012807 final long identity = Binder.clearCallingIdentity();
12808 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012809 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012810 } finally {
12811 Binder.restoreCallingIdentity(identity);
12812 }
12813 }
12814
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012815 @Override
12816 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12817 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12818 mApp.enforceCallingOrSelfPermission(
12819 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12820 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12821
12822 final long identity = Binder.clearCallingIdentity();
12823 try {
12824 Phone phone = getPhone(subId);
12825 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012826 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12827 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012828 phone.setVoiceServiceStateOverride(hasService);
12829 } finally {
12830 Binder.restoreCallingIdentity(identity);
12831 }
12832 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012833
12834 /**
12835 * set removable eSIM as default eUICC.
12836 *
12837 * @hide
12838 */
12839 @Override
12840 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12841 enforceModifyPermission();
12842 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12843
12844 final long identity = Binder.clearCallingIdentity();
12845 try {
12846 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12847 } finally {
12848 Binder.restoreCallingIdentity(identity);
12849 }
12850 }
12851
12852 /**
12853 * Returns whether the removable eSIM is default eUICC or not.
12854 *
12855 * @hide
12856 */
12857 @Override
12858 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12859 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12861
12862 final long identity = Binder.clearCallingIdentity();
12863 try {
12864 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12865 } finally {
12866 Binder.restoreCallingIdentity(identity);
12867 }
12868 }
12869
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012870 /**
12871 * Get the component name of the default app to direct respond-via-message intent for the
12872 * user associated with this subscription, update the cache if there is no respond-via-message
12873 * application currently configured for this user.
12874 * @return component name of the app and class to direct Respond Via Message intent to, or
12875 * {@code null} if the functionality is not supported.
12876 * @hide
12877 */
12878 @Override
12879 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12880 boolean updateIfNeeded) {
12881 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012882
joonhunshin4ac60942023-11-15 15:23:39 +000012883 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12884 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12885 "getDefaultRespondViaMessageApplication");
12886
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012887 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12888
Grant Menkeb0372492024-09-19 18:01:29 -070012889 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12890 UserHandle mainUser = null;
12891 Context userContext = null;
12892 final long identity = Binder.clearCallingIdentity();
12893 try {
12894 mainUser = mUserManager.getMainUser();
12895 userContext = context.createContextAsUser(mainUser, 0);
12896 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12897 } finally {
12898 Binder.restoreCallingIdentity(identity);
12899 }
12900 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12901 updateIfNeeded, mainUser);
12902 } else {
12903 UserHandle userHandle = null;
12904 final long identity = Binder.clearCallingIdentity();
12905 try {
12906 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12907 } finally {
12908 Binder.restoreCallingIdentity(identity);
12909 }
12910 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12911 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012912 }
Grant Menkeb0372492024-09-19 18:01:29 -070012913
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012914 }
Jack Yuf5badd92022-12-08 00:50:53 -080012915
12916 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012917 * Set whether the device is able to connect with null ciphering or integrity
12918 * algorithms. This is a global setting and will apply to all active subscriptions
12919 * and all new subscriptions after this.
12920 *
12921 * @param enabled when true, null cipher and integrity algorithms are allowed.
12922 * @hide
12923 */
12924 @Override
12925 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12926 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12927 enforceModifyPermission();
12928 checkForNullCipherAndIntegritySupport();
12929
12930 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12931 // for listening to these preference changes and applying them immediately.
12932 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12933 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12934 editor.apply();
12935
12936 for (Phone phone: PhoneFactory.getPhones()) {
12937 phone.handleNullCipherEnabledChange();
12938 }
12939 }
12940
12941
12942 /**
12943 * Get whether the device is able to connect with null ciphering or integrity
12944 * algorithms. Note that this retrieves the phone-global preference and not
12945 * the state of the radio.
12946 *
12947 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12948 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12949 * version for this feature.
12950 * @hide
12951 */
12952 @Override
12953 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12954 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12955 enforceReadPermission();
12956 checkForNullCipherAndIntegritySupport();
12957 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12958 }
12959
12960 private void checkForNullCipherAndIntegritySupport() {
12961 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12962 throw new UnsupportedOperationException(
12963 "Null cipher and integrity operations require HAL 2.1 or above");
12964 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012965 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12966 throw new UnsupportedOperationException(
12967 "Null cipher and integrity operations unsupported by modem");
12968 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012969 }
12970
Gil Cukierman06403e12023-11-29 16:33:03 +000012971 private void checkForIdentifierDisclosureNotificationSupport() {
12972 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12973 throw new UnsupportedOperationException(
12974 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12975 + "above");
12976 }
12977 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12978 throw new UnsupportedOperationException(
12979 "Cellular identifier disclosure transparency operations unsupported by modem");
12980 }
12981 }
12982
Michael Groover826b71d2023-12-21 22:08:06 -060012983 private void checkForNullCipherNotificationSupport() {
12984 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12985 throw new UnsupportedOperationException(
12986 "Null cipher notification operations require HAL 2.2 or above");
12987 }
12988 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12989 throw new UnsupportedOperationException(
12990 "Null cipher notification operations unsupported by modem");
12991 }
12992 }
12993
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012994 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012995 * Get the SIM state for the slot index.
12996 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12997 *
12998 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12999 */
13000 @Override
13001 @SimState
13002 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070013003 if (!mApp.getResources().getBoolean(
13004 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13006 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13007 }
joonhunshin4ac60942023-11-15 15:23:39 +000013008
Jack Yuf5badd92022-12-08 00:50:53 -080013009 IccCardConstants.State simState;
13010 if (slotIndex < 0) {
13011 simState = IccCardConstants.State.UNKNOWN;
13012 } else {
13013 Phone phone = null;
13014 try {
13015 phone = PhoneFactory.getPhone(slotIndex);
13016 } catch (IllegalStateException e) {
13017 // ignore
13018 }
13019 if (phone == null) {
13020 simState = IccCardConstants.State.UNKNOWN;
13021 } else {
13022 IccCard icc = phone.getIccCard();
13023 if (icc == null) {
13024 simState = IccCardConstants.State.UNKNOWN;
13025 } else {
13026 simState = icc.getState();
13027 }
13028 }
13029 }
13030 return simState.ordinal();
13031 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013032
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013033 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13034 boolean enableLogcat,
13035 long logcatStartTimestampMillis, boolean enableTelecomDump,
13036 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013037 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013038 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13039 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13040 ecdDataBuilder
13041 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13042 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013043 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013044 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013045 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013046 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13047 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013048 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13049 Executors.newCachedThreadPool(), db,
13050 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013051 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013052 }
13053
13054 /**
13055 * Request telephony to persist state for debugging emergency call failures.
13056 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013057 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013058 * @param enableLogcat whether to collect logcat output
13059 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13060 * @param enableTelecomDump whether to collect telecom dumpsys
13061 * @param enableTelephonyDump whether to collect telephony dumpsys
13062 */
13063 @Override
13064 @RequiresPermission(android.Manifest.permission.DUMP)
13065 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13066 long logcatStartTimestampMillis, boolean enableTelecomDump,
13067 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013068 // Verify that the caller has READ_DROPBOX_DATA permission.
13069 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13070 && Flags.enableReadDropboxPermission()) {
13071 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13072 "persistEmergencyCallDiagnosticData");
13073 } else {
13074 // Otherwise, enforce legacy permission.
13075 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13076 "persistEmergencyCallDiagnosticData");
13077 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013078 final long identity = Binder.clearCallingIdentity();
13079 try {
13080 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13081 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13082
13083 } finally {
13084 Binder.restoreCallingIdentity(identity);
13085 }
13086 }
13087
Hui Wang9b5793a2022-12-05 14:38:06 -060013088 /**
13089 * Get current cell broadcast ranges.
13090 */
13091 @Override
13092 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13093 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13094 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13095 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013096
13097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13098 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13099
Hui Wang9b5793a2022-12-05 14:38:06 -060013100 final long identity = Binder.clearCallingIdentity();
13101 try {
13102 return getPhone(subId).getCellBroadcastIdRanges();
13103 } finally {
13104 Binder.restoreCallingIdentity(identity);
13105 }
13106 }
13107
13108 /**
13109 * Set reception of cell broadcast messages with the list of the given ranges
13110 *
13111 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13112 */
13113 @Override
13114 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13115 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13116 @Nullable IIntegerConsumer callback) {
13117 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13118 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013119
13120 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13121 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13122
Hui Wang9b5793a2022-12-05 14:38:06 -060013123 final long identity = Binder.clearCallingIdentity();
13124 try {
13125 Phone phone = getPhoneFromSubId(subId);
13126 if (DBG) {
13127 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13128 }
13129 phone.setCellBroadcastIdRanges(ranges, result -> {
13130 if (callback != null) {
13131 try {
13132 callback.accept(result);
13133 } catch (RemoteException e) {
13134 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13135 }
13136 }
13137 });
13138 } finally {
13139 Binder.restoreCallingIdentity(identity);
13140 }
13141 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013142
13143 /**
13144 * Returns whether the device supports the domain selection service.
13145 *
13146 * @return {@code true} if the device supports the domain selection service.
13147 */
13148 @Override
13149 public boolean isDomainSelectionSupported() {
13150 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13151 "isDomainSelectionSupported");
13152
13153 final long identity = Binder.clearCallingIdentity();
13154 try {
13155 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13156 } finally {
13157 Binder.restoreCallingIdentity(identity);
13158 }
13159 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013160
13161 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013162 * Returns whether the AOSP domain selection service is supported.
13163 *
13164 * @return {@code true} if the AOSP domain selection service is supported,
13165 * {@code false} otherwise.
13166 */
13167 @Override
13168 public boolean isAospDomainSelectionService() {
13169 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13170 "isAospDomainSelectionService");
13171
13172 final long identity = Binder.clearCallingIdentity();
13173 try {
13174 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13175 String dssComponentName = mApp.getResources().getString(
13176 R.string.config_domain_selection_service_component_name);
13177 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13178 TelephonyDomainSelectionService.class.getName());
13179 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13180 + ", aosp=" + componentName.flattenToString());
13181 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13182 }
13183 } finally {
13184 Binder.restoreCallingIdentity(identity);
13185 }
13186 return false;
13187 }
13188
13189 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013190 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13191 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13192 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013193 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013194 * @param enableSatellite {@code true} to enable the satellite modem and
13195 * {@code false} to disable.
13196 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013197 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013198 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013199 *
13200 * @throws SecurityException if the caller doesn't have the required permission.
13201 */
13202 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013203 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013204 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013205 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013206 if (enableSatellite) {
13207 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13208 @Override
13209 protected void onReceiveResult(int resultCode, Bundle resultData) {
13210 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13211 + ", resultData=" + resultData);
13212 boolean isAllowed = false;
13213 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13214 callback::accept);
13215 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13216 if (resultData != null
13217 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13218 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13219 } else {
13220 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13221 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013222 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013223 result.accept(resultCode);
13224 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013225 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013226 if (isAllowed) {
13227 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013228 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013229 } else {
13230 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13231 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013232 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013233 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013234 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
youngtaecha2e6cfdd2024-09-04 04:59:10 +000013235 resultReceiver, true);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013236 } else {
13237 // No need to check if satellite is allowed at current location when disabling satellite
13238 mSatelliteController.requestSatelliteEnabled(
joonhunshin83da7cd2024-08-22 08:53:35 +000013239 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013240 }
Sarah Chin503828c2023-02-01 23:54:20 -080013241 }
13242
13243 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013244 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013245 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013246 * @param result The result receiver that returns whether the satellite modem is enabled
13247 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013248 *
13249 * @throws SecurityException if the caller doesn't have the required permission.
13250 */
13251 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013252 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013253 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013254 mSatelliteController.requestIsSatelliteEnabled(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013255 }
13256
13257 /**
Sarah Chin43457982023-02-15 17:50:38 -080013258 * Request to get whether the satellite service demo mode is enabled.
13259 *
Sarah Chin43457982023-02-15 17:50:38 -080013260 * @param result The result receiver that returns whether the satellite demo mode is enabled
13261 * if the request is successful or an error code if the request failed.
13262 *
13263 * @throws SecurityException if the caller doesn't have the required permission.
13264 */
13265 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013266 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013267 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013268 mSatelliteController.requestIsDemoModeEnabled(result);
Sarah Chin43457982023-02-15 17:50:38 -080013269 }
13270
13271 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013272 * Request to get whether the satellite service is enabled with emergency mode.
13273 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013274 * @param result The result receiver that returns whether the satellite emergency mode is
13275 * enabled if the request is successful or an error code if the request failed.
13276 *
13277 * @throws SecurityException if the caller doesn't have the required permission.
13278 */
13279 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013280 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013281 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshin83da7cd2024-08-22 08:53:35 +000013282 mSatelliteController.requestIsEmergencyModeEnabled(result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013283 }
13284
13285 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013286 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013287 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013288 * @param result The result receiver that returns whether the satellite service is supported on
13289 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013290 */
13291 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013292 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
13293 mSatelliteController.requestIsSatelliteSupported(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013294 }
13295
13296 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013297 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013298 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013299 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13300 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013301 *
13302 * @throws SecurityException if the caller doesn't have required permission.
13303 */
13304 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013305 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013306 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
joonhunshin83da7cd2024-08-22 08:53:35 +000013307 mSatelliteController.requestSatelliteCapabilities(result);
Sarah Chin503828c2023-02-01 23:54:20 -080013308 }
13309
13310 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013311 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013312 * This can be called by the pointing UI when the user starts pointing to the satellite.
13313 * Modem should continue to report the pointing input as the device or satellite moves.
13314 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013315 * @param resultCallback The callback to get the result of the request.
13316 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013317 *
13318 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013319 */
13320 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013321 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013322 @NonNull IIntegerConsumer resultCallback,
13323 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13324 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013325 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013326 }
13327
13328 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013329 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013330 * This can be called by the pointing UI when the user stops pointing to the satellite.
13331 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013332 * @param resultCallback The callback to get the result of the request.
13333 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013334 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013335 *
13336 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013337 */
13338 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013339 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013340 @NonNull IIntegerConsumer resultCallback,
13341 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13342 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
joonhunshin83da7cd2024-08-22 08:53:35 +000013343 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013344 }
13345
13346 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013347 * Register the subscription with a satellite provider.
13348 * This is needed to register the subscription if the provider allows dynamic registration.
13349 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013350 * @param token The token to be used as a unique identifier for provisioning with satellite
13351 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013352 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013353 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013354 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013355 * @return The signal transport used by the caller to cancel the provision request,
13356 * or {@code null} if the request failed.
13357 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013358 * @throws SecurityException if the caller doesn't have the required permission.
13359 */
13360 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013361 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013362 @NonNull String token, @NonNull byte[] provisionData,
13363 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013364 enforceSatelliteCommunicationPermission("provisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013365 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013366 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013367 }
13368
13369 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013370 * Unregister the device/subscription with the satellite provider.
13371 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013372 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013373 * should report as deprovisioned.
13374 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013375 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013376 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013377 *
13378 * @throws SecurityException if the caller doesn't have the required permission.
13379 */
13380 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013381 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013382 @NonNull String token, @NonNull IIntegerConsumer callback) {
13383 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
joonhunshin83da7cd2024-08-22 08:53:35 +000013384 mSatelliteController.deprovisionSatelliteService(token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013385 }
13386
13387 /**
Sarah Chin43457982023-02-15 17:50:38 -080013388 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013389 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013390 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013391 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013392 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013393 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013394 * @throws SecurityException if the caller doesn't have the required permission.
13395 */
13396 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013397 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013398 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013399 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013400 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013401 }
13402
13403 /**
Sarah Chin43457982023-02-15 17:50:38 -080013404 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013405 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013406 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013407 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013408 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013409 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013410 * @throws SecurityException if the caller doesn't have the required permission.
13411 */
13412 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013413 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013414 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013415 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013416 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013417 }
13418
13419 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013420 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013421 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013422 * @param result The result receiver that returns whether the device is provisioned with a
13423 * satellite provider if the request is successful or an error code if the
13424 * request failed.
13425 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013426 * @throws SecurityException if the caller doesn't have the required permission.
13427 */
13428 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013429 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013430 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
joonhunshin83da7cd2024-08-22 08:53:35 +000013431 mSatelliteController.requestIsSatelliteProvisioned(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013432 }
13433
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013434 /**
Sarah Chin43457982023-02-15 17:50:38 -080013435 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013436 *
Sarah Chin43457982023-02-15 17:50:38 -080013437 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013438 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013439 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013440 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013441 * @throws SecurityException if the caller doesn't have the required permission.
13442 */
13443 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013444 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013445 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013446 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013447 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013448 }
13449
13450 /**
Sarah Chin43457982023-02-15 17:50:38 -080013451 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013452 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013453 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013454 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013455 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013456 *
13457 * @throws SecurityException if the caller doesn't have the required permission.
13458 */
13459 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013460 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013461 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013462 mSatelliteController.unregisterForModemStateChanged(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013463 }
13464
13465 /**
13466 * Register to receive incoming datagrams over satellite.
13467 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013468 * @param callback The callback to handle incoming datagrams over satellite.
13469 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013470 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013471 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013472 * @throws SecurityException if the caller doesn't have the required permission.
13473 */
13474 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013475 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013476 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013477 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013478 return mSatelliteController.registerForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013479 }
13480
13481 /**
13482 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013483 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013484 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013485 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013486 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013487 *
13488 * @throws SecurityException if the caller doesn't have the required permission.
13489 */
13490 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013491 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013492 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013493 mSatelliteController.unregisterForIncomingDatagram(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013494 }
13495
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013496 /**
13497 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013498 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013499 * This method requests modem to check if there are any pending datagrams to be received over
13500 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013501 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013502 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013503 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013504 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013505 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013506 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013507 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013508 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
joonhunshin83da7cd2024-08-22 08:53:35 +000013509 mSatelliteController.pollPendingDatagrams(callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013510 }
13511
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013512 /**
13513 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013514 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013515 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13516 * input to this method. Datagram received here will be passed down to modem without any
13517 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013518 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013519 * @param datagramType datagram type indicating whether the datagram is of type
13520 * SOS_SMS or LOCATION_SHARING.
13521 * @param datagram encoded gateway datagram which is encrypted by the caller.
13522 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013523 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13524 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013525 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013526 *
13527 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013528 */
13529 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013530 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013531 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13532 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013533 enforceSatelliteCommunicationPermission("sendDatagram");
joonhunshin83da7cd2024-08-22 08:53:35 +000013534 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013535 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013536 }
13537
Sarah Chindf715ec2023-02-13 13:46:24 -080013538 /**
13539 * Request to get whether satellite communication is allowed for the current location.
13540 *
13541 * @param subId The subId of the subscription to check whether satellite communication is
13542 * allowed for the current location for.
13543 * @param result The result receiver that returns whether satellite communication is allowed
13544 * for the current location if the request is successful or an error code
13545 * if the request failed.
13546 *
13547 * @throws SecurityException if the caller doesn't have the required permission.
13548 */
13549 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013550 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013551 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013552 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
youngtaecha2e6cfdd2024-09-04 04:59:10 +000013553 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, false);
Sarah Chindf715ec2023-02-13 13:46:24 -080013554 }
13555
13556 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013557 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013558 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013559 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013560 * be visible if the request is successful or an error code if the request failed.
13561 *
13562 * @throws SecurityException if the caller doesn't have the required permission.
13563 */
13564 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013565 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013566 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
joonhunshin83da7cd2024-08-22 08:53:35 +000013567 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013568 }
13569
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013570 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013571 * Inform that Device is aligned to satellite for demo mode.
13572 *
Hakjun Choiae365972023-04-25 11:00:31 +000013573 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13574 * {@code false} Device fails to align with the satellite for demo mode.
13575 *
13576 * @throws SecurityException if the caller doesn't have required permission.
13577 */
13578 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13579
joonhunshin83da7cd2024-08-22 08:53:35 +000013580 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013581 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
joonhunshin83da7cd2024-08-22 08:53:35 +000013582 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013583 }
13584
13585 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013586 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13587 * by modem.
13588 *
13589 * @param subId The subId of the subscription to request for.
13590 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013591 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013592 * operation.
13593 *
13594 * @throws SecurityException if the caller doesn't have required permission.
13595 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013596 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013597 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13598 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013599 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013600 final long identity = Binder.clearCallingIdentity();
13601 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013602 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013603 } finally {
13604 Binder.restoreCallingIdentity(identity);
13605 }
13606 }
13607
13608 /**
13609 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13610 * by modem.
13611 *
13612 * @param subId The subId of the subscription to request for.
13613 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013614 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013615 * operation.
13616 *
13617 * @throws SecurityException if the caller doesn't have required permission.
13618 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013619 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013620 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13621 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013622 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013623 final long identity = Binder.clearCallingIdentity();
13624 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013625 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013626 } finally {
13627 Binder.restoreCallingIdentity(identity);
13628 }
13629 }
13630
13631 /**
13632 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013633 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013634 *
13635 * @param subId The subId of the subscription to request for.
13636 *
13637 * @return Integer array of reasons for disallowing satellite communication.
13638 *
13639 * @throws SecurityException if the caller doesn't have the required permission.
13640 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013641 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013642 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013643 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013644 final long identity = Binder.clearCallingIdentity();
13645 try {
13646 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013647 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013648 return reasonSet.stream().mapToInt(i->i).toArray();
13649 } finally {
13650 Binder.restoreCallingIdentity(identity);
13651 }
13652 }
13653
13654 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013655 * Request to get the signal strength of the satellite connection.
13656 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013657 * @param result Result receiver to get the error code of the request and the current signal
13658 * strength of the satellite connection.
13659 *
13660 * @throws SecurityException if the caller doesn't have required permission.
13661 */
13662 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013663 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013664 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13665 final long identity = Binder.clearCallingIdentity();
13666 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013667 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013668 } finally {
13669 Binder.restoreCallingIdentity(identity);
13670 }
13671 }
13672
13673 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013674 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13675 * is not successful, a {@link ServiceSpecificException} that contains
13676 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013677 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013678 * @param callback The callback to handle the NTN signal strength changed event. If the
13679 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13680 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13681 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13682 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013683 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013684 * @throws SecurityException If the caller doesn't have the required permission.
13685 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013686 */
13687 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013688 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013689 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013690 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13691 final long identity = Binder.clearCallingIdentity();
13692 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013693 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013694 } finally {
13695 Binder.restoreCallingIdentity(identity);
13696 }
13697 }
13698
13699 /**
13700 * Unregisters for NTN signal strength changed from satellite modem.
13701 * If callback was not registered before, the request will be ignored.
13702 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013703 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013704 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013705 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000013706 *
13707 * @throws SecurityException if the caller doesn't have the required permission.
13708 */
13709 @Override
13710 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013711 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013712 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13713 final long identity = Binder.clearCallingIdentity();
13714 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013715 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013716 } finally {
13717 Binder.restoreCallingIdentity(identity);
13718 }
13719 }
13720
13721 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013722 * Registers for satellite capabilities change event from the satellite service.
13723 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013724 * @param callback The callback to handle the satellite capabilities changed event.
13725 *
13726 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13727 *
13728 * @throws SecurityException if the caller doesn't have required permission.
13729 */
13730 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013731 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013732 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013733 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013734 final long identity = Binder.clearCallingIdentity();
13735 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013736 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013737 } finally {
13738 Binder.restoreCallingIdentity(identity);
13739 }
13740 }
13741
13742 /**
13743 * Unregisters for satellite capabilities change event from the satellite service.
13744 * If callback was not registered before, the request will be ignored.
13745 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013746 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000013747 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013748 *
13749 * @throws SecurityException if the caller doesn't have required permission.
13750 */
13751 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013752 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013753 @NonNull ISatelliteCapabilitiesCallback callback) {
13754 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013755 final long identity = Binder.clearCallingIdentity();
13756 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013757 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013758 } finally {
13759 Binder.restoreCallingIdentity(identity);
13760 }
13761 }
13762
13763 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013764 * Registers for the satellite supported state changed.
13765 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013766 * @param callback The callback to handle the satellite supported state changed event.
13767 *
13768 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13769 *
13770 * @throws SecurityException if the caller doesn't have the required permission.
13771 */
13772 @Override
13773 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013774 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013775 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013776 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013777 }
13778
13779 /**
13780 * Unregisters for the satellite supported state changed.
13781 * If callback was not registered before, the request will be ignored.
13782 *
Hakjun Choif92ac752024-03-18 19:34:29 +000013783 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013784 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000013785 *
13786 * @throws SecurityException if the caller doesn't have the required permission.
13787 */
13788 @Override
13789 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013790 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000013791 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
joonhunshin83da7cd2024-08-22 08:53:35 +000013792 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
Hakjun Choif92ac752024-03-18 19:34:29 +000013793 }
13794
13795 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013796 * This API can be used by only CTS to update satellite vendor service package name.
13797 *
13798 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000013799 * @param provisioned Whether satellite should be provisioned or not.
13800 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013801 * @return {@code true} if the satellite vendor service is set successfully,
13802 * {@code false} otherwise.
13803 */
Hakjun Choic3393242024-06-26 18:02:08 +000013804 public boolean setSatelliteServicePackageName(String servicePackageName,
13805 String provisioned) {
13806 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
13807 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013808 TelephonyPermissions.enforceShellOnly(
13809 Binder.getCallingUid(), "setSatelliteServicePackageName");
13810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13811 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13812 "setSatelliteServicePackageName");
Hakjun Choic3393242024-06-26 18:02:08 +000013813 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
13814 provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013815 }
13816
13817 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013818 * This API can be used by only CTS to update satellite gateway service package name.
13819 *
13820 * @param servicePackageName The package name of the satellite gateway service.
13821 * @return {@code true} if the satellite gateway service is set successfully,
13822 * {@code false} otherwise.
13823 */
13824 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13825 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13826 TelephonyPermissions.enforceShellOnly(
13827 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13829 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13830 "setSatelliteGatewayServicePackageName");
13831 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13832 }
13833
13834 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013835 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13836 *
13837 * @param packageName The package name of the satellite pointing UI app.
13838 * @param className The class name of the satellite pointing UI app.
13839 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13840 * {@code false} otherwise.
13841 */
13842 public boolean setSatellitePointingUiClassName(
13843 @Nullable String packageName, @Nullable String className) {
13844 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13845 + ", className=" + className);
13846 TelephonyPermissions.enforceShellOnly(
13847 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13849 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13850 "setSatelliteGatewayServicePackageName");
13851 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13852 }
13853
13854 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013855 * This API can be used by only CTS to update the timeout duration in milliseconds that
13856 * satellite should stay at listening mode to wait for the next incoming page before disabling
13857 * listening mode.
13858 *
13859 * @param timeoutMillis The timeout duration in millisecond.
13860 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13861 */
13862 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13863 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13864 TelephonyPermissions.enforceShellOnly(
13865 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13867 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13868 "setSatelliteListeningTimeoutDuration");
13869 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13870 }
13871
13872 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000013873 * This API can be used by only CTS to control ingoring cellular service state event.
13874 *
13875 * @param enabled Whether to enable boolean config.
13876 * @return {@code true} if the value is set successfully, {@code false} otherwise.
13877 */
13878 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
13879 Log.d(LOG_TAG, "setSatelliteIgnoreServiceState - " + enabled);
13880 TelephonyPermissions.enforceShellOnly(
13881 Binder.getCallingUid(), "setSatelliteIgnoreServiceState");
13882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13883 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13884 "setSatelliteIgnoreServiceState");
13885 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
13886 }
13887
13888 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013889 * This API can be used by only CTS to override the timeout durations used by the
13890 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013891 *
13892 * @param timeoutMillis The timeout duration in millisecond.
13893 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13894 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013895 public boolean setDatagramControllerTimeoutDuration(
13896 boolean reset, int timeoutType, long timeoutMillis) {
13897 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13898 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013899 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013900 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13902 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013903 "setDatagramControllerTimeoutDuration");
13904 return mSatelliteController.setDatagramControllerTimeoutDuration(
13905 reset, timeoutType, timeoutMillis);
13906 }
13907
13908 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013909 * This API can be used by only CTS to override the boolean configs used by the
13910 * DatagramController module.
13911 *
13912 * @param enable Whether to enable or disable boolean config.
13913 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13914 */
13915 public boolean setDatagramControllerBooleanConfig(
13916 boolean reset, int booleanType, boolean enable) {
13917 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13918 + ", reset=" + reset + ", enable=" + enable);
13919 TelephonyPermissions.enforceShellOnly(
13920 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13922 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13923 "ssetDatagramControllerBooleanConfig");
13924 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13925 }
13926
13927
13928 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013929 * This API can be used by only CTS to override the timeout durations used by the
13930 * SatelliteController module.
13931 *
13932 * @param timeoutMillis The timeout duration in millisecond.
13933 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13934 */
13935 public boolean setSatelliteControllerTimeoutDuration(
13936 boolean reset, int timeoutType, long timeoutMillis) {
13937 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13938 + reset + ", timeoutMillis=" + timeoutMillis);
13939 TelephonyPermissions.enforceShellOnly(
13940 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13942 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13943 "setSatelliteControllerTimeoutDuration");
13944 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13945 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013946 }
13947
13948 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013949 * This API can be used in only testing to override connectivity status in monitoring emergency
13950 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13951 *
13952 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13953 * of the following values to enable the override:
13954 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13955 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13956 * To disable the override, use -1 for handoverType.
13957 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13958 * delaySeconds after the emergency call starts.
13959 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13960 */
13961 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13962 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13963 TelephonyPermissions.enforceShellOnly(
13964 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13966 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13967 "setEmergencyCallToSatelliteHandoverType");
13968 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13969 handoverType, delaySeconds);
13970 }
13971
13972 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013973 * This API can be used in only testing to override oem-enabled satellite provision status.
13974 *
13975 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13976 * otherwise.
13977 * @param isProvisioned The overriding provision status.
13978 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13979 */
13980 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13981 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13982 + ", isProvisioned=" + isProvisioned);
13983 TelephonyPermissions.enforceShellOnly(
13984 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13986 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13987 "setOemEnabledSatelliteProvisionStatus");
13988 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13989 }
13990
13991 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013992 * This API should be used by only CTS tests to forcefully set telephony country codes.
13993 *
13994 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13995 */
13996 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13997 Map cachedNetworkCountryCodes, String locationCountryCode,
13998 long locationCountryCodeTimestampNanos) {
13999 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14000 + String.join(", ", currentNetworkCountryCodes)
14001 + ", locationCountryCode=" + locationCountryCode
14002 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14003 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14004 + String.join(", ", cachedNetworkCountryCodes.keySet()));
14005 TelephonyPermissions.enforceShellOnly(
14006 Binder.getCallingUid(), "setCachedLocationCountryCode");
14007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14008 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14009 "setCachedLocationCountryCode");
youngtaecha31b141d2024-07-15 12:01:39 +000014010 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), mFeatureFlags)
14011 .setCountryCodes(reset, currentNetworkCountryCodes, cachedNetworkCountryCodes,
14012 locationCountryCode, locationCountryCodeTimestampNanos);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014013 }
14014
14015 /**
14016 * This API should be used by only CTS tests to override the overlay configs of satellite
14017 * access controller.
14018 *
14019 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14020 * otherwise.
14021 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14022 */
14023 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14024 String s2CellFile, long locationFreshDurationNanos,
14025 List<String> satelliteCountryCodes) {
14026 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14027 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14028 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14029 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
14030 ? String.join(", ", satelliteCountryCodes) : null));
14031 TelephonyPermissions.enforceShellOnly(
14032 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14034 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14035 "setSatelliteAccessControlOverlayConfigs");
14036 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
14037 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
14038 }
14039
14040 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014041 * This API can be used by only CTS to override the cached value for the device overlay config
14042 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14043 * outgoing satellite datagrams should be sent to modem in demo mode.
14044 *
14045 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14046 * satellite modem or not.
14047 *
14048 * @return {@code true} if the operation is successful, {@code false} otherwise.
14049 */
14050 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14051 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14052 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14053 + "disabled");
14054 return false;
14055 }
14056 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14057 TelephonyPermissions.enforceShellOnly(
14058 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14060 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14061 "setShouldSendDatagramToModemInDemoMode");
14062 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14063 shouldSendToModemInDemoMode);
14064 }
14065
14066 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014067 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14068 *
14069 * @param state a state indicates whether satellite access allowed state should be cached and
14070 * the allowed state.
14071 * @return {@code true} if the setting is successful, {@code false} otherwise.
14072 */
14073 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14074 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14075 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14076 + "oemEnabledSatelliteFlag is disabled");
14077 return false;
14078 }
14079
14080 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14081 + "state=" + state);
14082 TelephonyPermissions.enforceShellOnly(
14083 Binder.getCallingUid(),
14084 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14086 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14087 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14088 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14089 state);
14090 }
14091
14092 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014093 * Sets the service defined in ComponentName to be bound.
14094 *
14095 * This should only be used for testing.
14096 * @return {@code true} if the DomainSelectionService to bind to was set,
14097 * {@code false} otherwise.
14098 */
14099 @Override
14100 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14101 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14102
14103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14104 "setDomainSelectionServiceOverride");
14105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14106 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14107
14108 final long identity = Binder.clearCallingIdentity();
14109 try {
14110 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14111 return DomainSelectionResolver.getInstance()
14112 .setDomainSelectionServiceOverride(componentName);
14113 }
14114 } finally {
14115 Binder.restoreCallingIdentity(identity);
14116 }
14117 return false;
14118 }
14119
14120 /**
14121 * Clears the DomainSelectionService override.
14122 *
14123 * This should only be used for testing.
14124 * @return {@code true} if the DomainSelectionService override was cleared,
14125 * {@code false} otherwise.
14126 */
14127 @Override
14128 public boolean clearDomainSelectionServiceOverride() {
14129 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14130
14131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14132 "clearDomainSelectionServiceOverride");
14133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14134 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14135
14136 final long identity = Binder.clearCallingIdentity();
14137 try {
14138 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14139 return DomainSelectionResolver.getInstance()
14140 .clearDomainSelectionServiceOverride();
14141 }
14142 } finally {
14143 Binder.restoreCallingIdentity(identity);
14144 }
14145 return false;
14146 }
14147
14148 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014149 * Enable or disable notifications sent for cellular identifier disclosure events.
14150 *
14151 * Disclosure events are defined as instances where a device has sent a cellular identifier
14152 * on the Non-access stratum (NAS) before a security context is established. As a result the
14153 * identifier is sent in the clear, which has privacy implications for the user.
14154 *
14155 * @param enable if notifications about disclosure events should be enabled
14156 * @throws SecurityException if the caller does not have the required privileges
14157 * @throws UnsupportedOperationException if the modem does not support this feature.
14158 */
14159 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014160 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014161 enforceModifyPermission();
14162 checkForIdentifierDisclosureNotificationSupport();
14163
14164 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14165 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14166 editor.apply();
14167
14168 // Each phone instance is responsible for updating its respective modem immediately
14169 // after we've made a preference change.
14170 for (Phone phone : PhoneFactory.getPhones()) {
14171 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14172 }
14173 }
14174
14175 /**
14176 * Get whether or not cellular identifier disclosure notifications are enabled.
14177 *
14178 * @throws SecurityException if the caller does not have the required privileges
14179 * @throws UnsupportedOperationException if the modem does not support this feature.
14180 */
14181 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014182 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014183 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14184 checkForIdentifierDisclosureNotificationSupport();
14185 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14186 }
14187
14188 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014189 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14190 * are in use by the cellular modem.
14191 *
14192 * @throws IllegalStateException if the Telephony process is not currently available
14193 * @throws SecurityException if the caller does not have the required privileges
14194 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14195 * and integrity algorithms in use
14196 * @hide
14197 */
14198 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014199 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014200 enforceModifyPermission();
14201 checkForNullCipherNotificationSupport();
14202
14203 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14204 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14205 editor.apply();
14206
14207 // Each phone instance is responsible for updating its respective modem immediately
14208 // after a preference change.
14209 for (Phone phone : PhoneFactory.getPhones()) {
14210 phone.handleNullCipherNotificationPreferenceChanged();
14211 }
14212 }
14213
14214 /**
14215 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14216 * cellular modem.
14217 *
14218 * @throws IllegalStateException if the Telephony process is not currently available
14219 * @throws SecurityException if the caller does not have the required privileges
14220 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14221 * and integrity algorithms in use
14222 * @hide
14223 */
14224 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14225 public boolean isNullCipherNotificationsEnabled() {
14226 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14227 checkForNullCipherNotificationSupport();
14228 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14229 }
14230
14231 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014232 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14233 *
14234 * <p>This method behaves in one of the following ways:
14235 * <ul>
14236 * <li>return true : if the calling package has the appop permission {@link
14237 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14238 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14239 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14240 * Owner device identifier access check, or the calling package has carrier privileges</>
14241 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14242 * </ul>
14243 */
14244 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14245 String callingPackage, @Nullable String callingFeatureId, String message) {
14246 for (Phone phone : PhoneFactory.getPhones()) {
14247 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14248 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14249 return true;
14250 }
14251 }
14252 return false;
14253 }
arunvoddud7401012022-12-15 16:08:12 +000014254
14255 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014256 * @return The subscription manager service instance.
14257 */
14258 public SubscriptionManagerService getSubscriptionManagerService() {
14259 return SubscriptionManagerService.getInstance();
14260 }
14261
14262 /**
arunvoddud7401012022-12-15 16:08:12 +000014263 * Class binds the consumer[callback] and carrierId.
14264 */
14265 private static class CallerCallbackInfo {
14266 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014267 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014268
Steve Statia28b7cb32024-03-11 23:58:50 +000014269 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014270 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014271 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014272 }
14273
14274 public Consumer<Integer> getConsumer() {
14275 return mConsumer;
14276 }
14277
Steve Statia28b7cb32024-03-11 23:58:50 +000014278 public Set<Integer> getCarrierIds() {
14279 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014280 }
14281 }
joonhunshin4ac60942023-11-15 15:23:39 +000014282
14283 /*
14284 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14285 * But the context that is passed in is unused if the phone app is already alive.
14286 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14287 */
14288 @VisibleForTesting
14289 public void setPackageManager(PackageManager packageManager) {
14290 mPackageManager = packageManager;
14291 }
14292
14293 /*
Nate Myren453c3472024-03-13 11:28:11 -070014294 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14295 * But the context that is passed in is unused if the phone app is already alive.
14296 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14297 */
14298 @VisibleForTesting
14299 public void setAppOpsManager(AppOpsManager appOps) {
14300 mAppOps = appOps;
14301 }
14302
14303 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014304 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14305 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14306 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14307 */
14308 @VisibleForTesting
14309 public void setFeatureFlags(FeatureFlags featureFlags) {
14310 mFeatureFlags = featureFlags;
14311 }
14312
14313 /**
14314 * Make sure the device has required telephony feature
14315 *
14316 * @throws UnsupportedOperationException if the device does not have required telephony feature
14317 */
14318 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14319 @NonNull String telephonyFeature, @NonNull String methodName) {
14320 if (callingPackage == null || mPackageManager == null) {
14321 return;
14322 }
14323
14324 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14325 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014326 Binder.getCallingUserHandle())
14327 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14328 // Skip to check associated telephony feature,
14329 // if compatibility change is not enabled for the current process or
14330 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014331 return;
14332 }
14333
14334 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14335 throw new UnsupportedOperationException(
14336 methodName + " is unsupported without " + telephonyFeature);
14337 }
14338 }
youngtaecha5d483d52024-04-29 17:05:45 +000014339
14340 /**
14341 * Registers for the satellite communication allowed state changed.
14342 *
14343 * @param subId The subId of the subscription to register for the satellite communication
14344 * allowed state changed.
14345 * @param callback The callback to handle the satellite communication allowed
14346 * state changed event.
14347 *
14348 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14349 *
14350 * @throws SecurityException if the caller doesn't have the required permission.
14351 */
14352 @Override
14353 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14354 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14355 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014356 final long identity = Binder.clearCallingIdentity();
14357 try {
14358 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14359 subId, callback);
14360 } finally {
14361 Binder.restoreCallingIdentity(identity);
14362 }
youngtaecha5d483d52024-04-29 17:05:45 +000014363 }
14364
14365 /**
14366 * Unregisters for the satellite communication allowed state changed.
14367 * If callback was not registered before, the request will be ignored.
14368 *
14369 * @param subId The subId of the subscription to unregister for the satellite communication
14370 * allowed state changed.
14371 * @param callback The callback that was passed to
14372 * {@link #registerForCommunicationAllowedStateChanged(int,
14373 * ISatelliteCommunicationAllowedStateCallback)}. *
14374 * @throws SecurityException if the caller doesn't have the required permission.
14375 */
14376 @Override
14377 public void unregisterForCommunicationAllowedStateChanged(
14378 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14379 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014380 final long identity = Binder.clearCallingIdentity();
14381 try {
14382 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14383 callback);
14384 } finally {
14385 Binder.restoreCallingIdentity(identity);
14386 }
youngtaecha5d483d52024-04-29 17:05:45 +000014387 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014388
14389 /**
14390 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14391 *
14392 * @param subId The subId of the subscription to the satellite session stats for.
14393 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14394 * if the request is successful or an error code if the request failed.
14395 *
14396 * @throws SecurityException if the caller doesn't have required permission.
14397 */
14398 @Override
14399 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14400 enforceModifyPermission();
14401 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014402 final long identity = Binder.clearCallingIdentity();
14403 try {
14404 mSatelliteController.requestSatelliteSessionStats(subId, result);
14405 } finally {
14406 Binder.restoreCallingIdentity(identity);
14407 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014408 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014409
14410 /**
14411 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14412 *
14413 * @param result The result receiver, which returns the list of prioritized satellite tokens
14414 * to be used for provision if the request is successful or an error code if the request failed.
14415 *
14416 * @throws SecurityException if the caller doesn't have the required permission.
14417 */
14418 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014419 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14420 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014421 final long identity = Binder.clearCallingIdentity();
14422 try {
14423 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14424 } finally {
14425 Binder.restoreCallingIdentity(identity);
14426 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014427 }
14428
14429 /**
14430 * Deliver the list of provisioned satellite subscriber ids.
14431 *
14432 * @param list List of provisioned satellite subscriber ids.
14433 * @param result The result receiver that returns whether deliver success or fail.
14434 *
14435 * @throws SecurityException if the caller doesn't have the required permission.
14436 */
14437 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014438 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014439 @NonNull ResultReceiver result) {
14440 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014441 final long identity = Binder.clearCallingIdentity();
14442 try {
14443 mSatelliteController.provisionSatellite(list, result);
14444 } finally {
14445 Binder.restoreCallingIdentity(identity);
14446 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014447 }
Hyosund6aaf062024-08-23 23:02:10 +000014448
14449 /**
14450 * This API can be used by only CTS to override the cached value for the device overlay config
14451 * value :
14452 * config_satellite_gateway_service_package and
14453 * config_satellite_carrier_roaming_esos_provisioned_class.
14454 * These values are set before sending an intent to broadcast there are any change to list of
14455 * subscriber informations.
14456 *
14457 * @param name the name is one of the following that constitute an intent.
14458 * Component package name, or component class name.
14459 * @return {@code true} if the setting is successful, {@code false} otherwise.
14460 */
14461 @Override
14462 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14463 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14464 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14465 + " carrierRoamingNbIotNtn is disabled");
14466 return false;
14467 }
14468 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14469 TelephonyPermissions.enforceShellOnly(
14470 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14472 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14473 "setSatelliteSubscriberIdListChangedIntentComponent");
14474 final long identity = Binder.clearCallingIdentity();
14475 try {
14476 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14477 } finally {
14478 Binder.restoreCallingIdentity(identity);
14479 }
14480 }
Jack Yu26735292024-09-25 14:33:49 -070014481
14482 /**
14483 * This API can be used by only CTS to override the Euicc UI component.
14484 *
14485 * @param componentName ui component to be launched for testing. {@code null} to reset.
14486 *
14487 * @hide
14488 */
14489 @Override
14490 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14491 enforceModifyPermission();
14492 log("setTestEuiccUiComponent: " + componentName);
14493 mTestEuiccUiComponent = componentName;
14494 }
14495
14496 /**
14497 * This API can be used by only CTS to retrieve the Euicc UI component.
14498 *
14499 * @return Euicc UI component. {@code null} if not available.
14500 * @hide
14501 */
14502 @Override
14503 @Nullable
14504 public ComponentName getTestEuiccUiComponent() {
14505 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14506 return mTestEuiccUiComponent;
14507 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014508
14509 /**
14510 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14511 *
14512 * @param state to update Ntn Eligibility.
14513 * @param resetRequired to reset the overridden flag in satellite controller.
14514 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14515 */
14516 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14517 boolean resetRequired) {
14518 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14519 resetRequired);
14520 }
Jack Yufa8ed012023-02-11 15:42:28 -080014521}